From 7d4b8cf277e6f52f5c7d19a5decb1de4201399e4 Mon Sep 17 00:00:00 2001 From: whitesnowx Date: Wed, 13 Mar 2024 00:42:46 +0800 Subject: [PATCH 01/13] ammend comments in module code --- src/test/java/staffconnect/model/person/ModuleTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/staffconnect/model/person/ModuleTest.java b/src/test/java/staffconnect/model/person/ModuleTest.java index dc1cf7613c3..a9c205e3fe0 100644 --- a/src/test/java/staffconnect/model/person/ModuleTest.java +++ b/src/test/java/staffconnect/model/person/ModuleTest.java @@ -21,10 +21,10 @@ public void constructor_invalidModule_throwsIllegalArgumentException() { @Test public void isValidModule() { - // null phone number + // null module code assertThrows(NullPointerException.class, () -> Module.isValidModule(null)); - // invalid phone numbers + // invalid module code assertFalse(Module.isValidModule("")); // empty string assertFalse(Module.isValidModule(" ")); // spaces only assertFalse(Module.isValidModule("ABCD")); // letters only @@ -38,7 +38,7 @@ public void isValidModule() { assertFalse(Module.isValidModule("cs2103t")); // suffix not capitalised assertFalse(Module.isValidModule("cs2103T")); // prefix not capitalised - // valid phone numbers + // valid module code assertTrue(Module.isValidModule("CS2103")); // 2 prefix, 4 letters without 1 optional suffix assertTrue(Module.isValidModule("CS2103T")); // 2 prefix, 4 letters with 1 optional suffix assertTrue(Module.isValidModule("GEN2050")); // 3 prefix, 4 letters without 1 optional suffix From 802927e99959ff214b62ff52bed522b2ccae85fb Mon Sep 17 00:00:00 2001 From: whitesnowx Date: Wed, 13 Mar 2024 01:29:31 +0800 Subject: [PATCH 02/13] Add Availability class --- .../model/person/Availability.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/main/java/staffconnect/model/person/Availability.java diff --git a/src/main/java/staffconnect/model/person/Availability.java b/src/main/java/staffconnect/model/person/Availability.java new file mode 100644 index 00000000000..62dd55742c8 --- /dev/null +++ b/src/main/java/staffconnect/model/person/Availability.java @@ -0,0 +1,62 @@ +package staffconnect.model.person; + +import static java.util.Objects.requireNonNull; +import static staffconnect.commons.util.AppUtil.checkArgument; + +/** + * Represents a Person's availability in the staff book. + * Guarantees: immutable; is valid as declared in {@link #isValidAvailability(String)} + */ +public class Availability { + + + public static final String MESSAGE_CONSTRAINTS = + "Module code should contain 2-4 capital letters followed by 4 digits long and at most 1 capitalised suffix"; + public static final String VALIDATION_REGEX = "/((mon|tues|wed(nes)?|thur(s)?|fri|sat(ur)?|sun)(day)?)/gi"; + + public final String value; + + /** + * Constructs a {@code Availability}. + * + * @param module A valid availability. + */ + public Availability(String module) { + requireNonNull(module); + checkArgument(isValidAvailability(module), MESSAGE_CONSTRAINTS); + value = module; + } + + /** + * Returns true if a given string is a valid availability. + */ + public static boolean isValidAvailability(String test) { + return test.matches(VALIDATION_REGEX); + } + + @Override + public String toString() { + return value; + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof Availability)) { + return false; + } + + Availability otherAvailability = (Availability) other; + return value.equals(otherAvailability.value); + } + + @Override + public int hashCode() { + return value.hashCode(); + } + +} From fd7c206fd574f66a0ae8d7951a22d7e9bfea3523 Mon Sep 17 00:00:00 2001 From: whitesnowx Date: Wed, 13 Mar 2024 01:32:10 +0800 Subject: [PATCH 03/13] Remove traces of module --- .../java/staffconnect/model/person/Availability.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/staffconnect/model/person/Availability.java b/src/main/java/staffconnect/model/person/Availability.java index 62dd55742c8..57f08ffccca 100644 --- a/src/main/java/staffconnect/model/person/Availability.java +++ b/src/main/java/staffconnect/model/person/Availability.java @@ -11,7 +11,7 @@ public class Availability { public static final String MESSAGE_CONSTRAINTS = - "Module code should contain 2-4 capital letters followed by 4 digits long and at most 1 capitalised suffix"; + "Should be a week of the day, the full word or the first syllable of the word"; public static final String VALIDATION_REGEX = "/((mon|tues|wed(nes)?|thur(s)?|fri|sat(ur)?|sun)(day)?)/gi"; public final String value; @@ -19,12 +19,12 @@ public class Availability { /** * Constructs a {@code Availability}. * - * @param module A valid availability. + * @param availability A valid availability. */ - public Availability(String module) { - requireNonNull(module); - checkArgument(isValidAvailability(module), MESSAGE_CONSTRAINTS); - value = module; + public Availability(String availability) { + requireNonNull(availability); + checkArgument(isValidAvailability(availability), MESSAGE_CONSTRAINTS); + value = availability; } /** From 0ab5ad3f1e085318777f9e03e992db06f40390b0 Mon Sep 17 00:00:00 2001 From: whitesnowx Date: Wed, 13 Mar 2024 02:05:09 +0800 Subject: [PATCH 04/13] Implement availability for partial part of the word but yet to capital insensitive --- .../model/person/Availability.java | 19 ++++- .../model/person/AvailabilityTest.java | 84 +++++++++++++++++++ 2 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 src/test/java/staffconnect/model/person/AvailabilityTest.java diff --git a/src/main/java/staffconnect/model/person/Availability.java b/src/main/java/staffconnect/model/person/Availability.java index 57f08ffccca..95dc02639a4 100644 --- a/src/main/java/staffconnect/model/person/Availability.java +++ b/src/main/java/staffconnect/model/person/Availability.java @@ -3,6 +3,7 @@ import static java.util.Objects.requireNonNull; import static staffconnect.commons.util.AppUtil.checkArgument; +import java.time.DayOfWeek; /** * Represents a Person's availability in the staff book. * Guarantees: immutable; is valid as declared in {@link #isValidAvailability(String)} @@ -12,7 +13,7 @@ public class Availability { public static final String MESSAGE_CONSTRAINTS = "Should be a week of the day, the full word or the first syllable of the word"; - public static final String VALIDATION_REGEX = "/((mon|tues|wed(nes)?|thur(s)?|fri|sat(ur)?|sun)(day)?)/gi"; + public static final String VALIDATION_REGEX = "((mon|tues|wed(nes)?|thur(s)?|fri|sat(ur)?|sun)(day)?)"; public final String value; @@ -24,7 +25,21 @@ public class Availability { public Availability(String availability) { requireNonNull(availability); checkArgument(isValidAvailability(availability), MESSAGE_CONSTRAINTS); - value = availability; + if (availability.matches("(mon)(day)?")) { + value = DayOfWeek.MONDAY.name(); + } else if (availability.matches("(tues)(day)?")) { + value = DayOfWeek.TUESDAY.name(); + } else if (availability.matches("(wed)(nes)?(day)?")) { + value = DayOfWeek.WEDNESDAY.name(); + } else if (availability.matches("(thur)(s)(day)?")) { + value = DayOfWeek.THURSDAY.name(); + } else if (availability.matches("(fri)(day)?")) { + value = DayOfWeek.FRIDAY.name(); + } else if (availability.matches("(sat)(ur)?(day)?")) { + value = DayOfWeek.SATURDAY.name(); + } else { + value = DayOfWeek.SUNDAY.name(); + } } /** diff --git a/src/test/java/staffconnect/model/person/AvailabilityTest.java b/src/test/java/staffconnect/model/person/AvailabilityTest.java new file mode 100644 index 00000000000..42c66ab408d --- /dev/null +++ b/src/test/java/staffconnect/model/person/AvailabilityTest.java @@ -0,0 +1,84 @@ +package staffconnect.model.person; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static staffconnect.testutil.Assert.assertThrows; + +import org.junit.jupiter.api.Test; + +public class AvailabilityTest { + + @Test + public void constructor_null_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new Module(null)); + } + + @Test + public void constructor_invalidModule_throwsIllegalArgumentException() { + String invalidAvailability = ""; + assertThrows(IllegalArgumentException.class, () -> new Availability(invalidAvailability)); + } + + @Test + public void isValidAvailability() { + // null module code + assertThrows(NullPointerException.class, () -> Availability.isValidAvailability(null)); + + // invalid module code + assertFalse(Availability.isValidAvailability("")); // empty string + assertFalse(Availability.isValidAvailability(" ")); // spaces only + assertFalse(Availability.isValidAvailability("m")); // 1 letter only + assertFalse(Availability.isValidAvailability("1")); // 1 number only + assertFalse(Availability.isValidAvailability("m o n")); // spaces between letters + assertFalse(Availability.isValidAvailability("birthday")); // incorrect type of day + assertFalse(Availability.isValidAvailability("moon")); // 1 letter duplicated + assertFalse(Availability.isValidAvailability("mon123")); // trailing number behind day + assertFalse(Availability.isValidAvailability("#@$!")); // special characters + assertFalse(Availability.isValidAvailability("mon#@$!")); // prefix and special characters + assertFalse(Availability.isValidAvailability("123#@$!")); // numbers and special characters + assertFalse(Availability.isValidAvailability("day")); // day without prefix + assertFalse(Availability.isValidAvailability("sytaudrh")); // scrambled spelling + assertFalse(Availability.isValidAvailability("chewsday")); // misspelling + assertFalse(Availability.isValidAvailability("thu")); // uncompleted syllable + + // valid module code + assertTrue(Availability.isValidAvailability("tues")); // first syllable tuesday + assertTrue(Availability.isValidAvailability("wed")); // first syllable wednesday + assertTrue(Availability.isValidAvailability("wednes")); // two syllable wednesday + assertTrue(Availability.isValidAvailability("thur")); // first syllable thursday without s + assertTrue(Availability.isValidAvailability("thurs")); // first syllable thursday with s + assertTrue(Availability.isValidAvailability("fri")); // first syllable friday + assertTrue(Availability.isValidAvailability("sat")); // first syllable saturday + assertTrue(Availability.isValidAvailability("sun")); // first syllable sunday + assertTrue(Availability.isValidAvailability("monday")); // full word monday + assertTrue(Availability.isValidAvailability("tuesday")); // full word tuesday + assertTrue(Availability.isValidAvailability("wednesday")); // full word wednesday + assertTrue(Availability.isValidAvailability("thursday")); // full word thursday + assertTrue(Availability.isValidAvailability("friday")); // full word friday + assertTrue(Availability.isValidAvailability("saturday")); // full word saturday + assertTrue(Availability.isValidAvailability("sunday")); // full word sunday + } + + @Test + public void equals() { + Availability availability = new Availability("monday"); + + // same values -> returns true + assertTrue(availability.equals(new Availability("monday"))); + + // same day -> return true + assertTrue(availability.equals(new Availability("mon"))); + + // same object -> returns true + assertTrue(availability.equals(availability)); + + // null -> returns false + assertFalse(availability.equals(null)); + + // different types -> returns false + assertFalse(availability.equals(5.0f)); + + // different values -> returns false + assertFalse(availability.equals(new Availability("sunday"))); + } +} From 7c271d6dd364e9248a9b572632e3e7e875a9b5e1 Mon Sep 17 00:00:00 2001 From: whitesnowx Date: Wed, 13 Mar 2024 02:26:20 +0800 Subject: [PATCH 05/13] Add test for Availability in AvailabilityTest and implement ignore capitalisation --- .../model/person/Availability.java | 14 +++++------ .../model/person/AvailabilityTest.java | 25 ++++++++++++------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/main/java/staffconnect/model/person/Availability.java b/src/main/java/staffconnect/model/person/Availability.java index 95dc02639a4..d64155c461e 100644 --- a/src/main/java/staffconnect/model/person/Availability.java +++ b/src/main/java/staffconnect/model/person/Availability.java @@ -13,7 +13,7 @@ public class Availability { public static final String MESSAGE_CONSTRAINTS = "Should be a week of the day, the full word or the first syllable of the word"; - public static final String VALIDATION_REGEX = "((mon|tues|wed(nes)?|thur(s)?|fri|sat(ur)?|sun)(day)?)"; + public static final String VALIDATION_REGEX = "(?i)((mon|tues|wed(nes)?|thur(s)?|fri|sat(ur)?|sun)(day)?)"; public final String value; @@ -25,17 +25,17 @@ public class Availability { public Availability(String availability) { requireNonNull(availability); checkArgument(isValidAvailability(availability), MESSAGE_CONSTRAINTS); - if (availability.matches("(mon)(day)?")) { + if (availability.matches("(?i)(mon)(day)?")) { value = DayOfWeek.MONDAY.name(); - } else if (availability.matches("(tues)(day)?")) { + } else if (availability.matches("(?i)(tues)(day)?")) { value = DayOfWeek.TUESDAY.name(); - } else if (availability.matches("(wed)(nes)?(day)?")) { + } else if (availability.matches("(?i)(wed)(nes)?(day)?")) { value = DayOfWeek.WEDNESDAY.name(); - } else if (availability.matches("(thur)(s)(day)?")) { + } else if (availability.matches("(?i)(thur)(s)(day)?")) { value = DayOfWeek.THURSDAY.name(); - } else if (availability.matches("(fri)(day)?")) { + } else if (availability.matches("(?i)(fri)(day)?")) { value = DayOfWeek.FRIDAY.name(); - } else if (availability.matches("(sat)(ur)?(day)?")) { + } else if (availability.matches("(?i)(sat)(ur)?(day)?")) { value = DayOfWeek.SATURDAY.name(); } else { value = DayOfWeek.SUNDAY.name(); diff --git a/src/test/java/staffconnect/model/person/AvailabilityTest.java b/src/test/java/staffconnect/model/person/AvailabilityTest.java index 42c66ab408d..a0ce74f6e7c 100644 --- a/src/test/java/staffconnect/model/person/AvailabilityTest.java +++ b/src/test/java/staffconnect/model/person/AvailabilityTest.java @@ -40,23 +40,30 @@ public void isValidAvailability() { assertFalse(Availability.isValidAvailability("sytaudrh")); // scrambled spelling assertFalse(Availability.isValidAvailability("chewsday")); // misspelling assertFalse(Availability.isValidAvailability("thu")); // uncompleted syllable + assertFalse(Availability.isValidAvailability("sun day")); // space between syllable // valid module code + assertTrue(Availability.isValidAvailability("mon")); // first syllable tuesday assertTrue(Availability.isValidAvailability("tues")); // first syllable tuesday assertTrue(Availability.isValidAvailability("wed")); // first syllable wednesday assertTrue(Availability.isValidAvailability("wednes")); // two syllable wednesday assertTrue(Availability.isValidAvailability("thur")); // first syllable thursday without s assertTrue(Availability.isValidAvailability("thurs")); // first syllable thursday with s - assertTrue(Availability.isValidAvailability("fri")); // first syllable friday assertTrue(Availability.isValidAvailability("sat")); // first syllable saturday + assertTrue(Availability.isValidAvailability("satur")); // two syllable saturday assertTrue(Availability.isValidAvailability("sun")); // first syllable sunday - assertTrue(Availability.isValidAvailability("monday")); // full word monday - assertTrue(Availability.isValidAvailability("tuesday")); // full word tuesday - assertTrue(Availability.isValidAvailability("wednesday")); // full word wednesday - assertTrue(Availability.isValidAvailability("thursday")); // full word thursday - assertTrue(Availability.isValidAvailability("friday")); // full word friday - assertTrue(Availability.isValidAvailability("saturday")); // full word saturday - assertTrue(Availability.isValidAvailability("sunday")); // full word sunday + assertTrue(Availability.isValidAvailability("Sun")); // first syllable with capitalised first letter + assertTrue(Availability.isValidAvailability("sAtUr")); // two syllable mixed case + assertTrue(Availability.isValidAvailability("monday")); // full word lowercase monday + assertTrue(Availability.isValidAvailability("tuesday")); // full word lowercase tuesday + assertTrue(Availability.isValidAvailability("wednesday")); // full word lowercase wednesday + assertTrue(Availability.isValidAvailability("thursday")); // full word lowercase thursday + assertTrue(Availability.isValidAvailability("friday")); // full word lowercase friday + assertTrue(Availability.isValidAvailability("saturday")); // full word lowercase saturday + assertTrue(Availability.isValidAvailability("sunday")); // full word lowercase sunday + assertTrue(Availability.isValidAvailability("MONDAY")); // full word uppercase monday + assertTrue(Availability.isValidAvailability("Tuesday")); // full word with capitalised first letter + assertTrue(Availability.isValidAvailability("wEdNeSdAy")); // full word mixed case } @Test @@ -67,7 +74,7 @@ public void equals() { assertTrue(availability.equals(new Availability("monday"))); // same day -> return true - assertTrue(availability.equals(new Availability("mon"))); + assertTrue(availability.equals(new Availability("mOn"))); // same object -> returns true assertTrue(availability.equals(availability)); From 3849391826d6c4532ced541403e46d63fc7b8275 Mon Sep 17 00:00:00 2001 From: whitesnowx Date: Wed, 13 Mar 2024 02:27:37 +0800 Subject: [PATCH 06/13] Remove traces of module in AvailabilityTest.java --- .../staffconnect/model/person/AvailabilityTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/staffconnect/model/person/AvailabilityTest.java b/src/test/java/staffconnect/model/person/AvailabilityTest.java index a0ce74f6e7c..12d39e07050 100644 --- a/src/test/java/staffconnect/model/person/AvailabilityTest.java +++ b/src/test/java/staffconnect/model/person/AvailabilityTest.java @@ -10,21 +10,21 @@ public class AvailabilityTest { @Test public void constructor_null_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> new Module(null)); + assertThrows(NullPointerException.class, () -> new Availability(null)); } @Test - public void constructor_invalidModule_throwsIllegalArgumentException() { + public void constructor_invalidAvailability_throwsIllegalArgumentException() { String invalidAvailability = ""; assertThrows(IllegalArgumentException.class, () -> new Availability(invalidAvailability)); } @Test public void isValidAvailability() { - // null module code + // null availability assertThrows(NullPointerException.class, () -> Availability.isValidAvailability(null)); - // invalid module code + // invalid availability assertFalse(Availability.isValidAvailability("")); // empty string assertFalse(Availability.isValidAvailability(" ")); // spaces only assertFalse(Availability.isValidAvailability("m")); // 1 letter only @@ -42,7 +42,7 @@ public void isValidAvailability() { assertFalse(Availability.isValidAvailability("thu")); // uncompleted syllable assertFalse(Availability.isValidAvailability("sun day")); // space between syllable - // valid module code + // valid availability assertTrue(Availability.isValidAvailability("mon")); // first syllable tuesday assertTrue(Availability.isValidAvailability("tues")); // first syllable tuesday assertTrue(Availability.isValidAvailability("wed")); // first syllable wednesday From 2b01e4af0901b7b6b56e649bbf6c007090250638 Mon Sep 17 00:00:00 2001 From: whitesnowx Date: Wed, 13 Mar 2024 04:17:52 +0800 Subject: [PATCH 07/13] Cover more test for different days of the week --- .../model/person/AvailabilityTest.java | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/test/java/staffconnect/model/person/AvailabilityTest.java b/src/test/java/staffconnect/model/person/AvailabilityTest.java index 12d39e07050..99cd8a91451 100644 --- a/src/test/java/staffconnect/model/person/AvailabilityTest.java +++ b/src/test/java/staffconnect/model/person/AvailabilityTest.java @@ -68,24 +68,41 @@ public void isValidAvailability() { @Test public void equals() { - Availability availability = new Availability("monday"); + Availability monAvailability = new Availability("monday"); // same values -> returns true - assertTrue(availability.equals(new Availability("monday"))); + assertTrue(monAvailability.equals(new Availability("monday"))); // same day -> return true - assertTrue(availability.equals(new Availability("mOn"))); + assertTrue(monAvailability.equals(new Availability("mOn"))); // same object -> returns true - assertTrue(availability.equals(availability)); + assertTrue(monAvailability.equals(monAvailability)); // null -> returns false - assertFalse(availability.equals(null)); + assertFalse(monAvailability.equals(null)); // different types -> returns false - assertFalse(availability.equals(5.0f)); + assertFalse(monAvailability.equals(5.0f)); + + // different values -> returns false, mon and tues + assertFalse(monAvailability.equals(new Availability("tues"))); + + Availability wedAvailability = new Availability("wed"); + Availability friAvailability = new Availability("wed"); + + // different values -> returns false, mon and wed + assertFalse(monAvailability.equals(wedAvailability)); + + // different values -> returns false, wed and thurs + assertFalse(wedAvailability.equals(new Availability("thurs"))); + + // different values -> returns false, sat and sun + assertFalse(friAvailability.equals(new Availability("SATURDAY"))); + + // different values -> returns false, sat and sun + assertFalse(friAvailability.equals(new Availability("sunday"))); + - // different values -> returns false - assertFalse(availability.equals(new Availability("sunday"))); } } From 3ff22406a75a8d458e0ea27bbb945af0d35810cf Mon Sep 17 00:00:00 2001 From: whitesnowx Date: Wed, 13 Mar 2024 05:02:24 +0800 Subject: [PATCH 08/13] Slap contructor to produce strToDayOfWeek function and fix middle syllable parse logic --- .../model/person/Availability.java | 42 ++++++++++++------- .../model/person/AvailabilityTest.java | 7 +++- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/main/java/staffconnect/model/person/Availability.java b/src/main/java/staffconnect/model/person/Availability.java index d64155c461e..27ff46e1e8e 100644 --- a/src/main/java/staffconnect/model/person/Availability.java +++ b/src/main/java/staffconnect/model/person/Availability.java @@ -13,7 +13,7 @@ public class Availability { public static final String MESSAGE_CONSTRAINTS = "Should be a week of the day, the full word or the first syllable of the word"; - public static final String VALIDATION_REGEX = "(?i)((mon|tues|wed(nes)?|thur(s)?|fri|sat(ur)?|sun)(day)?)"; + public static final String VALIDATION_REGEX = "(?i)((mon|tue(s)?|wed(nes)?|thu(r)?(rs)?|fri|sat(ur)?|sun)(day)?)"; public final String value; @@ -25,21 +25,7 @@ public class Availability { public Availability(String availability) { requireNonNull(availability); checkArgument(isValidAvailability(availability), MESSAGE_CONSTRAINTS); - if (availability.matches("(?i)(mon)(day)?")) { - value = DayOfWeek.MONDAY.name(); - } else if (availability.matches("(?i)(tues)(day)?")) { - value = DayOfWeek.TUESDAY.name(); - } else if (availability.matches("(?i)(wed)(nes)?(day)?")) { - value = DayOfWeek.WEDNESDAY.name(); - } else if (availability.matches("(?i)(thur)(s)(day)?")) { - value = DayOfWeek.THURSDAY.name(); - } else if (availability.matches("(?i)(fri)(day)?")) { - value = DayOfWeek.FRIDAY.name(); - } else if (availability.matches("(?i)(sat)(ur)?(day)?")) { - value = DayOfWeek.SATURDAY.name(); - } else { - value = DayOfWeek.SUNDAY.name(); - } + value = strToDayOfWeek(availability); } /** @@ -49,6 +35,30 @@ public static boolean isValidAvailability(String test) { return test.matches(VALIDATION_REGEX); } + /** + * Returns a standardised Day of the Week. + * + * @param validAvailability validatedAvailability to be translated. + * @return Corresponding Day of Week. + */ + public static String strToDayOfWeek(String validAvailability) { + if (validAvailability.matches("(?i)(mon)(day)?")) { + return DayOfWeek.MONDAY.name(); + } else if (validAvailability.matches("(?i)(tue)(s?)(sday?)")) { + return DayOfWeek.TUESDAY.name(); + } else if (validAvailability.matches("(?i)(wed)(nes)?(nesday)?")) { + return DayOfWeek.WEDNESDAY.name(); + } else if (validAvailability.matches("(?i)(thu)(r)?(rs)?(rsday)?")) { + return DayOfWeek.THURSDAY.name(); + } else if (validAvailability.matches("(?i)(fri)(day)?")) { + return DayOfWeek.FRIDAY.name(); + } else if (validAvailability.matches("(?i)(sat)(ur)?(urday)?")) { + return DayOfWeek.SATURDAY.name(); + } else { + return DayOfWeek.SUNDAY.name(); + } + } + @Override public String toString() { return value; diff --git a/src/test/java/staffconnect/model/person/AvailabilityTest.java b/src/test/java/staffconnect/model/person/AvailabilityTest.java index 99cd8a91451..0d649fe0b6e 100644 --- a/src/test/java/staffconnect/model/person/AvailabilityTest.java +++ b/src/test/java/staffconnect/model/person/AvailabilityTest.java @@ -39,14 +39,17 @@ public void isValidAvailability() { assertFalse(Availability.isValidAvailability("day")); // day without prefix assertFalse(Availability.isValidAvailability("sytaudrh")); // scrambled spelling assertFalse(Availability.isValidAvailability("chewsday")); // misspelling - assertFalse(Availability.isValidAvailability("thu")); // uncompleted syllable + assertFalse(Availability.isValidAvailability("th")); // uncompleted syllable assertFalse(Availability.isValidAvailability("sun day")); // space between syllable + assertFalse(Availability.isValidAvailability("sat day")); // missing middle syllable + assertFalse(Availability.isValidAvailability("satuday")); // missing middle letter // valid availability assertTrue(Availability.isValidAvailability("mon")); // first syllable tuesday assertTrue(Availability.isValidAvailability("tues")); // first syllable tuesday assertTrue(Availability.isValidAvailability("wed")); // first syllable wednesday assertTrue(Availability.isValidAvailability("wednes")); // two syllable wednesday + assertTrue(Availability.isValidAvailability("thu")); // first syllable thursday without rs assertTrue(Availability.isValidAvailability("thur")); // first syllable thursday without s assertTrue(Availability.isValidAvailability("thurs")); // first syllable thursday with s assertTrue(Availability.isValidAvailability("sat")); // first syllable saturday @@ -105,4 +108,6 @@ public void equals() { } + + } From f98e1f17878a08bb48207d6bc3fcb6549529b5d6 Mon Sep 17 00:00:00 2001 From: whitesnowx Date: Wed, 13 Mar 2024 05:14:01 +0800 Subject: [PATCH 09/13] Seperate Availability equals() test to strToDayOfWeekTest() --- .../model/person/Availability.java | 2 +- .../model/person/AvailabilityTest.java | 29 +++++++++---------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/main/java/staffconnect/model/person/Availability.java b/src/main/java/staffconnect/model/person/Availability.java index 27ff46e1e8e..d72881d736c 100644 --- a/src/main/java/staffconnect/model/person/Availability.java +++ b/src/main/java/staffconnect/model/person/Availability.java @@ -44,7 +44,7 @@ public static boolean isValidAvailability(String test) { public static String strToDayOfWeek(String validAvailability) { if (validAvailability.matches("(?i)(mon)(day)?")) { return DayOfWeek.MONDAY.name(); - } else if (validAvailability.matches("(?i)(tue)(s?)(sday?)")) { + } else if (validAvailability.matches("(?i)(tue)(s)?(sday)?")) { return DayOfWeek.TUESDAY.name(); } else if (validAvailability.matches("(?i)(wed)(nes)?(nesday)?")) { return DayOfWeek.WEDNESDAY.name(); diff --git a/src/test/java/staffconnect/model/person/AvailabilityTest.java b/src/test/java/staffconnect/model/person/AvailabilityTest.java index 0d649fe0b6e..dcf70e3070e 100644 --- a/src/test/java/staffconnect/model/person/AvailabilityTest.java +++ b/src/test/java/staffconnect/model/person/AvailabilityTest.java @@ -1,9 +1,12 @@ package staffconnect.model.person; +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 static staffconnect.testutil.Assert.assertThrows; +import java.time.DayOfWeek; + import org.junit.jupiter.api.Test; public class AvailabilityTest { @@ -91,23 +94,17 @@ public void equals() { // different values -> returns false, mon and tues assertFalse(monAvailability.equals(new Availability("tues"))); - Availability wedAvailability = new Availability("wed"); - Availability friAvailability = new Availability("wed"); - - // different values -> returns false, mon and wed - assertFalse(monAvailability.equals(wedAvailability)); - - // different values -> returns false, wed and thurs - assertFalse(wedAvailability.equals(new Availability("thurs"))); - - // different values -> returns false, sat and sun - assertFalse(friAvailability.equals(new Availability("SATURDAY"))); - - // different values -> returns false, sat and sun - assertFalse(friAvailability.equals(new Availability("sunday"))); - - } + @Test + public void strToDayOfWeekTest() { + assertEquals(DayOfWeek.MONDAY.toString(), Availability.strToDayOfWeek(new String("mon"))); + assertEquals(DayOfWeek.TUESDAY.toString(), Availability.strToDayOfWeek(new String("tues"))); + assertEquals(DayOfWeek.WEDNESDAY.toString(), Availability.strToDayOfWeek(new String("wednes"))); + assertEquals(DayOfWeek.THURSDAY.toString(), Availability.strToDayOfWeek(new String("thursday"))); + assertEquals(DayOfWeek.FRIDAY.toString(), Availability.strToDayOfWeek(new String("FRIDAY"))); + assertEquals(DayOfWeek.SATURDAY.toString(), Availability.strToDayOfWeek(new String("SATurday"))); + assertEquals(DayOfWeek.SUNDAY.toString(), Availability.strToDayOfWeek(new String("sunDAY"))); + } } From 782d321813030dcee362d066d959ca87453ba771 Mon Sep 17 00:00:00 2001 From: whitesnowx Date: Wed, 13 Mar 2024 05:16:00 +0800 Subject: [PATCH 10/13] added TUE check in AvailabilityTest --- src/test/java/staffconnect/model/person/AvailabilityTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/staffconnect/model/person/AvailabilityTest.java b/src/test/java/staffconnect/model/person/AvailabilityTest.java index dcf70e3070e..c73e4e0dcc7 100644 --- a/src/test/java/staffconnect/model/person/AvailabilityTest.java +++ b/src/test/java/staffconnect/model/person/AvailabilityTest.java @@ -49,7 +49,8 @@ public void isValidAvailability() { // valid availability assertTrue(Availability.isValidAvailability("mon")); // first syllable tuesday - assertTrue(Availability.isValidAvailability("tues")); // first syllable tuesday + assertTrue(Availability.isValidAvailability("tue")); // first syllable tuesday without s + assertTrue(Availability.isValidAvailability("tues")); // first syllable tuesday with s assertTrue(Availability.isValidAvailability("wed")); // first syllable wednesday assertTrue(Availability.isValidAvailability("wednes")); // two syllable wednesday assertTrue(Availability.isValidAvailability("thu")); // first syllable thursday without rs From 2ea5a721bd111fb658bbe56ed2ceb4815311925f Mon Sep 17 00:00:00 2001 From: whitesnowx Date: Wed, 13 Mar 2024 23:06:05 +0800 Subject: [PATCH 11/13] Moved Availability to its own package --- .../model/{person => Availability}/Availability.java | 4 ++-- src/test/java/staffconnect/model/person/AvailabilityTest.java | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) rename src/main/java/staffconnect/model/{person => Availability}/Availability.java (97%) diff --git a/src/main/java/staffconnect/model/person/Availability.java b/src/main/java/staffconnect/model/Availability/Availability.java similarity index 97% rename from src/main/java/staffconnect/model/person/Availability.java rename to src/main/java/staffconnect/model/Availability/Availability.java index d72881d736c..e57cf4d1f27 100644 --- a/src/main/java/staffconnect/model/person/Availability.java +++ b/src/main/java/staffconnect/model/Availability/Availability.java @@ -1,4 +1,4 @@ -package staffconnect.model.person; +package staffconnect.model.Availability; import static java.util.Objects.requireNonNull; import static staffconnect.commons.util.AppUtil.checkArgument; @@ -61,7 +61,7 @@ public static String strToDayOfWeek(String validAvailability) { @Override public String toString() { - return value; + return '[' + value + ']'; } @Override diff --git a/src/test/java/staffconnect/model/person/AvailabilityTest.java b/src/test/java/staffconnect/model/person/AvailabilityTest.java index c73e4e0dcc7..05d5288de43 100644 --- a/src/test/java/staffconnect/model/person/AvailabilityTest.java +++ b/src/test/java/staffconnect/model/person/AvailabilityTest.java @@ -8,6 +8,7 @@ import java.time.DayOfWeek; import org.junit.jupiter.api.Test; +import staffconnect.model.Availability.Availability; public class AvailabilityTest { From b77a3c56227ee6b6193d42f05e71194cab08ad76 Mon Sep 17 00:00:00 2001 From: whitesnowx Date: Wed, 13 Mar 2024 23:08:19 +0800 Subject: [PATCH 12/13] Move AvailabilityTest to its own package --- .../model/{Availability => availability}/Availability.java | 0 .../model/{person => availability}/AvailabilityTest.java | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/main/java/staffconnect/model/{Availability => availability}/Availability.java (100%) rename src/test/java/staffconnect/model/{person => availability}/AvailabilityTest.java (100%) diff --git a/src/main/java/staffconnect/model/Availability/Availability.java b/src/main/java/staffconnect/model/availability/Availability.java similarity index 100% rename from src/main/java/staffconnect/model/Availability/Availability.java rename to src/main/java/staffconnect/model/availability/Availability.java diff --git a/src/test/java/staffconnect/model/person/AvailabilityTest.java b/src/test/java/staffconnect/model/availability/AvailabilityTest.java similarity index 100% rename from src/test/java/staffconnect/model/person/AvailabilityTest.java rename to src/test/java/staffconnect/model/availability/AvailabilityTest.java From 50d5a04c60ebfe9d44eec44814efc3acdceeff7a Mon Sep 17 00:00:00 2001 From: whitesnowx Date: Wed, 13 Mar 2024 23:12:17 +0800 Subject: [PATCH 13/13] add file changes for previous commit --- .../java/staffconnect/model/availability/Availability.java | 2 +- .../java/staffconnect/model/availability/AvailabilityTest.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/staffconnect/model/availability/Availability.java b/src/main/java/staffconnect/model/availability/Availability.java index e57cf4d1f27..dc8df4673c6 100644 --- a/src/main/java/staffconnect/model/availability/Availability.java +++ b/src/main/java/staffconnect/model/availability/Availability.java @@ -1,4 +1,4 @@ -package staffconnect.model.Availability; +package staffconnect.model.availability; import static java.util.Objects.requireNonNull; import static staffconnect.commons.util.AppUtil.checkArgument; diff --git a/src/test/java/staffconnect/model/availability/AvailabilityTest.java b/src/test/java/staffconnect/model/availability/AvailabilityTest.java index 05d5288de43..d10ba39d211 100644 --- a/src/test/java/staffconnect/model/availability/AvailabilityTest.java +++ b/src/test/java/staffconnect/model/availability/AvailabilityTest.java @@ -1,4 +1,4 @@ -package staffconnect.model.person; +package staffconnect.model.availability; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -8,7 +8,6 @@ import java.time.DayOfWeek; import org.junit.jupiter.api.Test; -import staffconnect.model.Availability.Availability; public class AvailabilityTest {