Skip to content

Commit

Permalink
Merge pull request #183 from josepholim/improve-coverage
Browse files Browse the repository at this point in the history
Add more tests
  • Loading branch information
Nixx162 authored Nov 13, 2023
2 parents 959f7af + 488e1f7 commit 35acee1
Show file tree
Hide file tree
Showing 14 changed files with 254 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.ThrowingSupplier;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
Expand Down Expand Up @@ -89,7 +90,29 @@ public void equals() {
// null -> returns false
assertFalse(addNoteACommand.equals(null));

// different person -> returns false
// different person, different note -> returns false
assertFalse(addNoteACommand.equals(addNoteBCommand));

// same person, different note -> returns false
AddNoteCommand differentNoteAddNoteCommand = new AddNoteCommand(
ContactID.fromString(VALID_NOTE_A_PERSON_ID), noteB);
assertFalse(addNoteACommand.equals(differentNoteAddNoteCommand));

// different person, same note -> returns false
AddNoteCommand differentPersonAddNoteCommand = new AddNoteCommand(
ContactID.fromString(VALID_NOTE_B_PERSON_ID), noteA);
assertFalse(addNoteACommand.equals(differentPersonAddNoteCommand));
}

@Test
public void toStringMethod() {
Note noteA = NOTE_A;
AddNoteCommand addNoteACommand = new AddNoteCommand(ContactID.fromString(VALID_NOTE_A_PERSON_ID), noteA);
String expected = new ToStringBuilder(addNoteACommand)
.add("toAdd", NOTE_A)
.add("contactId", VALID_NOTE_A_PERSON_ID)
.toString();

assertEquals(expected, addNoteACommand.toString());
}
}
25 changes: 23 additions & 2 deletions src/test/java/seedu/address/logic/commands/AddTagCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.ThrowingSupplier;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
Expand Down Expand Up @@ -74,7 +75,7 @@ public void equals() {
final Set<Tag> tagSetB = new TagBuilder().withTag(VALID_TAG_FRIEND).inSet();

AddTagCommand commandA = new AddTagCommand(1, tagSetA);
AddTagCommand commandB = new AddTagCommand(1, tagSetB);
AddTagCommand commandB = new AddTagCommand(2, tagSetB);

// same object -> returns true
assertTrue(commandA.equals(commandA));
Expand All @@ -89,7 +90,27 @@ public void equals() {
// null -> returns false
assertFalse(commandA.equals(null));

// different person -> returns false
// different person, different tag -> returns false
assertFalse(commandA.equals(commandB));

// same person, different note -> returns false
AddTagCommand differentNoteCommand = new AddTagCommand(1, tagSetB);
assertFalse(commandA.equals(differentNoteCommand));

// different person, same note -> returns false
AddTagCommand differentPersonCommand = new AddTagCommand(2, tagSetA);
assertFalse(commandA.equals(differentPersonCommand));
}

@Test
public void toStringMethod() {
final Set<Tag> tagSetA = new TagBuilder().withTag(VALID_TAG_HUSBAND).inSet();
AddTagCommand addTagACommand = new AddTagCommand(1, tagSetA);
String expected = new ToStringBuilder(addTagACommand)
.add("toAdd", tagSetA)
.add("contactId", 1)
.toString();

assertEquals(expected, addTagACommand.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.ThrowingSupplier;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
Expand Down Expand Up @@ -100,7 +101,31 @@ public void equals() {
// null -> returns false
assertFalse(deleteNoteACommand.equals(null));

// different person -> returns false
// different person, different note -> returns false
assertFalse(deleteNoteACommand.equals(deleteNoteBCommand));

// same person, different note -> returns false
DeleteNoteCommand differentNoteDeleteNoteCommand = new DeleteNoteCommand(
ContactID.fromString(VALID_NOTE_A_PERSON_ID),
NoteID.fromString(VALID_NOTE_A_NOTE_ID + 1));
assertFalse(deleteNoteACommand.equals(differentNoteDeleteNoteCommand));

// different person, same note -> returns false
DeleteNoteCommand differentPersonDeleteNoteCommand = new DeleteNoteCommand(
ContactID.fromString(VALID_NOTE_B_PERSON_ID),
NoteID.fromString(VALID_NOTE_A_NOTE_ID));
assertFalse(deleteNoteACommand.equals(differentPersonDeleteNoteCommand));
}

@Test
public void toStringMethod() {
DeleteNoteCommand deleteNoteACommand = new DeleteNoteCommand(ContactID.fromString(VALID_NOTE_A_PERSON_ID),
NoteID.fromString(VALID_NOTE_A_NOTE_ID));
String expected = new ToStringBuilder(deleteNoteACommand)
.add("noteIdToDelete", VALID_NOTE_A_NOTE_ID)
.add("contactId", VALID_NOTE_A_PERSON_ID)
.toString();

assertEquals(expected, deleteNoteACommand.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.ThrowingSupplier;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
Expand Down Expand Up @@ -75,7 +76,7 @@ public void equals() {
final Set<Tag> tagSetB = new TagBuilder().withTag(VALID_TAG_FRIEND).inSet();

DeleteTagCommand commandA = new DeleteTagCommand(1, tagSetA);
DeleteTagCommand commandB = new DeleteTagCommand(1, tagSetB);
DeleteTagCommand commandB = new DeleteTagCommand(2, tagSetB);

// same object -> returns true
assertTrue(commandA.equals(commandA));
Expand All @@ -90,7 +91,27 @@ public void equals() {
// null -> returns false
assertFalse(commandA.equals(null));

// different person -> returns false
// different person, different tag -> returns false
assertFalse(commandA.equals(commandB));

// same person, different note -> returns false
DeleteTagCommand differentNoteCommand = new DeleteTagCommand(1, tagSetB);
assertFalse(commandA.equals(differentNoteCommand));

// different person, same note -> returns false
DeleteTagCommand differentPersonCommand = new DeleteTagCommand(2, tagSetA);
assertFalse(commandA.equals(differentPersonCommand));
}

@Test
public void toStringMethod() {
final Set<Tag> tagSetA = new TagBuilder().withTag(VALID_TAG_HUSBAND).inSet();
DeleteTagCommand deleteTagACommand = new DeleteTagCommand(1, tagSetA);
String expected = new ToStringBuilder(deleteTagACommand)
.add("toDelete", tagSetA)
.add("contactId", 1)
.toString();

assertEquals(expected, deleteTagACommand.toString());
}
}
25 changes: 25 additions & 0 deletions src/test/java/seedu/address/logic/commands/HelpCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package seedu.address.logic.commands;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;

import org.junit.jupiter.api.Test;
Expand All @@ -24,4 +26,27 @@ public void execute_unrecognizable_success() {
Messages.getHelpMessageForUnrecognizableCommand(AddCommand.COMMAND_WORD),
expectedModel);
}

@Test
public void equals() {
HelpCommand helpCommand = new HelpCommand(true);
HelpCommand helpCommandAdd = new HelpCommand(true, AddCommand.COMMAND_WORD);
HelpCommand helpCommandDelete = new HelpCommand(true, DeleteCommand.COMMAND_WORD);

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

// same values -> returns true
assertTrue(helpCommand.equals(new HelpCommand(true)));

// different types -> returns false
assertFalse(helpCommand.equals(1));

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

// different values -> returns false
assertFalse(helpCommand.equals(helpCommandAdd));
assertFalse(helpCommandAdd.equals(helpCommandDelete));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import seedu.address.model.tag.Tag;
import seedu.address.testutil.TagBuilder;

public class AddTagParserTest {
public class AddTagCommandParserTest {
private AddTagCommandParser parser = new AddTagCommandParser();

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import seedu.address.model.tag.Tag;
import seedu.address.testutil.TagBuilder;

public class DeleteTagParserTest {
public class DeleteTagCommandParserTest {
private DeleteTagCommandParser parser = new DeleteTagCommandParser();

@Test
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/seedu/address/model/person/AddressTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,17 @@ public void equals() {
// different values -> returns false
assertFalse(address.equals(new Address("Other Valid Address")));
}

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

// same values
Address addressCopy = new Address("Valid Address");
assertTrue(address.hashCode() == addressCopy.hashCode());

// different values
Address otherAddress = new Address("Other Valid Address");
assertFalse(address.hashCode() == otherAddress.hashCode());
}
}
32 changes: 32 additions & 0 deletions src/test/java/seedu/address/model/person/ContactIdTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package seedu.address.model.person;

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

import org.junit.jupiter.api.Test;

public class ContactIdTest {

@Test
public void equals() {
ContactID id = ContactID.fromString("1");

// same values -> returns true
assertTrue(id.equals(ContactID.fromString("1")));

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

// same values but using fromInt method -> returns true
assertTrue(id.equals(ContactID.fromInt(1)));

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

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

// different values -> returns false
assertFalse(id.equals(ContactID.fromString("2")));
}
}
13 changes: 13 additions & 0 deletions src/test/java/seedu/address/model/person/EmailTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,17 @@ public void equals() {
// different values -> returns false
assertFalse(email.equals(new Email("other.valid@email")));
}

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

// same values
Email emailCopy = new Email("valid.valid@email");
assertTrue(email.hashCode() == emailCopy.hashCode());

// different values
Email otherEmail = new Email("other.valid@email");
assertFalse(email.hashCode() == otherEmail.hashCode());
}
}
13 changes: 13 additions & 0 deletions src/test/java/seedu/address/model/person/NameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,17 @@ public void equals() {
// different values -> returns false
assertFalse(name.equals(new Name("Other Valid Name")));
}

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

// same values
Name nameCopy = new Name("Valid Name");
assertTrue(name.hashCode() == nameCopy.hashCode());

// different values
Name otherName = new Name("Valid Other Name");
assertFalse(name.hashCode() == otherName.hashCode());
}
}
14 changes: 14 additions & 0 deletions src/test/java/seedu/address/model/person/PersonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public void equals() {
// different tags -> returns true
editedAlice = new PersonBuilder(ALICE).withTags(VALID_TAG_HUSBAND).build();
assertTrue(ALICE.equals(editedAlice));

// different name and tags -> returns true
editedAlice = new PersonBuilder(ALICE).withName(VALID_NAME_BOB).withTags(VALID_TAG_HUSBAND).build();
assertFalse(ALICE.equals(editedAlice));
}

@Test
Expand All @@ -127,6 +131,16 @@ public void deleteTag_validSet_success() {
assertFalse(ALICE.getTags().contains(new TagBuilder().build()));
}

@Test
public void hashCodeMethod() {
// same values
Person aliceCopy = new PersonBuilder(ALICE).build();
assertTrue(ALICE.hashCode() == aliceCopy.hashCode());

// different values
assertFalse(ALICE.hashCode() == BOB.hashCode());
}

@Test
public void toStringMethod() {
String expected = Person.class.getCanonicalName() + "{name=" + ALICE.getName() + ", phone=" + ALICE.getPhone()
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/seedu/address/model/person/PhoneTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,17 @@ public void equals() {
// different values -> returns false
assertFalse(phone.equals(new Phone("995")));
}

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

// same values
Phone phoneCopy = new Phone("999");
assertTrue(phone.hashCode() == phoneCopy.hashCode());

// different values
Phone otherPhone = new Phone("995");
assertFalse(phone.hashCode() == otherPhone.hashCode());
}
}
Loading

0 comments on commit 35acee1

Please sign in to comment.