Skip to content

Commit 38825ff

Browse files
Create a test directory to test ToDo and DateAndTime classes using JUnit
The ToDoTest class tests the toString and isDone methods, while the DateAndTimeTest class tests the dayParser and isValidDate methods.
1 parent abb12c6 commit 38825ff

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package duke;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
6+
7+
import org.junit.jupiter.api.Test;
8+
9+
/**
10+
* Test cases for the {@link DateAndTime} class.
11+
*/
12+
public class DateAndTimeTest {
13+
14+
/**
15+
* Test the {@link DateAndTime#isValidDate()} method.
16+
*/
17+
@Test
18+
public void validTest() {
19+
DateAndTime test1 = new DateAndTime();
20+
assertTrue(test1.isValidDate("2023-04-01", "2023-04-02"));
21+
}
22+
23+
/**
24+
* Test the {@link DateAndTime#dayParse()} method.
25+
*/
26+
@Test
27+
public void dateStringTest() {
28+
DateAndTime test2 = new DateAndTime();
29+
assertEquals("APRIL 1, 2023", test2.dayParse("2023-04-01"));
30+
}
31+
32+
/**
33+
* Test the {@link DateAndTime#dayParse()} method.
34+
*/
35+
@Test
36+
public void dateTimeStringTest() {
37+
DateAndTime test3 = new DateAndTime();
38+
assertEquals("APRIL 3, 2023, 18:00", test3.dayParse("2023-04-03", "18:00"));
39+
}
40+
}

src/test/java/duke/ToDoTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package duke;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
6+
7+
import org.junit.jupiter.api.Test;
8+
9+
/**
10+
* Test cases for the {@link ToDo} class.
11+
*/
12+
public class ToDoTest {
13+
14+
/**
15+
* Test the {@link ToDo#toString()} method.
16+
*/
17+
@Test
18+
public void toStringTest() {
19+
ToDo test1 = new ToDo("test");
20+
assertEquals(test1.toString(), "[T][ ] test");
21+
}
22+
23+
/**
24+
* Test the {@link ToDo#isDone()} method.
25+
*/
26+
@Test
27+
public void doneTest() {
28+
ToDo test2 = new ToDo("test");
29+
test2.done();
30+
assertTrue(test2.isDone());
31+
}
32+
33+
/**
34+
* Test the {@link ToDo#isDone()} method.
35+
*/
36+
@Test
37+
public void unDoneTest() {
38+
ToDo test3 = new ToDo("test");
39+
assertFalse(test3.isDone());
40+
}
41+
}

0 commit comments

Comments
 (0)