Skip to content

Commit

Permalink
Merge pull request #282 from shishirbychapur/master
Browse files Browse the repository at this point in the history
Update PPP
  • Loading branch information
shishirbychapur authored Nov 13, 2023
2 parents 60b4bd1 + 82407a5 commit 6df043d
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 32 deletions.
1 change: 0 additions & 1 deletion src/main/java/seedu/lovebook/model/DatePrefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public DatePrefs(ReadOnlyDatePrefs toBeCopied) {
*/
public void resetData(ReadOnlyDatePrefs newData) {
requireNonNull(newData);

setPreferences(newData.getPreferences().get(0));
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/lovebook/model/date/Avatar.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class Avatar {
public static final String MESSAGE_CONSTRAINTS = "Avatar should only contain numbers from 1 to 9.";
private static final int LOWER_BOUND = 1;
private static final int UPPER_BOUND = 10;
private static final int UPPER_BOUND = 10; // Exclusive

public final String value;

Expand All @@ -36,6 +36,8 @@ public Avatar() {
* @return the avatar number
*/
public String getAvatarNumber() {
int val = Integer.parseInt(value);
assert val >= LOWER_BOUND && val < UPPER_BOUND : "Avatar number is not valid";
return value;
}

Expand Down
13 changes: 7 additions & 6 deletions src/main/java/seedu/lovebook/model/date/Date.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import seedu.lovebook.model.date.horoscope.Horoscope;

/**
* Represents a Date in the lovebook.
* Guarantees: details are present and not null, field values are validated, immutable.
* Represents a Date in the LoveBook.
*/
public class Date implements Comparable<Date> {

Expand All @@ -27,7 +26,7 @@ public class Date implements Comparable<Date> {
private final Avatar avatar;

/**
* Every field must be present and not null.
* Constructs a {@code Date}.
*/
public Date(Name name, Age age, Gender gender, Height height, Income income, Horoscope horoscope) {
requireAllNonNull(name, age, gender, height);
Expand Down Expand Up @@ -93,10 +92,13 @@ public Name getName() {
}

public Age getAge() {
return age;
int age = Integer.parseInt(this.age.value);
assert age >= 18 && age <= 150 : "Invalid Age!";
return this.age;
}

public Gender getGender() {
assert gender.toString().equals(Gender.MALE) || gender.toString().equals(Gender.FEMALE) : "Invalid Gender!";
return gender;
}

Expand Down Expand Up @@ -134,7 +136,7 @@ public boolean isSamePerson(Date otherDate) {
}

/**
* Returns the score of the date based on how well it mactches the user preferences.
* Returns the score of the date based on how well it matches the user preferences.
*
* @param prefs User's date preferences
* @return the score of the date based on how it matches user preferences.
Expand Down Expand Up @@ -198,7 +200,6 @@ public boolean equals(Object other) {

@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing :your own
return Objects.hash(name, age, gender, height, income, horoscope, avatar);
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/lovebook/model/date/Gender.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
public class Gender {
public static final String MESSAGE_CONSTRAINTS =
"Gender should be a single character, either M or F";
public static final String MALE = "M";
public static final String FEMALE = "F";
public static final String VALIDATION_REGEX = "[MF]{1}";
public final String value;

/**
* Constructs a {@code Age}.
* Constructs a {@code Gender}.
*
* @param gender A valid gender.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public JsonAdaptedDatePrefs(DatePrefs source) {
/**
* Converts this Jackson-friendly adapted date object into the model's {@code DatePrefs} object.
*
* @throws IllegalValueException if there were any data constraints violated in the adapted date.
* @throws IllegalValueException if there were any data constraints violated in the adapted prefs.
*/
public DatePrefs toModelType() throws IllegalValueException {
if (age == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public JsonSerializableDatePrefs(ReadOnlyDatePrefs source) {
}

/**
* Converts these preferences into the model's {@code Preferences} object.
* Converts these preferences into the model's {@code DatePrefs} object.
*
* @throws IllegalValueException if there were any data constraints violated.
*/
Expand Down
33 changes: 23 additions & 10 deletions src/main/java/seedu/lovebook/ui/DateCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ public class DateCard extends UiPart<Region> {

private static final String FXML = "DateListCard.fxml";

private static final String MALE_AVATAR_FILE_PATH = "images/avatars/male/";
private static final String FEMALE_AVATAR_FILE_PATH = "images/avatars/female/";
private static final String INVALID_IMAGE_FILE_PATH = "images/bot.png";
private static final String STAR_IMAGE_FILE_PATH = "images/star.png";
private static final String HOROSCOPE_FILE_PATH = "images/horoscopes/";
private static final String MALE_GENDER_FILE_PATH = "images/genders/male.png";
private static final String FEMALE_GENDER_FILE_PATH = "images/genders/female.png";
private static final String AGE_HEIGHT = " years old, with a height of ";
private static final String HEIGHT_INCOME = "cm, and an income of $";
private static final String INCOME = " per month.";
private static final String PNG = ".png";


/**
* Note: Certain keywords such as "location" and "resources" are reserved keywords in JavaFX.
* As a consequence, UI elements' variable names cannot be set to such keywords
Expand Down Expand Up @@ -47,26 +60,26 @@ public DateCard(Date date, int displayedIndex) {
this.date = date;
id.setText(displayedIndex + ". ");
name.setText(date.getName().fullName);
aboutInfo.setText(date.getAge().value + " years old, with a height of " + date.getHeight().value + "cm, and "
+ "an income of $" + date.getIncome().value + " per month.");
aboutInfo.setText(date.getAge().value + AGE_HEIGHT + date.getHeight().value
+ HEIGHT_INCOME + date.getIncome().value + INCOME);
displayIcons();
}
private void displayIcons() {
try {
horoscopeImage.setImage(new Image("images/horoscopes/" + date.getHoroscope().value.toLowerCase()
+ ".png"));
horoscopeImage.setImage(new Image(HOROSCOPE_FILE_PATH + date.getHoroscope().value.toLowerCase()
+ PNG));
if (date.getGender().value.equals("M")) {
genderImage.setImage(new Image("images/genders/male.png"));
avatarImage.setImage(new Image("images/avatars/male/" + date.getAvatar().value + ".png"));
genderImage.setImage(new Image(MALE_GENDER_FILE_PATH));
avatarImage.setImage(new Image(MALE_AVATAR_FILE_PATH + date.getAvatar().value + PNG));
} else {
genderImage.setImage(new Image("images/genders/female.png"));
avatarImage.setImage(new Image("images/avatars/female/" + date.getAvatar().value + ".png"));
genderImage.setImage(new Image(FEMALE_GENDER_FILE_PATH));
avatarImage.setImage(new Image(FEMALE_AVATAR_FILE_PATH + date.getAvatar().value + PNG));
}
if (date.getStar().isStarred.equals("true")) {
starImage.setImage(new Image("images/star.png"));
starImage.setImage(new Image(STAR_IMAGE_FILE_PATH));
}
} catch (IllegalArgumentException e) {
horoscopeImage.setImage(new Image("images/bot.png"));
horoscopeImage.setImage(new Image(INVALID_IMAGE_FILE_PATH));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public class CommandTestUtil {
public static final String HOROSCOPE_DESC_BOB = " " + PREFIX_HOROSCOPE + VALID_HOROSCOPE_BOB;
public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "James&"; // '&' not allowed in names
public static final String INVALID_AGE_DESC = " " + PREFIX_AGE + "911a"; // 'a' not allowed in ages
public static final String INVALID_GENDER_DESC = " " + PREFIX_GENDER + "bob!yahoo"; // missing '@' symbol
public static final String INVALID_HEIGHT_DESC = " " + PREFIX_HEIGHT; // empty string not allowed for addresses
public static final String INVALID_GENDER_DESC = " " + PREFIX_GENDER + "bob!yahoo"; // invalid gender
public static final String INVALID_HEIGHT_DESC = " " + PREFIX_HEIGHT; // empty string not allowed for height
public static final String INVALID_INCOME_DESC = " " + PREFIX_INCOME; // empty string not allowed for income
public static final String INVALID_HOROSCOPE_DESC =
" " + PREFIX_HOROSCOPE; // empty string not allowed for horoscope
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/seedu/lovebook/model/date/AgeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void isValidAge() {
// null age number
assertThrows(NullPointerException.class, () -> Age.isValidAge(null));

// invalid age numbers
// invalid age numbers [Applying Equivalence Partitioning]
assertFalse(Age.isValidAge("")); // empty string
assertFalse(Age.isValidAge(" ")); // spaces only
assertFalse(Age.isValidAge("age")); // non-numeric
Expand All @@ -36,9 +36,9 @@ public void isValidAge() {
assertFalse(Age.isValidAge("151")); // Age above 150

// valid age numbers
assertTrue(Age.isValidAge("91")); // exactly 3 numbers
assertTrue(Age.isValidAge("91"));
assertTrue(Age.isValidAge("23"));
assertTrue(Age.isValidAge("124")); // long age numbers
assertTrue(Age.isValidAge("124"));

// EP Boundary Values
assertTrue(Age.isValidAge("18")); // Age 18
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/seedu/lovebook/model/date/AvatarTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public void isValidAvatarTest() {
assertThrows(NumberFormatException.class, () -> Avatar.isValidAvatar(" ")); // spaces only
assertThrows(NumberFormatException.class, () -> Avatar.isValidAvatar("hello")); // Non-numeric

// Invalid Values
// Invalid Values [Applying Equivalence Partitioning]
assertFalse(Avatar.isValidAvatar("12")); // Above upper bound
assertFalse(Avatar.isValidAvatar("0")); // Below lower bound

// Boundary Values
// Boundary Values [Applying Boundary Value Analysis]
assertTrue(Avatar.isValidAvatar("1")); // Lower bound (inclusive)
assertTrue(Avatar.isValidAvatar("9")); // Upper bound (inclusive)
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/seedu/lovebook/model/date/GenderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public void isValidGender() {

// Repeated/Invalid
assertFalse(Gender.isValidGender("FF")); // repetition of F
assertFalse(Gender.isValidGender("MM")); // repetition of F
assertFalse(Gender.isValidGender("MM")); // repetition of M
assertFalse(Gender.isValidGender("T")); // something other than M or F

// valid gender
assertTrue(Gender.isValidGender("M")); // underscore in local part
assertTrue(Gender.isValidGender("F")); // period in local part
assertTrue(Gender.isValidGender("M"));
assertTrue(Gender.isValidGender("F"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void saveDatePrefs_nullDatePrefs_throwsNullPointerException() {
}

/**
* Saves {@code LoveBook} at the specified {@code filePath}.
* Saves {@code DatePrefs} at the specified {@code filePath}.
*/
private void saveDatePrefs(ReadOnlyDatePrefs datePrefs, String filePath) {
try {
Expand Down

0 comments on commit 6df043d

Please sign in to comment.