Skip to content

Commit

Permalink
Add additional tests for itinerary-related classes
Browse files Browse the repository at this point in the history
  • Loading branch information
limkoonkiat committed Oct 27, 2020
1 parent 5558028 commit 2b1e2bd
Show file tree
Hide file tree
Showing 28 changed files with 1,344 additions and 106 deletions.
5 changes: 4 additions & 1 deletion src/main/java/seedu/address/model/itinerary/Day.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public List<ItineraryAttraction> getItineraryAttractions() {
* Adds an itinerary attraction and sorts them based on their start times.
*/
public void addItineraryAttraction(ItineraryAttraction toAdd) {
for (ItineraryAttraction itineraryAttraction : itineraryAttractions) {
checkArgument(!toAdd.isTimingClash(itineraryAttraction),
"The timing clashes with another attraction in the itinerary");
}
itineraryAttractions.add(toAdd);
itineraryAttractions.sort(new Comparator<ItineraryAttraction>() {
@Override
Expand All @@ -63,7 +67,6 @@ public int compare(ItineraryAttraction first, ItineraryAttraction second) {
} else if (first.getStartTime().isLaterThan(second.getStartTime())) {
return 1;
} else {
assert false; // There cannot be 2 itinerary attractions with same start time in a day
return 0;
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/seedu/address/model/itinerary/Itinerary.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -70,7 +71,7 @@ public Budget getBudget() {
}

public List<Day> getDays() {
return days;
return Collections.unmodifiableList(days);
}

public Day getDay(Index day) {
Expand Down Expand Up @@ -162,8 +163,7 @@ public boolean isSameItinerary(Itinerary otherItinerary) {
return otherItinerary != null
&& otherItinerary.getName().equals(getName())
&& otherItinerary.getStartDate().equals(getStartDate())
&& otherItinerary.getEndDate().equals(getEndDate())
&& otherItinerary.getBudget().equals(getBudget());
&& otherItinerary.getEndDate().equals(getEndDate());
}

/**
Expand All @@ -186,7 +186,8 @@ public boolean equals(Object other) {
&& otherItinerary.getStartDate().equals(getStartDate())
&& otherItinerary.getEndDate().equals(getEndDate())
&& otherItinerary.getBudget().equals(getBudget())
&& otherItinerary.getDays().equals(getDays());
&& otherItinerary.getDays().equals(getDays())
&& otherItinerary.getItineraryAttractions().equals(getItineraryAttractions());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ public boolean isSameItineraryAttraction(ItineraryAttraction otherItineraryAttra
* Returns false if timing does not clash with this itinerary attraction.
*/
public boolean isTimingClash(ItineraryAttraction itineraryAttraction) {
// Might make a mistake here with the ! due to De Morgan's law
return !this.getStartTime().isEarlierThan(itineraryAttraction.getStartTime())
&& !this.getEndTime().isLaterThan(itineraryAttraction.getEndTime());
return (this.getStartTime().isEarlierThan(itineraryAttraction.getEndTime()))
&& (itineraryAttraction.getStartTime().isEarlierThan(this.getEndTime()));
}

/**
Expand Down Expand Up @@ -128,7 +127,9 @@ public int hashCode() {
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append(super.toString())
.append(" Start time: ")
.append(startTime)
.append(" End time: ")
.append(endTime);

return builder.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public boolean test(Itinerary itinerary) {
|| StringUtil.containsWordIgnoreCase(itinerary.getDescription().value, keyword)
|| StringUtil.containsWordIgnoreCase(itinerary.getStartDate().toString(), keyword)
|| StringUtil.containsWordIgnoreCase(itinerary.getEndDate().toString(), keyword)
|| StringUtil.containsWordIgnoreCase(itinerary.getBudget().value, keyword)
|| itinerary.getBudget().value.contains(keyword) // numerical budget value
|| itinerary.getBudget().toString().contains(keyword) // budget value with $
)
) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public boolean equals(Object other) {

@Override
public String toString() {
return String.valueOf(time);
return String.format("%04d", time);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.attraction.Attraction;
import seedu.address.model.itinerary.ItineraryAttraction;
import seedu.address.model.itinerary.ItineraryTime;

/**
* Jackson-friendly version of {@link ItineraryAttraction}.
Expand All @@ -16,23 +17,28 @@ class JsonAdaptedItineraryAttraction {
public static final String MISSING_FIELD_MESSAGE_FORMAT = "Itinerary attraction's %s field is missing!";

private final JsonAdaptedAttraction attraction;
// todo add more fields specific to itinerary attraction
private final String startTime;
private final String endTime;

/**
* Constructs a {@code JsonAdaptedItineraryAttraction} with the given itinerary attraction details.
*/
@JsonCreator
public JsonAdaptedItineraryAttraction(@JsonProperty("attraction") JsonAdaptedAttraction attraction) {
public JsonAdaptedItineraryAttraction(@JsonProperty("attraction") JsonAdaptedAttraction attraction,
@JsonProperty("startTime") String startTime,
@JsonProperty("endTime") String endTime) {
this.attraction = attraction;
// todo add more fields specific to itinerary attraction
this.startTime = startTime;
this.endTime = endTime;
}

/**
* Converts a given {@code ItineraryAttraction} into this class for Jackson use.
*/
public JsonAdaptedItineraryAttraction(ItineraryAttraction source) {
attraction = new JsonAdaptedAttraction(source.getAttraction());
// todo add more fields specific to itinerary attraction
startTime = source.getStartTime().toString();
endTime = source.getEndTime().toString();
}

/**
Expand All @@ -42,15 +48,38 @@ public JsonAdaptedItineraryAttraction(ItineraryAttraction source) {
* @throws IllegalValueException if there were any data constraints violated in the adapted itinerary attraction.
*/
public ItineraryAttraction toModelType() throws IllegalValueException {
// todo add more fields specific to itinerary attraction
final Attraction modelAttraction;
final ItineraryTime modelStartTime;
final ItineraryTime modelEndTime;

// Start time is not optional
if (startTime == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT,
ItineraryTime.class.getSimpleName()));
} else if (!ItineraryTime.isValidItineraryTime(startTime)) {
throw new IllegalValueException(ItineraryTime.MESSAGE_CONSTRAINTS);
} else {
modelStartTime = new ItineraryTime(startTime);
}

// End time is not optional
if (endTime == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT,
ItineraryTime.class.getSimpleName()));
} else if (!ItineraryTime.isValidItineraryTime(endTime)) {
throw new IllegalValueException(ItineraryTime.MESSAGE_CONSTRAINTS);
} else {
modelEndTime = new ItineraryTime(endTime);
}

// Attraction is not optional
if (attraction == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT,
Attraction.class.getSimpleName()));
} else {
// todo make these not null next time
return new ItineraryAttraction(attraction.toModelType(), null, null);
modelAttraction = attraction.toModelType();
}

return new ItineraryAttraction(modelAttraction, modelStartTime, modelEndTime);
}
}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/ItineraryListCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ItineraryListCard(Itinerary itinerary, int displayedIndex) {
startDate.setText(itinerary.getStartDate().value);
endDate.setText(itinerary.getEndDate().value);
description.setText(itinerary.getDescription().value);
budget.setText(itinerary.getBudget().value);
budget.setText(itinerary.getBudget().toString());
locale.setText(itinerary.getLocations());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"itineraries" : [ {
"name" : "Japan trip",
"description" : "Visit Japan",
"startDate" : "12-12-2020",
"endDate" : "14-12-2020",
"budget" : "3020",
"days" : [ {
"day" : "1",
"itineraryAttractions" : [ ]
}, {
"day" : "2",
"itineraryAttractions" : [ ]
}, {
"day" : "3",
"itineraryAttractions" : [ ]
} ]
}, {
"name" : "Japan trip",
"description" : "Visit Japan",
"startDate" : "12-12-2020",
"endDate" : "14-12-2020",
"budget" : "3020",
"days" : [ {
"day" : "1",
"itineraryAttractions" : [ ]
}, {
"day" : "2",
"itineraryAttractions" : [ ]
}, {
"day" : "3",
"itineraryAttractions" : [ ]
} ]
} ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"itineraries" : [ {
"name" : "Japan trip",
"description" : "Visit Japan",
"startDate" : "12-122-2020",
"endDate" : "14-12-2020",
"budget" : "3020"
} ]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"_comment": "TrackPad save file which contains the same Attraction values as in TypicalAttractions#getTypicalTrackPad()",
"_comment": "TrackPad save file which contains the same Attraction values as in TypicalAttractions#getTypicalAttractions()",
"attractions" : [ {
"name" : "JurongBirdPark",
"phone" : "94351253",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{
"_comment": "TrackPad save file which contains the same Itinerary values as in TypicalItineraries#getTypicalItineraries()",
"itineraries" : [ {
"name" : "Singapore Zoos",
"description" : "Rediscover our wildlife parks!",
"startDate" : "06-07-2019",
"endDate" : "07-07-2019",
"budget" : "500.00",
"days" : [ {
"day" : "1",
"itineraryAttractions" : [ {
"attraction" : {
"name" : "Singapore Zoo",
"phone" : "95352563",
"email" : "singaporezoo@example.com",
"address" : "80 Mandai Lake Rd",
"description" : "",
"location" : "Singapore, Singapore",
"openingHours" : "1000-1800",
"priceRange" : "",
"rating" : "",
"visited" : "",
"tagged" : [ ]
},
"startTime" : "1000",
"endTime" : "1700"
}, {
"attraction" : {
"name" : "Night Safari",
"phone" : "98765432",
"email" : "nightsafari@example.com",
"address" : "80 Mandai Lake Rd",
"description" : "The world's first nocturnal zoo.",
"location": "Singapore, Singapore",
"openingHours": "1800-2300",
"priceRange": "",
"rating": "",
"visited": "",
"tagged" : [ "animals", "night" ]
},
"startTime" : "1900",
"endTime" : "2300"
} ]
}, {
"day" : "2",
"itineraryAttractions" : [ {
"attraction" : {
"name" : "River Safari",
"phone" : "87652533",
"email" : "riversafari@example.com",
"address" : "80 Mandai Lake Rd",
"description" : "A river-themed zoo and aquarium in Singapore.",
"location": "Singapore, Singapore",
"openingHours": "1000-1800",
"priceRange": "",
"rating": "",
"visited": "",
"tagged" : [ "panda" ]
},
"startTime" : "1200",
"endTime" : "1800"
} ]
} ]
}, {
"name" : "Paris Trip",
"description" : "Visit the City of Light",
"startDate" : "21-12-2020",
"endDate" : "26-12-2020",
"budget" : "",
"days" : [ {
"day" : "1",
"itineraryAttractions" : [ {
"attraction" : {
"name" : "Eiffel Tower",
"phone" : "33892701239",
"email" : "eiffel@example.com",
"address" : "Champ de Mars, 5 Avenue Anatole France, 75007",
"description" : "Gustave Eiffel's iconic, wrought-iron 1889 tower, with steps and elevators to observation decks.",
"location" : "Paris, France",
"openingHours" : "1000-2200",
"priceRange" : "HIGH",
"rating" : "4.8",
"visited" : "FALSE",
"tagged" : [ "activity" ]
},
"startTime" : "0900",
"endTime" : "1500"
} ]
}, {
"day" : "2",
"itineraryAttractions" : [ {
"attraction" : {
"name" : "Louvre Museum",
"phone" : "330140205317",
"email" : "info@louvre.fr",
"address" : "Rue de Rivoli, 75001",
"description" : "The Louvre, or the Louvre Museum, is the world's largest art museum and a historic monument in Paris, France.",
"location": "Paris, France",
"openingHours": "0900-1800",
"priceRange": "MEDIUM",
"rating": "4.7",
"visited": "FALSE",
"tagged" : [ ]
},
"startTime" : "1100",
"endTime" : "1800"
} ]
}, {
"day" : "3",
"itineraryAttractions" : [ {
"attraction" : {
"name" : "Cathedrale Notre Dame de Paris",
"phone" : "",
"email" : "",
"address" : "6 Parvis Notre-Dame - Pl. Jean-Paul II, 75004",
"description" : "",
"location": "Paris, France",
"openingHours": "",
"priceRange": "",
"rating": "",
"visited": "",
"tagged" : [ ]
},
"startTime" : "1200",
"endTime" : "1500"
} ]
} ]
} ]
}

0 comments on commit 2b1e2bd

Please sign in to comment.