Skip to content

Commit

Permalink
Rewrite tests so that they cover some lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Chua Zi Long committed Apr 6, 2024
1 parent d374ef2 commit a93e19b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ public AddScheduleCommand parse(String userInput) throws ParseException {
try {
LocalDateTime dateTime1 = LocalDateTime.of(Integer.parseInt(startYear), Integer.parseInt(startMonth),
Integer.parseInt(startDay), Integer.parseInt(startHour), Integer.parseInt(startMinute));
} catch (DateTimeException e) {
throw new ParseException("Date or time are out of range.");
}

try {
LocalDateTime dateTime2 = LocalDateTime.of(Integer.parseInt(endYear), Integer.parseInt(endMonth),
Integer.parseInt(endDay), Integer.parseInt(endHour), Integer.parseInt(endMinute));
} catch (DateTimeException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,32 +159,38 @@ public void isFirstDateTimeBeforeSecond_validDateTimes_firstIsAfter() {
}

@Test
public void isFirstDateTimeBeforeSecond_validDateTimes_firstIsAfterThrows() {
public void parse_startDateTimeAfterEndDateTime_throwsParseException() {
AddScheduleCommandParser parser = new AddScheduleCommandParser();
String dateTimeStr1 = "2023-03-21 17:00";
String dateTimeStr2 = "2023-03-21 16:00";
// Note: Adjust the date-time format according to your actual parser implementation.
String startDateTime = "2023-03-21 17:00";
String endDateTime = "2023-03-21 16:00";

assertThrows(ParseException.class, () -> parser.parse(" add_schedule title/title d/description"
+ " start/" + dateTimeStr1 + " end/" + dateTimeStr2));
// Attempt to parse a schedule with startDateTime after endDateTime
String input = "add_schedule title/Meeting d/Discussion start/" + startDateTime + " end/" + endDateTime;

assertThrows(ParseException.class, () -> parser.parse(input),
"Start date-time after end date-time should throw ParseException.");
}

@Test
public void invalidDateTimes_outOfRangeStart() {
public void parse_invalidMonth_throwsParseException() {
AddScheduleCommandParser parser = new AddScheduleCommandParser();
String dateTimeStr1 = "2023-03-41 15:00";
String dateTimeStr2 = "2023-03-21 16:00";
String startDateTime = "2023-13-21 15:00"; // Invalid month
String endDateTime = "2023-03-21 16:00";

String input = "add_schedule title/Meeting d/Discussion start/" + startDateTime + " end/" + endDateTime;

assertThrows(ParseException.class, () -> parser.parse(" add_schedule title/title d/description"
+ " start/" + dateTimeStr1 + " end/" + dateTimeStr2));
assertThrows(ParseException.class, () -> parser.parse(input), "Invalid month should throw ParseException.");
}

@Test
public void invalidDateTimes_outOfRangeEnd() {
public void parse_invalidDay_throwsParseException() {
AddScheduleCommandParser parser = new AddScheduleCommandParser();
String dateTimeStr1 = "2023-03-21 15:00";
String dateTimeStr2 = "2023-03-41 16:00";
String startDateTime = "2023-03-32 15:00"; // Invalid day
String endDateTime = "2023-03-21 16:00";

String input = "add_schedule title/Meeting d/Discussion start/" + startDateTime + " end/" + endDateTime;

assertThrows(ParseException.class, () -> parser.parse(" add_schedule title/title d/description"
+ " start/" + dateTimeStr1 + " end/" + dateTimeStr2));
assertThrows(ParseException.class, () -> parser.parse(input), "Invalid day should throw ParseException.");
}
}

0 comments on commit a93e19b

Please sign in to comment.