forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for Lesson and Subject classes
- Loading branch information
1 parent
282e984
commit 1f5277d
Showing
7 changed files
with
136 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package seedu.address.model.person; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static seedu.address.testutil.Assert.assertThrows; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class LessonTest { | ||
|
||
@Test | ||
public void constructor_null_throwsNullPointerException() { | ||
assertThrows(NullPointerException.class, () -> new Lesson(null)); | ||
} | ||
|
||
@Test | ||
public void constructor_invalidLesson_throwsIllegalArgumentException() { | ||
String invalidLesson = ""; | ||
assertThrows(IllegalArgumentException.class, () -> new Lesson(invalidLesson)); | ||
} | ||
|
||
@Test | ||
public void isValidLesson() { | ||
// null lesson | ||
assertThrows(NullPointerException.class, () -> Lesson.isValidLesson(null)); | ||
|
||
// invalid lessons | ||
assertFalse(Lesson.isValidLesson("")); // empty string | ||
assertFalse(Lesson.isValidLesson(" ")); // spaces only | ||
assertFalse(Lesson.isValidLesson("Math|invalidDate|09:00|0")); // invalid date format | ||
assertFalse(Lesson.isValidLesson("Math|01-01-2023|invalidTime|0")); // invalid time format | ||
assertFalse(Lesson.isValidLesson("Math|01-01-2023|09:00|2")); // invalid isCompleted value | ||
|
||
// valid lessons | ||
assertTrue(Lesson.isValidLesson("Math|01-01-2023|09:00|0")); | ||
assertTrue(Lesson.isValidLesson("Science|01-01-2023|10:00|1")); | ||
} | ||
|
||
@Test | ||
public void equals() { | ||
Lesson lesson = new Lesson("Math|01-01-2023|09:00|0"); | ||
|
||
// same values -> returns true | ||
assertTrue(lesson.equals(new Lesson("Math|01-01-2023|09:00|0"))); | ||
|
||
// same object -> returns true | ||
assertEquals(lesson, lesson); | ||
|
||
// null -> returns false | ||
assertFalse(lesson.equals(null)); | ||
|
||
// different types -> returns false | ||
assertFalse(lesson.equals(5.0f)); | ||
|
||
// different values -> returns false | ||
assertFalse(lesson.equals(new Lesson("Science|01-01-2023|09:00|0"))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package seedu.address.model.person; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static seedu.address.testutil.Assert.assertThrows; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class SubjectTest { | ||
|
||
@Test | ||
public void constructor_null_throwsNullPointerException() { | ||
assertThrows(NullPointerException.class, () -> new Subject(null)); | ||
} | ||
|
||
@Test | ||
public void constructor_invalidSubject_throwsIllegalArgumentException() { | ||
String invalidSubject = ""; | ||
assertThrows(IllegalArgumentException.class, () -> new Subject(invalidSubject)); | ||
} | ||
|
||
@Test | ||
public void isValidSubject() { | ||
// null subject | ||
assertThrows(NullPointerException.class, () -> Subject.isValidSubject(null)); | ||
|
||
// invalid subjects | ||
assertFalse(Subject.isValidSubject("")); // empty string | ||
assertFalse(Subject.isValidSubject(" ")); // spaces only | ||
assertFalse(Subject.isValidSubject("123")); // numeric characters | ||
assertFalse(Subject.isValidSubject("!@#$%")); // special characters | ||
|
||
// valid subjects | ||
assertTrue(Subject.isValidSubject("Math")); | ||
assertTrue(Subject.isValidSubject("English Literature")); | ||
assertTrue(Subject.isValidSubject("Computer Science")); | ||
assertTrue(Subject.isValidSubject("Social Studies")); | ||
} | ||
|
||
@Test | ||
public void equals() { | ||
Subject subject = new Subject("Math"); | ||
|
||
// same values -> returns true | ||
assertEquals(subject, new Subject("Math")); | ||
|
||
// same object -> returns true | ||
assertEquals(subject, subject); | ||
|
||
// null -> returns false | ||
assertNotEquals(null, subject); | ||
|
||
// different types -> returns false | ||
assertNotEquals(5.0f, subject, String.valueOf(0.0)); | ||
|
||
// different values -> returns false | ||
assertNotEquals(subject, new Subject("Science")); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.