forked from nus-cs2103-AY2324S1/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from asdfghjkxd/branch-MoreJUnitTests
Add new unit tests for some tasks
- Loading branch information
Showing
2 changed files
with
310 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
package juke.tasks; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.time.DateTimeException; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Tests the {@code JukeDeadline} class. | ||
*/ | ||
public class JukeDeadlineTest { | ||
/** | ||
* Tests if the input "this is valid" and 01-01-2001 0001 creates an instance of {@code JukeTodo} properly. | ||
*/ | ||
@Test | ||
public void constructor_valid_successOne() { | ||
assertDoesNotThrow(() -> new JukeDeadline("this is valid", LocalDateTime.of( | ||
2001, 1, 1, 0, 1 | ||
))); | ||
} | ||
|
||
/** | ||
* Tests if the input "this is also valid", 31-12-9999 2359 and true | ||
* creates an instance of {@code JukeTodo} properly. | ||
*/ | ||
@Test | ||
public void constructor_valid_successTwo() { | ||
assertDoesNotThrow(() -> new JukeDeadline("this is also valid", LocalDateTime.of( | ||
9999, 12, 31, 23, 59 | ||
), true)); | ||
} | ||
|
||
/** | ||
* Tests if the input "this is obviously valid", 31-12-9999 2359 and false creates an instance of | ||
* {@code JukeTodo} properly. | ||
*/ | ||
@Test | ||
public void constructor_valid_successThree() { | ||
assertDoesNotThrow(() -> new JukeDeadline("this is also valid", LocalDateTime.of( | ||
9999, 12, 31, 23, 59 | ||
), false)); | ||
} | ||
|
||
/** | ||
* Tests if an illegal date is permitted. | ||
*/ | ||
@Test | ||
public void constructor_invalid_failureOne() { | ||
assertThrows(DateTimeException.class, () -> new JukeDeadline("this is valid", LocalDateTime.parse( | ||
"2001-13-01T01:00", DateTimeFormatter.ISO_LOCAL_DATE_TIME | ||
))); | ||
} | ||
|
||
/** | ||
* Tests if an illegal date is permitted. | ||
*/ | ||
@Test | ||
public void constructor_invalid_failureTwo() { | ||
assertThrows(DateTimeException.class, () -> new JukeDeadline("this is valid", LocalDateTime.parse( | ||
"2023-01-2022T25:59", DateTimeFormatter.ISO_LOCAL_DATE_TIME | ||
))); | ||
} | ||
|
||
/** | ||
* Tests if an illegal date is permitted. | ||
*/ | ||
@Test | ||
public void constructor_invalid_failureThree() { | ||
assertThrows(DateTimeException.class, () -> new JukeDeadline("this is valid", LocalDateTime.parse( | ||
"1-01-2022T25:59", DateTimeFormatter.ISO_LOCAL_DATE_TIME | ||
))); | ||
} | ||
|
||
/** | ||
* Tests if the created deadlines are properly converted to the correct save String. | ||
*/ | ||
@Test | ||
public void save_valid_successOne() { | ||
JukeDeadline jukeDeadline = new JukeDeadline("this is valid", LocalDateTime.of( | ||
2001, 1, 1, 0, 1 | ||
)); | ||
|
||
assertEquals(jukeDeadline.toString(), "[D] [ ] this is valid (by 01 Jan 2001, 0001 hrs)"); | ||
} | ||
|
||
/** | ||
* Tests if the created (not completed) deadline are properly converted to the correct save String. | ||
*/ | ||
@Test | ||
public void save_valid_successTwo() { | ||
JukeDeadline jukeDeadline = new JukeDeadline("this is also valid", LocalDateTime.of( | ||
9999, 12, 31, 23, 59 | ||
), true); | ||
assertEquals(jukeDeadline.toString(), "[D] [✓] this is also valid (by 31 Dec 9999, 2359 hrs)"); | ||
} | ||
|
||
/** | ||
* Tests if the created (completed) deadline are properly converted to the correct save String. | ||
*/ | ||
@Test | ||
public void save_valid_successThree() { | ||
JukeDeadline jukeDeadline = new JukeDeadline("this is also valid", LocalDateTime.of( | ||
9999, 12, 31, 23, 59 | ||
), false); | ||
assertEquals(jukeDeadline.toString(), "[D] [ ] this is also valid (by 31 Dec 9999, 2359 hrs)"); | ||
} | ||
|
||
/** | ||
* Tests if the matching function will return correctly if the input string is found within the task | ||
* description. | ||
*/ | ||
@Test | ||
public void stringMatches_valid_successOne() { | ||
JukeDeadline jukeDeadline = new JukeDeadline("this is valid", LocalDateTime.of( | ||
2001, 1, 1, 0, 1 | ||
)); | ||
assertTrue(jukeDeadline.stringMatches("this ")); | ||
} | ||
|
||
/** | ||
* Tests if the matching function will return correctly if the input string is found within the task | ||
* description. | ||
*/ | ||
@Test | ||
public void stringMatches_valid_successTwo() { | ||
JukeDeadline jukeDeadline = new JukeDeadline("this is valid", LocalDateTime.of( | ||
2001, 1, 1, 0, 1 | ||
)); | ||
assertTrue(jukeDeadline.stringMatches(" i")); | ||
} | ||
|
||
/** | ||
* Tests if the matching function will return correctly if the input string is found within the task | ||
* description. | ||
*/ | ||
@Test | ||
public void stringMatches_valid_successThree() { | ||
JukeDeadline jukeDeadline = new JukeDeadline("this is valid", LocalDateTime.of( | ||
2001, 1, 1, 0, 1 | ||
)); | ||
assertTrue(jukeDeadline.stringMatches("is ")); | ||
} | ||
|
||
/** | ||
* Tests if the matching function will return correctly if the input string is found within the task | ||
* description. This method is supposed to fail. | ||
*/ | ||
@Test | ||
public void stringMatches_invalid_failureOne() { | ||
JukeDeadline jukeDeadline = new JukeDeadline("this is valid", LocalDateTime.of( | ||
2001, 1, 1, 0, 1 | ||
)); | ||
assertFalse(jukeDeadline.stringMatches("x")); | ||
} | ||
|
||
/** | ||
* Tests if the matching function will return correctly if the input string is found within the task | ||
* description. This method is supposed to fail. | ||
*/ | ||
@Test | ||
public void stringMatches_invalid_failureTwo() { | ||
JukeDeadline jukeDeadline = new JukeDeadline("this is valid", LocalDateTime.of( | ||
2001, 1, 1, 0, 1 | ||
)); | ||
assertFalse(jukeDeadline.stringMatches("si")); | ||
} | ||
|
||
/** | ||
* Tests if the matching function will return correctly if the input string is found within the task | ||
* description. This method is supposed to fail. | ||
*/ | ||
@Test | ||
public void stringMatches_invalid_failureThree() { | ||
JukeDeadline jukeDeadline = new JukeDeadline("this is valid", LocalDateTime.of( | ||
2001, 1, 1, 0, 1 | ||
)); | ||
assertFalse(jukeDeadline.stringMatches("this is valdi")); | ||
} | ||
} |
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,124 @@ | ||
package juke.tasks; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
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 org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Tests the {@code JukeTodo} class. | ||
*/ | ||
public class JukeTodoTest { | ||
/** | ||
* Tests if the input "this is valid" creates an instance of {@code JukeTodo} properly. | ||
*/ | ||
@Test | ||
public void constructor_valid_successOne() { | ||
assertDoesNotThrow(() -> new JukeTodo("this is valid")); | ||
} | ||
|
||
/** | ||
* Tests if the input "this is also quite valid" with true creates an instance of {@code JukeTodo} properly. | ||
*/ | ||
@Test | ||
public void constructor_valid_successTwo() { | ||
assertDoesNotThrow(() -> new JukeTodo("this is also quite valid", true)); | ||
} | ||
|
||
/** | ||
* Tests if the input "this is also quite valid" with false creates an instance of {@code JukeTodo} properly. | ||
*/ | ||
@Test | ||
public void constructor_valid_successThree() { | ||
assertDoesNotThrow(() -> new JukeTodo("this is also quite valid", false)); | ||
} | ||
|
||
/** | ||
* Tests if the created todos are properly converted to the correct save String. | ||
*/ | ||
@Test | ||
public void save_valid_successOne() { | ||
JukeTodo jukeTodo = new JukeTodo("this is valid"); | ||
assertEquals(jukeTodo.toString(), "[T] [ ] this is valid"); | ||
} | ||
|
||
/** | ||
* Tests if the created (not completed) todos are properly converted to the correct save String. | ||
*/ | ||
@Test | ||
public void save_valid_successTwo() { | ||
JukeTodo jukeTodo = new JukeTodo("this is also quite valid", true); | ||
assertEquals(jukeTodo.toString(), "[T] [✓] this is also quite valid"); | ||
} | ||
|
||
/** | ||
* Tests if the created (completed) todos are properly converted to the correct save String. | ||
*/ | ||
@Test | ||
public void save_valid_successThree() { | ||
JukeTodo jukeTodo = new JukeTodo("this is also quite valid", false); | ||
assertEquals(jukeTodo.toString(), "[T] [ ] this is also quite valid"); | ||
} | ||
|
||
/** | ||
* Tests if the matching function will return correctly if the input string is found within the task | ||
* description. | ||
*/ | ||
@Test | ||
public void stringMatches_valid_successOne() { | ||
JukeTodo jukeTodo = new JukeTodo("this is valid"); | ||
assertTrue(jukeTodo.stringMatches("this ")); | ||
} | ||
|
||
/** | ||
* Tests if the matching function will return correctly if the input string is found within the task | ||
* description. | ||
*/ | ||
@Test | ||
public void stringMatches_valid_successTwo() { | ||
JukeTodo jukeTodo = new JukeTodo("this is valid"); | ||
assertTrue(jukeTodo.stringMatches(" i")); | ||
} | ||
|
||
/** | ||
* Tests if the matching function will return correctly if the input string is found within the task | ||
* description. | ||
*/ | ||
@Test | ||
public void stringMatches_valid_successThree() { | ||
JukeTodo jukeTodo = new JukeTodo("this is valid"); | ||
assertTrue(jukeTodo.stringMatches("is ")); | ||
} | ||
|
||
/** | ||
* Tests if the matching function will return correctly if the input string is found within the task | ||
* description. This method is supposed to fail. | ||
*/ | ||
@Test | ||
public void stringMatches_invalid_failureOne() { | ||
JukeTodo jukeTodo = new JukeTodo("this is valid"); | ||
assertFalse(jukeTodo.stringMatches("x")); | ||
} | ||
|
||
/** | ||
* Tests if the matching function will return correctly if the input string is found within the task | ||
* description. This method is supposed to fail. | ||
*/ | ||
@Test | ||
public void stringMatches_invalid_failureTwo() { | ||
JukeTodo jukeTodo = new JukeTodo("this is valid"); | ||
assertFalse(jukeTodo.stringMatches("si")); | ||
} | ||
|
||
/** | ||
* Tests if the matching function will return correctly if the input string is found within the task | ||
* description. This method is supposed to fail. | ||
*/ | ||
@Test | ||
public void stringMatches_invalid_failureThree() { | ||
JukeTodo jukeTodo = new JukeTodo("this is valid"); | ||
assertFalse(jukeTodo.stringMatches("this is valdi")); | ||
} | ||
} |