From cf918c1668c8a55c9ce86ef26f5933c10c22e8a7 Mon Sep 17 00:00:00 2001 From: AjayArvind2207 Date: Mon, 15 Apr 2024 00:34:00 +0800 Subject: [PATCH 1/2] Add tests for equality in Tag.java --- .../java/seedu/address/model/tag/TagTest.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/test/java/seedu/address/model/tag/TagTest.java b/src/test/java/seedu/address/model/tag/TagTest.java index 0cbb31213f9..5db32cfa065 100644 --- a/src/test/java/seedu/address/model/tag/TagTest.java +++ b/src/test/java/seedu/address/model/tag/TagTest.java @@ -1,5 +1,7 @@ package seedu.address.model.tag; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.testutil.Assert.assertThrows; import org.junit.jupiter.api.Test; @@ -26,10 +28,21 @@ public void isValidTagName() { @Test public void capitaliseTest() { Tag tag = new Tag("software engineer"); - assert(tag.capitalise().equals("Software Engineer")); + assertTrue(tag.capitalise().equals("Software Engineer")); tag = new Tag("softWare EnginEEr"); - assert(tag.capitalise().equals("Software Engineer")); + assertTrue(tag.capitalise().equals("Software Engineer")); + + } + + @Test + public void equals() { + Tag legalTag = new Tag("Software Engineer"); + assertTrue(legalTag.equals(legalTag)); + + Tag nullTag = null; + assertFalse(legalTag.equals(nullTag)); + } From b5fe5d94a416efdb6c2fedb096eeb17d5bb4b8ec Mon Sep 17 00:00:00 2001 From: AjayArvind2207 Date: Mon, 15 Apr 2024 01:10:29 +0800 Subject: [PATCH 2/2] Add more rigorous testing for equality in Tag.java and fix naming convention in PhoneTest.java --- .../seedu/address/model/company/PhoneTest.java | 14 +++++++------- .../java/seedu/address/model/tag/TagTest.java | 18 ++++++++++++++---- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/test/java/seedu/address/model/company/PhoneTest.java b/src/test/java/seedu/address/model/company/PhoneTest.java index fe249a02f2e..beb6496cefd 100644 --- a/src/test/java/seedu/address/model/company/PhoneTest.java +++ b/src/test/java/seedu/address/model/company/PhoneTest.java @@ -45,16 +45,16 @@ public void isValidPhone() { @Test public void isPhonePresent() { - Phone default_phone = Phone.getDefaultPhone(); + Phone defaultPhone = Phone.getDefaultPhone(); Phone phone = new Phone("995"); assertTrue(phone.isPhonePresent()); - assertFalse(default_phone.isPhonePresent()); + assertFalse(defaultPhone.isPhonePresent()); } @Test public void equals() { Phone phone = new Phone("999"); - Phone default_phone = Phone.getDefaultPhone(); + Phone defaultPhone = Phone.getDefaultPhone(); // same values -> returns true assertTrue(phone.equals(new Phone("999"))); @@ -62,7 +62,7 @@ public void equals() { assertTrue(phone.equals(phone)); //two phones with default values -> return true - assertTrue(default_phone.equals(Phone.getDefaultPhone())); + assertTrue(defaultPhone.equals(Phone.getDefaultPhone())); // null -> returns false assertFalse(phone.equals(null)); @@ -74,13 +74,13 @@ public void equals() { assertFalse(phone.equals(new Phone("995"))); //one default phone, one non default phone -> returns false - assertFalse(default_phone.equals(new Phone("995"))); + assertFalse(defaultPhone.equals(new Phone("995"))); } @Test public void testToString() { - Phone default_phone = Phone.getDefaultPhone(); - assertTrue(default_phone.toString().equals("No phone number")); + Phone defaultPhone = Phone.getDefaultPhone(); + assertTrue(defaultPhone.toString().equals("No phone number")); Phone phone = new Phone("995"); assertTrue(phone.toString().equals("995")); } diff --git a/src/test/java/seedu/address/model/tag/TagTest.java b/src/test/java/seedu/address/model/tag/TagTest.java index 5db32cfa065..22c357c4782 100644 --- a/src/test/java/seedu/address/model/tag/TagTest.java +++ b/src/test/java/seedu/address/model/tag/TagTest.java @@ -6,6 +6,7 @@ import org.junit.jupiter.api.Test; + public class TagTest { @Test @@ -37,13 +38,22 @@ public void capitaliseTest() { @Test public void equals() { - Tag legalTag = new Tag("Software Engineer"); - assertTrue(legalTag.equals(legalTag)); + Tag tag = new Tag("Valid Tag"); + + // same values -> returns true + assertTrue(tag.equals(new Tag("Valid Tag"))); + + // same object -> returns true + assertTrue(tag.equals(tag)); - Tag nullTag = null; - assertFalse(legalTag.equals(nullTag)); + // null -> returns false + assertFalse(tag.equals(null)); + // different types -> returns false + assertFalse(tag.equals(5.0f)); + // different values -> returns false + assertFalse(tag.equals(new Tag("Other Valid Tag"))); } }