diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 4902b8345da..a78d11b0ae6 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -12,6 +12,7 @@ import seedu.address.model.person.Course; import seedu.address.model.person.Email; import seedu.address.model.person.Name; +import seedu.address.model.tag.StudentRank; import seedu.address.model.tag.Tag; /** @@ -80,7 +81,7 @@ public static Email parseEmail(String email) throws ParseException { } /** - * Parses a {@code String tag} into a {@code Tag}. + * Parses a {@code StudentRank tag} into a {@code Tag}. * Leading and trailing whitespaces will be trimmed. * * @throws ParseException if the given {@code tag} is invalid. @@ -91,7 +92,15 @@ public static Tag parseTag(String tag) throws ParseException { if (!Tag.isValidTagName(trimmedTag)) { throw new ParseException(Tag.MESSAGE_CONSTRAINTS); } - return new Tag(trimmedTag); + if (trimmedTag.equals(StudentRank.GOOD.toString())) { + return new Tag(StudentRank.GOOD); + } else if (trimmedTag.equals(StudentRank.POOR.toString())) { + return new Tag(StudentRank.POOR); + } else if (trimmedTag.equals(StudentRank.AVERAGE.toString())) { + return new Tag(StudentRank.AVERAGE); + } else { + throw new ParseException(Tag.MESSAGE_CONSTRAINTS_ENUMS); + } } /** diff --git a/src/main/java/seedu/address/model/tag/StudentRank.java b/src/main/java/seedu/address/model/tag/StudentRank.java new file mode 100644 index 00000000000..d8a0c5735f3 --- /dev/null +++ b/src/main/java/seedu/address/model/tag/StudentRank.java @@ -0,0 +1,10 @@ +package seedu.address.model.tag; + +/** + * Enumeration representing the ranking of a student's performance. + */ +public enum StudentRank { + GOOD, + AVERAGE, + POOR +} diff --git a/src/main/java/seedu/address/model/tag/Tag.java b/src/main/java/seedu/address/model/tag/Tag.java index f1a0d4e233b..26cb66df79d 100644 --- a/src/main/java/seedu/address/model/tag/Tag.java +++ b/src/main/java/seedu/address/model/tag/Tag.java @@ -10,19 +10,20 @@ public class Tag { public static final String MESSAGE_CONSTRAINTS = "Tags names should be alphanumeric"; + public static final String MESSAGE_CONSTRAINTS_ENUMS = "Tags names should be GOOD/AVERAGE/POOR"; public static final String VALIDATION_REGEX = "\\p{Alnum}+"; - public final String tagName; + public final StudentRank ranking; /** * Constructs a {@code Tag}. * - * @param tagName A valid tag name. + * @param ranking A valid tag name. */ - public Tag(String tagName) { - requireNonNull(tagName); - checkArgument(isValidTagName(tagName), MESSAGE_CONSTRAINTS); - this.tagName = tagName; + public Tag(StudentRank ranking) { + requireNonNull(ranking); + checkArgument(isValidTagName(ranking.toString()), MESSAGE_CONSTRAINTS); + this.ranking = ranking; } /** @@ -44,19 +45,19 @@ public boolean equals(Object other) { } Tag otherTag = (Tag) other; - return tagName.equals(otherTag.tagName); + return ranking.toString().equals(otherTag.ranking.toString()); } @Override public int hashCode() { - return tagName.hashCode(); + return ranking.hashCode(); } /** * Format state as text for viewing. */ public String toString() { - return '[' + tagName + ']'; + return '[' + ranking.toString() + ']'; } } diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 20d1359c906..6ffa4c34eae 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -11,6 +11,7 @@ import seedu.address.model.person.Name; import seedu.address.model.person.Remark; import seedu.address.model.person.Student; +import seedu.address.model.tag.StudentRank; import seedu.address.model.tag.Tag; /** @@ -19,20 +20,19 @@ public class SampleDataUtil { public static final Remark EMPTY_REMARK = new Remark(""); public static Student[] getSampleStudents() { - return new Student[] { new Student(new Name("Alex Yeoh"), new Course("CS2103T"), new Email("alexyeoh@u.nus.edu"), EMPTY_REMARK, - getTagSet("GOOD")), + getTagSet(StudentRank.GOOD)), new Student(new Name("Bernice Yu"), new Course("CS2103T"), new Email("berniceyu@u.nus.edu"), - EMPTY_REMARK, getTagSet("GOOD")), + EMPTY_REMARK, getTagSet(StudentRank.POOR)), new Student(new Name("Charlotte Oliveiro"), new Course("CS2103T"), new Email("charlotte@u.nus.edu"), - EMPTY_REMARK, getTagSet("POOR")), + EMPTY_REMARK, getTagSet(StudentRank.POOR)), new Student(new Name("David Li"), new Course("CS2103T"), new Email("lidavid@u.nus.edu"), EMPTY_REMARK, - getTagSet("POOR")), + getTagSet(StudentRank.AVERAGE)), new Student(new Name("Irfan Ibrahim"), new Course("CS2103T"), new Email("irfan@u.nus.edu"), - EMPTY_REMARK, getTagSet("AVERAGE")), + EMPTY_REMARK, getTagSet(StudentRank.GOOD)), new Student(new Name("Roy Balakrishnan"), new Course("CS2103T"), new Email("royb@u.nus.edu"), - EMPTY_REMARK, getTagSet("AVERAGE")) + EMPTY_REMARK, getTagSet(StudentRank.GOOD)) }; } @@ -47,8 +47,8 @@ public static ReadOnlyStudentList getSampleStudentList() { /** * Returns a tag set containing the list of strings given. */ - public static Set getTagSet(String... strings) { - return Arrays.stream(strings) + public static Set getTagSet(StudentRank... ranking) { + return Arrays.stream(ranking) .map(Tag::new) .collect(Collectors.toSet()); } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedTag.java b/src/main/java/seedu/address/storage/JsonAdaptedTag.java index 0df22bdb754..226de2c6e6e 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedTag.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedTag.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonValue; import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.logic.parser.ParserUtil; import seedu.address.model.tag.Tag; /** @@ -11,26 +12,26 @@ */ class JsonAdaptedTag { - private final String tagName; + private final String ranking; /** * Constructs a {@code JsonAdaptedTag} with the given {@code tagName}. */ @JsonCreator - public JsonAdaptedTag(String tagName) { - this.tagName = tagName; + public JsonAdaptedTag(String ranking) { + this.ranking = ranking; } /** * Converts a given {@code Tag} into this class for Jackson use. */ public JsonAdaptedTag(Tag source) { - tagName = source.tagName; + ranking = source.ranking.toString(); } @JsonValue public String getTagName() { - return tagName; + return ranking; } /** @@ -39,10 +40,10 @@ public String getTagName() { * @throws IllegalValueException if there were any data constraints violated in the adapted tag. */ public Tag toModelType() throws IllegalValueException { - if (!Tag.isValidTagName(tagName)) { + if (!Tag.isValidTagName(ranking)) { throw new IllegalValueException(Tag.MESSAGE_CONSTRAINTS); } - return new Tag(tagName); + return ParserUtil.parseTag(ranking); } } diff --git a/src/main/java/seedu/address/ui/StudentCard.java b/src/main/java/seedu/address/ui/StudentCard.java index c533beb34b7..7bd41c182e0 100644 --- a/src/main/java/seedu/address/ui/StudentCard.java +++ b/src/main/java/seedu/address/ui/StudentCard.java @@ -53,7 +53,7 @@ public StudentCard(Student student, int displayedIndex) { email.setText(student.getEmail().value); remark.setText(student.getRemark().value); student.getTags().stream() - .sorted(Comparator.comparing(tag -> tag.tagName)) - .forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); + .sorted(Comparator.comparing(tag -> tag.ranking)) + .forEach(tag -> tags.getChildren().add(new Label(tag.ranking.toString()))); } } diff --git a/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json index a602b100467..78c4f284110 100644 --- a/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json @@ -4,8 +4,7 @@ "phone": "94351253", "email": "alice@example.com", "address": "123, Jurong West Ave 6, #08-111", - "remark" : "", - "tagged": [ "friends" ] + "remark" : "" }, { "name": "Alice Pauline", "phone": "94351253", diff --git a/src/test/data/JsonSerializableStudentListTest/duplicateStudentStudentList.json b/src/test/data/JsonSerializableStudentListTest/duplicateStudentStudentList.json index 17f3bcc7d19..7255794584f 100644 --- a/src/test/data/JsonSerializableStudentListTest/duplicateStudentStudentList.json +++ b/src/test/data/JsonSerializableStudentListTest/duplicateStudentStudentList.json @@ -4,7 +4,7 @@ "course": "CS2103T", "email": "alice@example.com", "remark" : "", - "tags": [ "friends" ] + "tags": [ "GOOD" ] }, { "name": "Alice Pauline", "course": "CS2103T", diff --git a/src/test/data/JsonSerializableStudentListTest/typicalStudentsStudentList.json b/src/test/data/JsonSerializableStudentListTest/typicalStudentsStudentList.json index fcc23a1935b..742284fcbd7 100644 --- a/src/test/data/JsonSerializableStudentListTest/typicalStudentsStudentList.json +++ b/src/test/data/JsonSerializableStudentListTest/typicalStudentsStudentList.json @@ -4,15 +4,15 @@ "name" : "Alice Pauline", "course" : "CS2103T", "email" : "alice@example.com", - "remark" : "", - "tags" : [ "friends" ] + "remark" : "She likes aardvarks.", + "tags" : [ "AVERAGE" ] }, { "name" : "Benson Meier", "course" : "CS2103T", "email" : "johnd@example.com", - "remark" : "", - "tags" : [ "owesMoney", "friends" ] + "remark" : "He can't take beer!", + "tags" : [ "GOOD" ] }, { "name" : "Carl Kurz", @@ -26,7 +26,7 @@ "course" : "CS2103T", "email" : "cornelia@example.com", "remark" : "", - "tags" : [ "friends" ] + "tags" : [ "GOOD" ] }, { "name" : "Elle Meyer", diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index daa742620d0..c5cd5235e78 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -18,6 +18,7 @@ import seedu.address.model.StudentList; import seedu.address.model.person.NameContainsKeywordsPredicate; import seedu.address.model.person.Student; +import seedu.address.model.tag.StudentRank; import seedu.address.testutil.EditStudentDescriptorBuilder; /** @@ -27,23 +28,32 @@ public class CommandTestUtil { public static final String VALID_NAME_AMY = "Amy Bee"; public static final String VALID_NAME_BOB = "Bob Choo"; + public static final String VALID_NAME_CLARA = "Clara Ng"; + public static final String VALID_COURSE_AMY = "11111111"; public static final String VALID_COURSE_BOB = "22222222"; + public static final String VALID_COURSE_CLARA = "33333333"; public static final String VALID_EMAIL_AMY = "amy@example.com"; public static final String VALID_EMAIL_BOB = "bob@example.com"; + public static final String VALID_EMAIL_CLARA = "clara@example.com"; public static final String VALID_REMARK_AMY = "Like skiing."; public static final String VALID_REMARK_BOB = "Favourite pastime: Eating"; - public static final String VALID_TAG_HUSBAND = "husband"; - public static final String VALID_TAG_FRIEND = "friend"; + public static final StudentRank VALID_TAG_AVERAGE = StudentRank.AVERAGE; + public static final StudentRank VALID_TAG_GOOD = StudentRank.GOOD; + public static final StudentRank VALID_TAG_POOR = StudentRank.POOR; public static final String NAME_DESC_AMY = " " + PREFIX_NAME + VALID_NAME_AMY; public static final String NAME_DESC_BOB = " " + PREFIX_NAME + VALID_NAME_BOB; + public static final String NAME_DESC_CLARA = " " + PREFIX_NAME + VALID_NAME_CLARA; public static final String COURSE_DESC_AMY = " " + PREFIX_COURSE + VALID_COURSE_AMY; public static final String COURSE_DESC_BOB = " " + PREFIX_COURSE + VALID_COURSE_BOB; + public static final String COURSE_DESC_CLARA = " " + PREFIX_COURSE + VALID_COURSE_CLARA; public static final String EMAIL_DESC_AMY = " " + PREFIX_EMAIL + VALID_EMAIL_AMY; public static final String EMAIL_DESC_BOB = " " + PREFIX_EMAIL + VALID_EMAIL_BOB; - public static final String TAG_DESC_FRIEND = " " + PREFIX_TAG + VALID_TAG_FRIEND; - public static final String TAG_DESC_HUSBAND = " " + PREFIX_TAG + VALID_TAG_HUSBAND; + public static final String EMAIL_DESC_CLARA = " " + PREFIX_EMAIL + VALID_EMAIL_CLARA; + public static final String TAG_DESC_AVERAGE = " " + PREFIX_TAG + VALID_TAG_AVERAGE; + public static final String TAG_DESC_GOOD = " " + PREFIX_TAG + VALID_TAG_GOOD; + public static final String TAG_DESC_POOR = " " + PREFIX_TAG + VALID_TAG_POOR; public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "James&"; // '&' not allowed in names public static final String INVALID_COURSE_DESC = " " + PREFIX_COURSE + "911CS"; // 'a' not allowed in COURSEs @@ -52,17 +62,20 @@ public class CommandTestUtil { public static final String PREAMBLE_WHITESPACE = "\t \r \n"; public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble"; - public static final EditCommand.EditStudentDescriptor DESC_AMY; public static final EditCommand.EditStudentDescriptor DESC_BOB; + public static final EditCommand.EditStudentDescriptor DESC_CLARA; static { DESC_AMY = new EditStudentDescriptorBuilder().withName(VALID_NAME_AMY) .withCourse(VALID_COURSE_AMY).withEmail(VALID_EMAIL_AMY) - .withTags(VALID_TAG_FRIEND).build(); + .withTags(VALID_TAG_AVERAGE).build(); DESC_BOB = new EditStudentDescriptorBuilder().withName(VALID_NAME_BOB) .withCourse(VALID_COURSE_BOB).withEmail(VALID_EMAIL_BOB) - .withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND).build(); + .withTags(VALID_TAG_POOR).build(); + DESC_CLARA = new EditStudentDescriptorBuilder().withName(VALID_NAME_CLARA) + .withCourse(VALID_COURSE_CLARA).withEmail(VALID_EMAIL_CLARA) + .withTags(VALID_TAG_GOOD).build(); } /** diff --git a/src/test/java/seedu/address/logic/commands/EditCommandTest.java b/src/test/java/seedu/address/logic/commands/EditCommandTest.java index 31bb03b4f3c..11f3ad7171b 100644 --- a/src/test/java/seedu/address/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/EditCommandTest.java @@ -7,7 +7,7 @@ import static seedu.address.logic.commands.CommandTestUtil.DESC_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_AVERAGE; import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.address.logic.commands.CommandTestUtil.showStudentAtIndex; @@ -54,13 +54,12 @@ public void execute_allFieldsSpecifiedUnfilteredList_success() { public void execute_someFieldsSpecifiedUnfilteredList_success() { Index indexLastStudent = Index.fromOneBased(model.getFilteredStudentList().size()); Student lastStudent = model.getFilteredStudentList().get(indexLastStudent.getZeroBased()); - StudentBuilder studentInList = new StudentBuilder(lastStudent); Student editedStudent = studentInList.withName(VALID_NAME_BOB).withCourse(VALID_COURSE_BOB) - .withTags(VALID_TAG_HUSBAND).build(); + .withTags(VALID_TAG_AVERAGE).build(); EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder().withName(VALID_NAME_BOB) - .withCourse(VALID_COURSE_BOB).withTags(VALID_TAG_HUSBAND).build(); + .withCourse(VALID_COURSE_BOB).withTags(VALID_TAG_AVERAGE).build(); EditCommand editCommand = new EditCommand(indexLastStudent, descriptor); String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_STUDENT_SUCCESS, diff --git a/src/test/java/seedu/address/logic/commands/EditStudentDescriptorTest.java b/src/test/java/seedu/address/logic/commands/EditStudentDescriptorTest.java index fae3ecb1f26..8ac45f5a779 100644 --- a/src/test/java/seedu/address/logic/commands/EditStudentDescriptorTest.java +++ b/src/test/java/seedu/address/logic/commands/EditStudentDescriptorTest.java @@ -8,7 +8,7 @@ import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_GOOD; import org.junit.jupiter.api.Test; @@ -48,7 +48,7 @@ public void equals() { assertFalse(DESC_AMY.equals(editedAmy)); // different tags -> returns false - editedAmy = new EditStudentDescriptorBuilder(DESC_AMY).withTags(VALID_TAG_HUSBAND).build(); + editedAmy = new EditStudentDescriptorBuilder(DESC_AMY).withTags(VALID_TAG_GOOD).build(); assertFalse(DESC_AMY.equals(editedAmy)); } diff --git a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java index 0aa9e2db221..d7e96d03369 100644 --- a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java @@ -8,18 +8,19 @@ import static seedu.address.logic.commands.CommandTestUtil.INVALID_COURSE_DESC; import static seedu.address.logic.commands.CommandTestUtil.INVALID_EMAIL_DESC; import static seedu.address.logic.commands.CommandTestUtil.INVALID_NAME_DESC; -import static seedu.address.logic.commands.CommandTestUtil.INVALID_TAG_DESC; import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_BOB; import static seedu.address.logic.commands.CommandTestUtil.PREAMBLE_NON_EMPTY; import static seedu.address.logic.commands.CommandTestUtil.PREAMBLE_WHITESPACE; -import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_FRIEND; -import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_AVERAGE; +import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_GOOD; +import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_POOR; import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_FRIEND; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_AVERAGE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_GOOD; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_POOR; import static seedu.address.logic.parser.CliSyntax.PREFIX_COURSE; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; @@ -36,7 +37,6 @@ import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.Student; -import seedu.address.model.tag.Tag; import seedu.address.testutil.StudentBuilder; public class AddCommandParserTest { @@ -44,25 +44,25 @@ public class AddCommandParserTest { @Test public void parse_allFieldsPresent_success() { - Student expectedStudent = new StudentBuilder(BOB).withTags(VALID_TAG_FRIEND).build(); + Student expectedStudent = new StudentBuilder(BOB).withTags(VALID_TAG_GOOD).build(); // whitespace only preamble assertParseSuccess(parser, PREAMBLE_WHITESPACE + NAME_DESC_BOB + COURSE_DESC_BOB + EMAIL_DESC_BOB - + TAG_DESC_FRIEND, new AddCommand(expectedStudent)); + + TAG_DESC_GOOD, new AddCommand(expectedStudent)); // multiple tags - all accepted - Student expectedStudentMultipleTags = new StudentBuilder(BOB).withTags(VALID_TAG_FRIEND, VALID_TAG_HUSBAND) + Student expectedStudentMultipleTags = new StudentBuilder(BOB).withTags(VALID_TAG_POOR, VALID_TAG_AVERAGE) .build(); assertParseSuccess(parser, - NAME_DESC_BOB + COURSE_DESC_BOB + EMAIL_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, + NAME_DESC_BOB + COURSE_DESC_BOB + EMAIL_DESC_BOB + TAG_DESC_POOR + TAG_DESC_AVERAGE, new AddCommand(expectedStudentMultipleTags)); } @Test public void parse_repeatedNonTagValue_failure() { String validExpectedStudentString = NAME_DESC_BOB + COURSE_DESC_BOB + EMAIL_DESC_BOB - + TAG_DESC_FRIEND; + + TAG_DESC_AVERAGE; // multiple names assertParseFailure(parser, NAME_DESC_AMY + validExpectedStudentString, @@ -120,6 +120,7 @@ public void parse_optionalFieldsMissing_success() { new AddCommand(expectedStudent)); } + @Test public void parse_compulsoryFieldMissing_failure() { String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE); @@ -145,19 +146,15 @@ public void parse_compulsoryFieldMissing_failure() { public void parse_invalidValue_failure() { // invalid name assertParseFailure(parser, INVALID_NAME_DESC + COURSE_DESC_BOB + EMAIL_DESC_BOB - + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Name.MESSAGE_CONSTRAINTS); + + TAG_DESC_GOOD + TAG_DESC_AVERAGE, Name.MESSAGE_CONSTRAINTS); // invalid COURSE assertParseFailure(parser, NAME_DESC_BOB + INVALID_COURSE_DESC + EMAIL_DESC_BOB - + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Course.MESSAGE_CONSTRAINTS); + + TAG_DESC_GOOD + TAG_DESC_AVERAGE, Course.MESSAGE_CONSTRAINTS); // invalid email assertParseFailure(parser, NAME_DESC_BOB + COURSE_DESC_BOB + INVALID_EMAIL_DESC - + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Email.MESSAGE_CONSTRAINTS); - - // invalid tag - assertParseFailure(parser, NAME_DESC_BOB + COURSE_DESC_BOB + EMAIL_DESC_BOB - + INVALID_TAG_DESC + VALID_TAG_FRIEND, Tag.MESSAGE_CONSTRAINTS); + + TAG_DESC_GOOD + TAG_DESC_AVERAGE, Email.MESSAGE_CONSTRAINTS); // two invalid values, only first invalid value reported assertParseFailure(parser, INVALID_NAME_DESC + COURSE_DESC_BOB + EMAIL_DESC_BOB, @@ -165,7 +162,7 @@ public void parse_invalidValue_failure() { // non-empty preamble assertParseFailure(parser, PREAMBLE_NON_EMPTY + NAME_DESC_BOB + COURSE_DESC_BOB + EMAIL_DESC_BOB - + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, + + TAG_DESC_AVERAGE + TAG_DESC_GOOD, String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } } diff --git a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java index c7b93ba2480..81a4e43e10f 100644 --- a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java @@ -10,14 +10,14 @@ import static seedu.address.logic.commands.CommandTestUtil.INVALID_NAME_DESC; import static seedu.address.logic.commands.CommandTestUtil.INVALID_TAG_DESC; import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY; -import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_FRIEND; -import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_AVERAGE; +import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_GOOD; import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_AMY; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_FRIEND; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_AVERAGE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_GOOD; import static seedu.address.logic.parser.CliSyntax.PREFIX_COURSE; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; @@ -87,9 +87,9 @@ public void parse_invalidValue_failure() { // while parsing {@code PREFIX_TAG} alone will reset the tags of the {@code Person} being edited, // parsing it together with a valid tag results in error - assertParseFailure(parser, "1" + TAG_DESC_FRIEND + TAG_DESC_HUSBAND + TAG_EMPTY, Tag.MESSAGE_CONSTRAINTS); - assertParseFailure(parser, "1" + TAG_DESC_FRIEND + TAG_EMPTY + TAG_DESC_HUSBAND, Tag.MESSAGE_CONSTRAINTS); - assertParseFailure(parser, "1" + TAG_EMPTY + TAG_DESC_FRIEND + TAG_DESC_HUSBAND, Tag.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, "1" + TAG_DESC_GOOD + TAG_DESC_AVERAGE + TAG_EMPTY, Tag.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, "1" + TAG_DESC_GOOD + TAG_EMPTY + TAG_DESC_AVERAGE, Tag.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, "1" + TAG_EMPTY + TAG_DESC_GOOD + TAG_DESC_AVERAGE, Tag.MESSAGE_CONSTRAINTS); // multiple invalid values, but only the first invalid value is captured assertParseFailure(parser, "1" + INVALID_NAME_DESC + INVALID_EMAIL_DESC + VALID_COURSE_AMY, @@ -99,12 +99,12 @@ public void parse_invalidValue_failure() { @Test public void parse_allFieldsSpecified_success() { Index targetIndex = INDEX_SECOND_STUDENT; - String userInput = targetIndex.getOneBased() + COURSE_DESC_BOB + TAG_DESC_HUSBAND - + EMAIL_DESC_AMY + NAME_DESC_AMY + TAG_DESC_FRIEND; + String userInput = targetIndex.getOneBased() + COURSE_DESC_BOB + TAG_DESC_AVERAGE + + EMAIL_DESC_AMY + NAME_DESC_AMY + TAG_DESC_AVERAGE; EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder().withName(VALID_NAME_AMY) .withCourse(VALID_COURSE_BOB).withEmail(VALID_EMAIL_AMY) - .withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND).build(); + .withTags(VALID_TAG_AVERAGE, VALID_TAG_AVERAGE).build(); EditCommand expectedCommand = new EditCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); @@ -144,8 +144,9 @@ public void parse_oneFieldSpecified_success() { assertParseSuccess(parser, userInput, expectedCommand); // tags - userInput = targetIndex.getOneBased() + TAG_DESC_FRIEND; - descriptor = new EditStudentDescriptorBuilder().withTags(VALID_TAG_FRIEND).build(); + + userInput = targetIndex.getOneBased() + TAG_DESC_GOOD; + descriptor = new EditStudentDescriptorBuilder().withTags(VALID_TAG_GOOD).build(); expectedCommand = new EditCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); } @@ -168,8 +169,8 @@ public void parse_multipleRepeatedFields_failure() { // mulltiple valid fields repeated userInput = targetIndex.getOneBased() + COURSE_DESC_AMY + EMAIL_DESC_AMY - + TAG_DESC_FRIEND + COURSE_DESC_AMY + EMAIL_DESC_AMY + TAG_DESC_FRIEND - + COURSE_DESC_BOB + EMAIL_DESC_BOB + TAG_DESC_HUSBAND; + + TAG_DESC_GOOD + COURSE_DESC_AMY + EMAIL_DESC_AMY + TAG_DESC_GOOD + + COURSE_DESC_BOB + EMAIL_DESC_BOB + TAG_DESC_AVERAGE; assertParseFailure(parser, userInput, Messages.getErrorMessageForDuplicatePrefixes(PREFIX_COURSE, PREFIX_EMAIL)); diff --git a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java index d03486cf666..a986404afb8 100644 --- a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java +++ b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java @@ -17,19 +17,20 @@ import seedu.address.model.person.Course; import seedu.address.model.person.Email; import seedu.address.model.person.Name; +import seedu.address.model.tag.StudentRank; import seedu.address.model.tag.Tag; public class ParserUtilTest { private static final String INVALID_NAME = "R@chel"; private static final String INVALID_COURSE = "+651234"; private static final String INVALID_EMAIL = "example.com"; - private static final String INVALID_TAG = "#friend"; + private static final String INVALID_TAG = "im a invalid tag"; private static final String VALID_NAME = "Rachel Walker"; private static final String VALID_COURSE = "CS2103T"; private static final String VALID_EMAIL = "rachel@example.com"; - private static final String VALID_TAG_1 = "friend"; - private static final String VALID_TAG_2 = "neighbour"; + private static final StudentRank VALID_TAG_1 = StudentRank.GOOD; + private static final StudentRank VALID_TAG_2 = StudentRank.AVERAGE; private static final String WHITESPACE = " \t\r\n"; @@ -129,13 +130,13 @@ public void parseTag_null_throwsNullPointerException() { @Test public void parseTag_invalidValue_throwsParseException() { - assertThrows(ParseException.class, () -> ParserUtil.parseTag(INVALID_TAG)); + assertThrows(ParseException.class, () -> ParserUtil.parseTag(INVALID_TAG.toString())); } @Test public void parseTag_validValueWithoutWhitespace_returnsTag() throws Exception { Tag expectedTag = new Tag(VALID_TAG_1); - assertEquals(expectedTag, ParserUtil.parseTag(VALID_TAG_1)); + assertEquals(expectedTag, ParserUtil.parseTag(VALID_TAG_1.toString())); } @Test @@ -152,7 +153,8 @@ public void parseTags_null_throwsNullPointerException() { @Test public void parseTags_collectionWithInvalidTags_throwsParseException() { - assertThrows(ParseException.class, () -> ParserUtil.parseTags(Arrays.asList(VALID_TAG_1, INVALID_TAG))); + assertThrows(ParseException.class, () -> ParserUtil.parseTags( + Arrays.asList(VALID_TAG_1.toString(), INVALID_TAG.toString()))); } @Test @@ -162,7 +164,7 @@ public void parseTags_emptyCollection_returnsEmptySet() throws Exception { @Test public void parseTags_collectionWithValidTags_returnsTagSet() throws Exception { - Set actualTagSet = ParserUtil.parseTags(Arrays.asList(VALID_TAG_1, VALID_TAG_2)); + Set actualTagSet = ParserUtil.parseTags(Arrays.asList(VALID_TAG_1.toString(), VALID_TAG_2.toString())); Set expectedTagSet = new HashSet(Arrays.asList(new Tag(VALID_TAG_1), new Tag(VALID_TAG_2))); assertEquals(expectedTagSet, actualTagSet); diff --git a/src/test/java/seedu/address/model/StudentListTest.java b/src/test/java/seedu/address/model/StudentListTest.java index 724758772d7..e4875cfebb8 100644 --- a/src/test/java/seedu/address/model/StudentListTest.java +++ b/src/test/java/seedu/address/model/StudentListTest.java @@ -3,7 +3,7 @@ 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 seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_GOOD; import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalStudents.ALICE; import static seedu.address.testutil.TypicalStudents.getTypicalStudentList; @@ -45,7 +45,7 @@ public void resetData_withValidReadOnlyStudentList_replacesData() { @Test public void resetData_withDuplicateStudents_throwsDuplicateStudentException() { // Two Students with the same identity fields - Student editedAlice = new StudentBuilder(ALICE).withTags(VALID_TAG_HUSBAND) + Student editedAlice = new StudentBuilder(ALICE).withTags(VALID_TAG_GOOD) .build(); List newStudents = Arrays.asList(ALICE, editedAlice); StudentListStub newData = new StudentListStub(newStudents); @@ -72,7 +72,7 @@ public void hasStudent_studentInStudentList_returnsTrue() { @Test public void hasStudent_studentWithSameIdentityFieldsInStudentList_returnsTrue() { studentList.addStudent(ALICE); - Student editedAlice = new StudentBuilder(ALICE).withTags(VALID_TAG_HUSBAND) + Student editedAlice = new StudentBuilder(ALICE).withTags(VALID_TAG_GOOD) .build(); assertTrue(studentList.hasStudent(editedAlice)); } diff --git a/src/test/java/seedu/address/model/person/StudentTest.java b/src/test/java/seedu/address/model/person/StudentTest.java index 68c64a21df6..b1abc6af87f 100644 --- a/src/test/java/seedu/address/model/person/StudentTest.java +++ b/src/test/java/seedu/address/model/person/StudentTest.java @@ -6,7 +6,8 @@ import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_AVERAGE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_GOOD; import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalStudents.ALICE; import static seedu.address.testutil.TypicalStudents.BOB; @@ -33,7 +34,7 @@ public void isSameStudent() { // same name, all other attributes different -> returns false Student editedAlice = new StudentBuilder(ALICE).withCourse(VALID_COURSE_BOB).withEmail(VALID_EMAIL_BOB) - .withTags(VALID_TAG_HUSBAND).build(); + .withTags(VALID_TAG_AVERAGE).build(); assertFalse(ALICE.isSameStudent(editedAlice)); // different name, all other attributes same -> returns false @@ -81,7 +82,7 @@ public void equals() { assertFalse(ALICE.equals(editedAlice)); // different tags -> returns false - editedAlice = new StudentBuilder(ALICE).withTags(VALID_TAG_HUSBAND).build(); + editedAlice = new StudentBuilder(ALICE).withTags(VALID_TAG_GOOD).build(); assertFalse(ALICE.equals(editedAlice)); } diff --git a/src/test/java/seedu/address/model/person/UniqueStudentListTest.java b/src/test/java/seedu/address/model/person/UniqueStudentListTest.java index ad38b220b64..0bca802343c 100644 --- a/src/test/java/seedu/address/model/person/UniqueStudentListTest.java +++ b/src/test/java/seedu/address/model/person/UniqueStudentListTest.java @@ -3,7 +3,7 @@ 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 seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_GOOD; import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalStudents.ALICE; import static seedu.address.testutil.TypicalStudents.BOB; @@ -41,7 +41,7 @@ public void contains_studentInList_returnsTrue() { @Test public void contains_studentWithSameIdentityFieldsInList_returnsTrue() { uniqueStudentList.add(ALICE); - Student editedAlice = new StudentBuilder(ALICE).withTags(VALID_TAG_HUSBAND) + Student editedAlice = new StudentBuilder(ALICE).withTags(VALID_TAG_GOOD) .build(); assertTrue(uniqueStudentList.contains(editedAlice)); } @@ -84,7 +84,7 @@ public void setStudent_editedStudentIsSameStudent_success() { @Test public void setStudent_editedStudentHasSameIdentity_success() { uniqueStudentList.add(ALICE); - Student editedAlice = new StudentBuilder(ALICE).withTags(VALID_TAG_HUSBAND) + Student editedAlice = new StudentBuilder(ALICE).withTags(VALID_TAG_GOOD) .build(); uniqueStudentList.setStudent(ALICE, editedAlice); UniqueStudentList expectedUniqueStudentList = new UniqueStudentList(); diff --git a/src/test/java/seedu/address/model/tag/TagTest.java b/src/test/java/seedu/address/model/tag/TagTest.java index 64d07d79ee2..dda71ffda3f 100644 --- a/src/test/java/seedu/address/model/tag/TagTest.java +++ b/src/test/java/seedu/address/model/tag/TagTest.java @@ -4,6 +4,9 @@ import org.junit.jupiter.api.Test; +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.logic.parser.ParserUtil; + public class TagTest { @Test @@ -12,9 +15,9 @@ public void constructor_null_throwsNullPointerException() { } @Test - public void constructor_invalidTagName_throwsIllegalArgumentException() { - String invalidTagName = ""; - assertThrows(IllegalArgumentException.class, () -> new Tag(invalidTagName)); + public void constructor_invalidTagName_throwsIllegalValueException() { + String invalidTagName = "#invalid"; + assertThrows(IllegalValueException.class, () -> ParserUtil.parseTag(invalidTagName)); } @Test diff --git a/src/test/java/seedu/address/testutil/EditStudentDescriptorBuilder.java b/src/test/java/seedu/address/testutil/EditStudentDescriptorBuilder.java index cc0dc66f36c..51d6cd17cc9 100644 --- a/src/test/java/seedu/address/testutil/EditStudentDescriptorBuilder.java +++ b/src/test/java/seedu/address/testutil/EditStudentDescriptorBuilder.java @@ -9,6 +9,7 @@ import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.Student; +import seedu.address.model.tag.StudentRank; import seedu.address.model.tag.Tag; /** @@ -66,7 +67,7 @@ public EditStudentDescriptorBuilder withEmail(String email) { * Parses the {@code tags} into a {@code Set} and set it to the {@code EditPersonDescriptor} * that we are building. */ - public EditStudentDescriptorBuilder withTags(String... tags) { + public EditStudentDescriptorBuilder withTags(StudentRank... tags) { Set tagSet = Stream.of(tags).map(Tag::new).collect(Collectors.toSet()); descriptor.setTags(tagSet); return this; diff --git a/src/test/java/seedu/address/testutil/StudentBuilder.java b/src/test/java/seedu/address/testutil/StudentBuilder.java index c8ad7911d55..0dd16b29b45 100644 --- a/src/test/java/seedu/address/testutil/StudentBuilder.java +++ b/src/test/java/seedu/address/testutil/StudentBuilder.java @@ -8,6 +8,7 @@ import seedu.address.model.person.Name; import seedu.address.model.person.Remark; import seedu.address.model.person.Student; +import seedu.address.model.tag.StudentRank; import seedu.address.model.tag.Tag; import seedu.address.model.util.SampleDataUtil; @@ -60,7 +61,7 @@ public StudentBuilder withName(String name) { /** * Parses the {@code tags} into a {@code Set} and set it to the {@code Person} that we are building. */ - public StudentBuilder withTags(String ... tags) { + public StudentBuilder withTags(StudentRank ... tags) { this.tags = SampleDataUtil.getTagSet(tags); return this; } diff --git a/src/test/java/seedu/address/testutil/StudentUtil.java b/src/test/java/seedu/address/testutil/StudentUtil.java index 9d02b61fdfd..b129d2501e3 100644 --- a/src/test/java/seedu/address/testutil/StudentUtil.java +++ b/src/test/java/seedu/address/testutil/StudentUtil.java @@ -33,7 +33,7 @@ public static String getPersonDetails(Student student) { sb.append(PREFIX_COURSE + student.getCourse().value + " "); sb.append(PREFIX_EMAIL + student.getEmail().value + " "); student.getTags().stream().forEach( - s -> sb.append(PREFIX_TAG + s.tagName + " ") + s -> sb.append(PREFIX_TAG + s.ranking.toString() + " ") ); return sb.toString(); } @@ -51,7 +51,7 @@ public static String getEditStudentDescriptorDetails(EditStudentDescriptor descr if (tags.isEmpty()) { sb.append(PREFIX_TAG); } else { - tags.forEach(s -> sb.append(PREFIX_TAG).append(s.tagName).append(" ")); + tags.forEach(s -> sb.append(PREFIX_TAG).append(s.ranking).append(" ")); } } return sb.toString(); diff --git a/src/test/java/seedu/address/testutil/TypicalStudents.java b/src/test/java/seedu/address/testutil/TypicalStudents.java index 42626c657f5..050782f4589 100644 --- a/src/test/java/seedu/address/testutil/TypicalStudents.java +++ b/src/test/java/seedu/address/testutil/TypicalStudents.java @@ -6,8 +6,9 @@ import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_FRIEND; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_AVERAGE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_GOOD; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_POOR; import java.util.ArrayList; import java.util.Arrays; @@ -22,15 +23,15 @@ public class TypicalStudents { public static final Student ALICE = new StudentBuilder().withName("Alice Pauline") - .withEmail("alice@example.com").withCourse("CS2103T") - .withTags("friends").build(); + .withEmail("alice@example.com").withCourse("CS2103T").withRemark("She likes aardvarks.") + .withTags(VALID_TAG_AVERAGE).build(); public static final Student BENSON = new StudentBuilder().withName("Benson Meier") - .withEmail("johnd@example.com").withCourse("CS2103T") - .withTags("owesMoney", "friends").build(); + .withEmail("johnd@example.com").withCourse("CS2103T").withRemark("He can't take beer!") + .withTags(VALID_TAG_GOOD).build(); public static final Student CARL = new StudentBuilder().withName("Carl Kurz").withCourse("CS2103T") .withEmail("heinz@example.com").build(); public static final Student DANIEL = new StudentBuilder().withName("Daniel Meier").withCourse("CS2103T") - .withEmail("cornelia@example.com").withTags("friends").build(); + .withEmail("cornelia@example.com").withTags(VALID_TAG_GOOD).build(); public static final Student ELLE = new StudentBuilder().withName("Elle Meyer").withCourse("CS2103T") .withEmail("werner@example.com").build(); public static final Student FIONA = new StudentBuilder().withName("Fiona Kunz").withCourse("CS2103T") @@ -46,9 +47,9 @@ public class TypicalStudents { // Manually added - Student's details found in {@code CommandTestUtil} public static final Student AMY = new StudentBuilder().withName(VALID_NAME_AMY).withCourse(VALID_COURSE_AMY) - .withEmail(VALID_EMAIL_AMY).withTags(VALID_TAG_FRIEND).build(); + .withEmail(VALID_EMAIL_AMY).withTags(VALID_TAG_AVERAGE).build(); public static final Student BOB = new StudentBuilder().withName(VALID_NAME_BOB).withCourse(VALID_COURSE_BOB) - .withEmail(VALID_EMAIL_BOB).withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND) + .withEmail(VALID_EMAIL_BOB).withTags(VALID_TAG_POOR) .build(); public static final String KEYWORD_MATCHING_MEIER = "Meier"; // A keyword that matches MEIER