Skip to content

Commit

Permalink
Add test cases for UserPrefs.hashCode()
Browse files Browse the repository at this point in the history
Key Changes:
* adds a test case to verify that the hashCode() method in UserPrefs
returns the same value for equal objects
  • Loading branch information
PateShin committed Mar 21, 2024
1 parent 605dd42 commit fb44df8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,32 @@ public static Person[] getSamplePersons() {
new Person(new Id(240001), new Name("Alex Yeoh"), new Phone("87438807"),
new Email("[email protected]"),
new Address("Blk 30 Geylang Street 29, #06-40"),
new YearJoined("2024"),
new YearJoined("2024"),
getTagSet("friends")),
new Person(new Id(240002), new Name("Bernice Yu"), new Phone("99272758"),
new Email("[email protected]"),
new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"),
new YearJoined("2024"),
new YearJoined("2024"),
getTagSet("colleagues", "friends")),
new Person(new Id(240003), new Name("Charlotte Oliveiro"), new Phone("93210283"),
new Email("[email protected]"),
new Address("Blk 11 Ang Mo Kio Street 74, #11-04"),
new YearJoined("2024"),
new YearJoined("2024"),
getTagSet("neighbours")),
new Person(new Id(240004), new Name("David Li"), new Phone("91031282"),
new Email("[email protected]"),
new Address("Blk 436 Serangoon Gardens Street 26, #16-43"),
new YearJoined("2024"),
new YearJoined("2024"),
getTagSet("family")),
new Person(new Id(240005), new Name("Irfan Ibrahim"), new Phone("92492021"),
new Email("[email protected]"),
new Address("Blk 47 Tampines Street 20, #17-35"),
new YearJoined("2024"),
new YearJoined("2024"),
getTagSet("classmates")),
new Person(new Id(240006), new Name("Roy Balakrishnan"), new Phone("92624417"),
new Email("[email protected]"),
new Address("Blk 45 Aljunied Street 85, #11-31"),
new YearJoined("2024"),
new YearJoined("2024"),
getTagSet("colleagues"))
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public void execute_filteredList_success() {
public void execute_duplicatePersonUnfilteredList_failure() {
Person firstPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(firstPerson).withName("Benson Meier").build();

EditCommand editCommand = new EditCommand(
model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()).getId(), descriptor);

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

import static org.junit.jupiter.api.Assertions.assertEquals;
import static seedu.address.testutil.Assert.assertThrows;

import org.junit.jupiter.api.Test;
Expand All @@ -18,4 +19,14 @@ public void setPayBackFilePath_nullPath_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> userPrefs.setPayBackFilePath(null));
}

@Test
public void hashCode_equalObjects_returnsSameHashCode() {
UserPrefs userPrefs1 = new UserPrefs();
UserPrefs userPrefs2 = new UserPrefs();
userPrefs2.setGuiSettings(userPrefs1.getGuiSettings());
userPrefs2.setPayBackFilePath(userPrefs1.getPayBackFilePath());

assertEquals(userPrefs1.hashCode(), userPrefs2.hashCode());
}

}

0 comments on commit fb44df8

Please sign in to comment.