Skip to content

Commit

Permalink
Add tests for #equals(Object) implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
pyokagan authored and damithc committed Aug 4, 2023
1 parent 136b577 commit 15b62ac
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/test/java/seedu/address/AppParametersTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package seedu.address;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.file.Paths;
import java.util.Collections;
Expand Down Expand Up @@ -44,6 +46,28 @@ public void toStringMethod() {
assertEquals(expected, appParameters.toString());
}

@Test
public void equals() {
AppParameters appParameters = new AppParameters();

// same values -> returns true
assertTrue(appParameters.equals(new AppParameters()));

// same object -> returns true
assertTrue(appParameters.equals(appParameters));

// null -> returns false
assertFalse(appParameters.equals(null));

// different types -> returns false
assertFalse(appParameters.equals(5.0f));

// different config path -> returns false
AppParameters otherAppParameters = new AppParameters();
otherAppParameters.setConfigPath(Paths.get("configPath"));
assertFalse(appParameters.equals(otherAppParameters));
}

private static class ParametersStub extends Application.Parameters {
private Map<String, String> namedParameters = new HashMap<>();

Expand Down
20 changes: 20 additions & 0 deletions src/test/java/seedu/address/model/person/AddressTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,24 @@ public void isValidAddress() {
assertTrue(Address.isValidAddress("-")); // one character
assertTrue(Address.isValidAddress("Leng Inc; 1234 Market St; San Francisco CA 2349879; USA")); // long address
}

@Test
public void equals() {
Address address = new Address("Valid Address");

// same values -> returns true
assertTrue(address.equals(new Address("Valid Address")));

// same object -> returns true
assertTrue(address.equals(address));

// null -> returns false
assertFalse(address.equals(null));

// different types -> returns false
assertFalse(address.equals(5.0f));

// different values -> returns false
assertFalse(address.equals(new Address("Other Valid Address")));
}
}
20 changes: 20 additions & 0 deletions src/test/java/seedu/address/model/person/EmailTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,24 @@ public void isValidEmail() {
assertTrue(Email.isValidEmail("[email protected]")); // long local part
assertTrue(Email.isValidEmail("[email protected]")); // more than one period in domain
}

@Test
public void equals() {
Email email = new Email("valid@email");

// same values -> returns true
assertTrue(email.equals(new Email("valid@email")));

// same object -> returns true
assertTrue(email.equals(email));

// null -> returns false
assertFalse(email.equals(null));

// different types -> returns false
assertFalse(email.equals(5.0f));

// different values -> returns false
assertFalse(email.equals(new Email("other.valid@email")));
}
}
20 changes: 20 additions & 0 deletions src/test/java/seedu/address/model/person/NameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,24 @@ public void isValidName() {
assertTrue(Name.isValidName("Capital Tan")); // with capital letters
assertTrue(Name.isValidName("David Roger Jackson Ray Jr 2nd")); // long names
}

@Test
public void equals() {
Name name = new Name("Valid Name");

// same values -> returns true
assertTrue(name.equals(new Name("Valid Name")));

// same object -> returns true
assertTrue(name.equals(name));

// null -> returns false
assertFalse(name.equals(null));

// different types -> returns false
assertFalse(name.equals(5.0f));

// different values -> returns false
assertFalse(name.equals(new Name("Other Valid Name")));
}
}
20 changes: 20 additions & 0 deletions src/test/java/seedu/address/model/person/PhoneTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,24 @@ public void isValidPhone() {
assertTrue(Phone.isValidPhone("93121534"));
assertTrue(Phone.isValidPhone("124293842033123")); // long phone numbers
}

@Test
public void equals() {
Phone phone = new Phone("999");

// same values -> returns true
assertTrue(phone.equals(new Phone("999")));

// same object -> returns true
assertTrue(phone.equals(phone));

// null -> returns false
assertFalse(phone.equals(null));

// different types -> returns false
assertFalse(phone.equals(5.0f));

// different values -> returns false
assertFalse(phone.equals(new Phone("995")));
}
}

0 comments on commit 15b62ac

Please sign in to comment.