Skip to content

Commit

Permalink
add testcase for timeinterval
Browse files Browse the repository at this point in the history
  • Loading branch information
Kailash201 committed Nov 10, 2023
1 parent c6e4364 commit 1454c07
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/model/Time.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class Time {
* @param hour The time of the day.
*/
public Time(DayOfWeek day, LocalTime hour) {
requireNonNull(day);
requireNonNull(hour);
this.day = day;
this.hour = hour;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/model/TimeInterval.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.model;


import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_FREETIME;

import java.time.DayOfWeek;
Expand Down Expand Up @@ -31,6 +32,8 @@ public class TimeInterval {
* @param end The end time of the interval.
*/
public TimeInterval(Time start, Time end) {
requireNonNull(start);
requireNonNull(end);
this.start = start;
this.end = end;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void execute_newPerson_success() {
public void execute_duplicatePerson_throwsCommandException() {
Person personInList = model.getAddressBook().getPersonList().get(0);
assertCommandFailure(new AddCommand(personInList), model,
AddCommand.MESSAGE_DUPLICATE_PERSON);
String.format(AddCommand.MESSAGE_DUPLICATE_PERSON, personInList.getName().toString()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void parse_allFieldsPresent_success() {
Person expectedPerson = new PersonBuilder(BOB).build();

// whitespace only preamble
assertParseSuccess(parser, PREAMBLE_WHITESPACE + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB
9(parser, PREAMBLE_WHITESPACE + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB
+ GROUP_DESC_BOB, new AddCommand(expectedPerson));


Expand Down
172 changes: 172 additions & 0 deletions src/test/java/seedu/address/model/TimeIntervalTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
package seedu.address.model;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.testutil.Assert.assertThrows;
import java.time.DayOfWeek;
import java.time.LocalTime;
import java.util.ArrayList;
import org.junit.jupiter.api.Test;
import seedu.address.testutil.TimeBuilder;
import seedu.address.testutil.TypicalTimeIntervals;

public class TimeIntervalTest {

@Test
public void constructor_nullArguments_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> new TimeInterval(null, null));
}

@Test
public void isTimeIntervalOverlap_noOverlaps_returnFalse() {
ArrayList<TimeInterval> timeIntervalArrayList = new ArrayList<>();
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalOneNoOverlap);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalTwoNoOverlap);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalThreeNoOverlap);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalFourNoOverlap);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalFiveNoOverlap);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalSixNoOverlap);
assertFalse(TimeInterval.isTimeIntervalOverlap(timeIntervalArrayList));
}

//all time interval overlaps
@Test
public void isTimeIntervalOverlap_OverlapsA_returnTrue() {
ArrayList<TimeInterval> timeIntervalArrayList = new ArrayList<>();
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalOneOverlapA);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalTwoOverlapA);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalThreeOverlapA);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalFourOverlapA);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalFiveOverlapA);
assertTrue(TimeInterval.isTimeIntervalOverlap(timeIntervalArrayList));
}

@Test
public void isTimeIntervalOverlap_OneOverlapsA_returnTrue() {
ArrayList<TimeInterval> timeIntervalArrayList = new ArrayList<>();
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalOneOverlapA);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalThreeNoOverlap);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalFourNoOverlap);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalTwoOverlapA);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalFiveNoOverlap);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalSixNoOverlap);
assertTrue(TimeInterval.isTimeIntervalOverlap(timeIntervalArrayList));
}

@Test
public void isTimeIntervalOverlap_EqualOverlapsA_returnTrue() {
ArrayList<TimeInterval> timeIntervalArrayList = new ArrayList<>();
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalOneOverlapA);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalFiveNoOverlap);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalSixNoOverlap);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalThreeOverlapA);
assertTrue(TimeInterval.isTimeIntervalOverlap(timeIntervalArrayList));
}

@Test
public void isTimeIntervalOverlap_InsideOutsideOverlapsB_returnTrue() {
ArrayList<TimeInterval> timeIntervalArrayList = new ArrayList<>();
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalOneOverlapB);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalFourNoOverlap);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalFiveNoOverlap);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalTwoOverlapB);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalSixNoOverlap);
assertTrue(TimeInterval.isTimeIntervalOverlap(timeIntervalArrayList));
}

@Test
public void isTimeIntervalOverlap_DiffDaysOverlapsC_returnTrue() {
ArrayList<TimeInterval> timeIntervalArrayList = new ArrayList<>();
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalOneOverlapC);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalFourNoOverlap);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalFiveNoOverlap);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalTwoOverlapC);
timeIntervalArrayList.add(TypicalTimeIntervals.timeIntervalSixNoOverlap);
assertTrue(TimeInterval.isTimeIntervalOverlap(timeIntervalArrayList));
}

@Test
public void isValidTimeIntervalSyntax_validInput_returnTrue() {
String input = "mon 1200 - fri 1300";
assertTrue(TimeInterval.isValidTimeIntervalSyntax(input));
}

@Test
public void isValidTimeIntervalSyntax_inValidInput_returnFalse() {
String input = "mon 1200 - ";
assertFalse(TimeInterval.isValidTimeIntervalSyntax(input));
}

@Test
public void isValidTimeIntervalSyntax_inValidInputA_returnFalse() {
String input = "mon 1200 fri 2200";
assertFalse(TimeInterval.isValidTimeIntervalSyntax(input));
}

@Test
public void isValidTimeIntervalSyntax_inValidInputB_returnFalse() {
String input = "mon1200 - fri 2200";
assertFalse(TimeInterval.isValidTimeIntervalSyntax(input));
}

@Test
public void isValidTimeIntervalSyntax_inValidInputC_returnFalse() {
String input = "mon 1300 - fri";
assertFalse(TimeInterval.isValidTimeIntervalSyntax(input));
}

@Test
public void isValidTimeIntervalLogic_validInput_returnTrue() {
Time start = new TimeBuilder().withDayAndHour(DayOfWeek.MONDAY, LocalTime.of(2,00)).build();
Time end = new TimeBuilder().withDayAndHour(DayOfWeek.WEDNESDAY, LocalTime.of(2,00)).build();
assertTrue(TimeInterval.isValidTimeIntervalLogic(start, end));
}

@Test
public void isValidTimeIntervalLogic_validInputB_returnFalse() {
Time start = new TimeBuilder().withDayAndHour(DayOfWeek.TUESDAY, LocalTime.of(23,59)).build();
Time end = new TimeBuilder().withDayAndHour(DayOfWeek.WEDNESDAY, LocalTime.of(00,00)).build();
assertTrue(TimeInterval.isValidTimeIntervalLogic(start, end));
}

@Test
public void isValidTimeIntervalLogic_inValidInputEqual_returnFalse() {
Time start = new TimeBuilder().withDayAndHour(DayOfWeek.MONDAY, LocalTime.of(2,00)).build();
Time end = new TimeBuilder().withDayAndHour(DayOfWeek.MONDAY, LocalTime.of(2,00)).build();
assertFalse(TimeInterval.isValidTimeIntervalLogic(start, end));
}

@Test
public void isValidTimeIntervalLogic_inValidInputEndBeforeStart_returnFalse() {
Time start = new TimeBuilder().withDayAndHour(DayOfWeek.WEDNESDAY, LocalTime.of(12,00)).build();
Time end = new TimeBuilder().withDayAndHour(DayOfWeek.MONDAY, LocalTime.of(2,00)).build();
assertFalse(TimeInterval.isValidTimeIntervalLogic(start, end));
}

@Test
public void isValidTimeIntervalLogic_inValidInputEndBeforeStartA_returnFalse() {
Time start = new TimeBuilder().withDayAndHour(DayOfWeek.WEDNESDAY, LocalTime.of(12,00)).build();
Time end = new TimeBuilder().withDayAndHour(DayOfWeek.WEDNESDAY, LocalTime.of(11,59)).build();
assertFalse(TimeInterval.isValidTimeIntervalLogic(start, end));
}

@Test
public void isValidTimeIntervalLogic_inValidInputEndBeforeStartB_returnFalse() {
Time start = new TimeBuilder().withDayAndHour(DayOfWeek.SUNDAY, LocalTime.of(12,00)).build();
Time end = new TimeBuilder().withDayAndHour(DayOfWeek.MONDAY, LocalTime.of(00,00)).build();
assertFalse(TimeInterval.isValidTimeIntervalLogic(start, end));
}













}
1 change: 1 addition & 0 deletions src/test/java/seedu/address/testutil/PersonBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public PersonBuilder(Person personToCopy) {
phone = personToCopy.getPhone();
email = personToCopy.getEmail();
grpList = personToCopy.getGroups();
timeIntervalList = personToCopy.getTime();
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/seedu/address/testutil/TypicalPersons.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TIME_MON;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -54,6 +55,8 @@ public class TypicalPersons {
public static final Person BOB = new PersonBuilder().withName(VALID_NAME_BOB).withPhone(VALID_PHONE_BOB)
.withEmail(VALID_EMAIL_BOB).withGroupList(VALID_GROUP_BOB).build();



public static final String KEYWORD_MATCHING_MEIER = "Meier"; // A keyword that matches MEIER

private TypicalPersons() {} // prevents instantiation
Expand Down
39 changes: 39 additions & 0 deletions src/test/java/seedu/address/testutil/TypicalTimeIntervals.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ public class TypicalTimeIntervals {
.withDayAndHour(DayOfWeek.MONDAY, LocalTime.of(14, 00)).build(),
new TimeBuilder().withDayAndHour(DayOfWeek.MONDAY, LocalTime.of(15, 00)).build()).build();

public static TimeInterval timeIntervalFourNoOverlap = new TimeIntervalBuilder()
.withStartTimeAndEndTime(new TimeBuilder()
.withDayAndHour(DayOfWeek.MONDAY, LocalTime.of(22, 00)).build(),
new TimeBuilder().withDayAndHour(DayOfWeek.MONDAY, LocalTime.of(23, 00)).build()).build();

public static TimeInterval timeIntervalFiveNoOverlap = new TimeIntervalBuilder()
.withStartTimeAndEndTime(new TimeBuilder()
.withDayAndHour(DayOfWeek.MONDAY, LocalTime.of(21, 05)).build(),
new TimeBuilder().withDayAndHour(DayOfWeek.MONDAY, LocalTime.of(21, 9)).build()).build();

public static TimeInterval timeIntervalSixNoOverlap = new TimeIntervalBuilder()
.withStartTimeAndEndTime(new TimeBuilder()
.withDayAndHour(DayOfWeek.MONDAY, LocalTime.of(21, 12)).build(),
new TimeBuilder().withDayAndHour(DayOfWeek.MONDAY, LocalTime.of(21, 23)).build()).build();


public static TimeInterval timeIntervalOneOverlapA = new TimeIntervalBuilder()
.withStartTimeAndEndTime(new TimeBuilder()
Expand Down Expand Up @@ -48,6 +63,30 @@ public class TypicalTimeIntervals {
new TimeBuilder().withDayAndHour(DayOfWeek.MONDAY, LocalTime.of(13, 00)).build()).build();


public static TimeInterval timeIntervalOneOverlapB = new TimeIntervalBuilder()
.withStartTimeAndEndTime(new TimeBuilder()
.withDayAndHour(DayOfWeek.MONDAY, LocalTime.of(5, 00)).build(),
new TimeBuilder().withDayAndHour(DayOfWeek.MONDAY, LocalTime.of(12, 00)).build()).build();

public static TimeInterval timeIntervalTwoOverlapB = new TimeIntervalBuilder()
.withStartTimeAndEndTime(new TimeBuilder()
.withDayAndHour(DayOfWeek.MONDAY, LocalTime.of(6, 00)).build(),
new TimeBuilder().withDayAndHour(DayOfWeek.MONDAY, LocalTime.of(8, 00)).build()).build();

public static TimeInterval timeIntervalOneOverlapC = new TimeIntervalBuilder()
.withStartTimeAndEndTime(new TimeBuilder()
.withDayAndHour(DayOfWeek.MONDAY, LocalTime.of(5, 00)).build(),
new TimeBuilder().withDayAndHour(DayOfWeek.WEDNESDAY, LocalTime.of(12, 00)).build()).build();

public static TimeInterval timeIntervalTwoOverlapC = new TimeIntervalBuilder()
.withStartTimeAndEndTime(new TimeBuilder()
.withDayAndHour(DayOfWeek.WEDNESDAY, LocalTime.of(6, 00)).build(),
new TimeBuilder().withDayAndHour(DayOfWeek.FRIDAY, LocalTime.of(8, 00)).build()).build();








Expand Down

0 comments on commit 1454c07

Please sign in to comment.