diff --git a/src/main/java/seedu/address/logic/commands/AddTeamCommand.java b/src/main/java/seedu/address/logic/commands/AddTeamCommand.java index 63d5002b00d..ee26af442bb 100644 --- a/src/main/java/seedu/address/logic/commands/AddTeamCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddTeamCommand.java @@ -25,11 +25,11 @@ public class AddTeamCommand extends Command { public static final String COMMAND_WORD = "/add_team"; public static final String MESSAGE_USAGE = COMMAND_WORD - + ": Create a team with a name and an optional size, assigned to a particular tutorial class\n" - + "Parameters: " + PREFIX_MODULECODE + "MODULE_CODE " - + PREFIX_TUTORIALCLASS + "TUTORIAL_CLASS " + PREFIX_NAME + "TEAM_NAME " + PREFIX_TEAM_SIZE + "TEAM_SIZE\n" - + "Example: " + COMMAND_WORD + " " + PREFIX_MODULECODE + "CS2103T " - + PREFIX_TUTORIALCLASS + "T09 " + PREFIX_NAME + "Team 1 " + PREFIX_TEAM_SIZE + "5"; + + ": Create a team with a name and an optional size, assigned to a particular tutorial class\n" + + "Parameters: " + PREFIX_MODULECODE + "MODULE_CODE " + + PREFIX_TUTORIALCLASS + "TUTORIAL_CLASS " + PREFIX_NAME + "TEAM_NAME " + PREFIX_TEAM_SIZE + "TEAM_SIZE\n" + + "Example: " + COMMAND_WORD + " " + PREFIX_MODULECODE + "CS2103T " + + PREFIX_TUTORIALCLASS + "T09 " + PREFIX_NAME + "Team 1 " + PREFIX_TEAM_SIZE + "5"; private final ModuleCode module; private final TutorialClass tutorialClass; @@ -100,7 +100,7 @@ protected ModuleTutorialPair getModuleAndTutorialClass(Model model) throws Comma } if (existingTutorialClass == null) { throw new CommandException( - String.format(ModuleMessages.MESSAGE_TUTORIAL_DOES_NOT_BELONG_TO_MODULE, tutorialClass, module)); + String.format(ModuleMessages.MESSAGE_TUTORIAL_DOES_NOT_BELONG_TO_MODULE, tutorialClass, module)); } return new ModuleTutorialPair(existingModule, existingTutorialClass); } @@ -123,7 +123,7 @@ protected TutorialClass getTutorialClass() { */ private String generateSuccessMessage(ModuleCode module, TutorialClass tutorialString, String teamName) { return String.format(MESSAGE_ADD_TEAM_SUCCESS_WITHOUT_SIZE, teamName, module, - tutorialString); + tutorialString); } /** @@ -155,4 +155,4 @@ public boolean equals(Object other) { return module.equals(e.module) && tutorialClass.equals(e.tutorialClass) && teamName.equals(e.teamName) && teamSize == e.teamSize; } -} \ No newline at end of file +} diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index c6258538cf8..4d8b2f3a6a4 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -1,7 +1,8 @@ package seedu.address.logic.parser; /** - * Contains Command Line Interface (CLI) syntax definitions common to multiple commands + * Contains Command Line Interface (CLI) syntax definitions common to multiple + * commands */ public class CliSyntax { diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index b1b9d644d55..57e20948968 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -18,16 +18,19 @@ import seedu.address.model.tag.Tag; /** - * Contains utility methods used for parsing strings in the various *Parser classes. + * Contains utility methods used for parsing strings in the various *Parser + * classes. */ public class ParserUtil { public static final String MESSAGE_INVALID_INDEX = "Index is not a non-zero unsigned integer."; /** - * Parses {@code oneBasedIndex} into an {@code Index} and returns it. Leading and trailing whitespaces will be + * Parses {@code oneBasedIndex} into an {@code Index} and returns it. Leading + * and trailing whitespaces will be * trimmed. - * @throws ParseException if the specified index is invalid (not non-zero unsigned integer). + * @throws ParseException if the specified index is invalid (not non-zero + * unsigned integer). */ public static Index parseIndex(String oneBasedIndex) throws ParseException { String trimmedIndex = oneBasedIndex.trim(); @@ -40,7 +43,6 @@ public static Index parseIndex(String oneBasedIndex) throws ParseException { /** * Parses a {@code String name} into a {@code Name}. * Leading and trailing whitespaces will be trimmed. - * * @throws ParseException if the given {@code name} is invalid. */ public static Name parseName(String name) throws ParseException { @@ -55,7 +57,6 @@ public static Name parseName(String name) throws ParseException { /** * Parses a {@code String email} into an {@code Email}. * Leading and trailing whitespaces will be trimmed. - * * @throws ParseException if the given {@code email} is invalid. */ public static Email parseEmail(String email) throws ParseException { @@ -70,7 +71,6 @@ public static Email parseEmail(String email) throws ParseException { /** * Parses a {@code String studentId} into a {@code StudentId}. * Leading and trailing whitespaces will be trimmed. - * * @throws ParseException if the given {@code studentId} is invalid. */ public static StudentId parseStudentId(String studentId) throws ParseException { @@ -85,7 +85,6 @@ public static StudentId parseStudentId(String studentId) throws ParseException { /** * Parses a {@code String moduleCode} into an {@code ModuleCode}. * Leading and trailing whitespaces will be trimmed. - * * @throws ParseException if the given {@code moduleCode} is invalid. */ public static ModuleCode parseModuleCode(String moduleCode) throws ParseException { @@ -97,11 +96,9 @@ public static ModuleCode parseModuleCode(String moduleCode) throws ParseExceptio return new ModuleCode(trimmedModuleCode); } - /** * Parses a {@code String tutorial} into an {@code TutorialClass}. * Leading and trailing whitespaces will be trimmed. - * * @throws ParseException if the given {@code tutorial} is invalid. */ public static TutorialClass parseTutorialClass(String tutorial) throws ParseException { @@ -116,7 +113,6 @@ public static TutorialClass parseTutorialClass(String tutorial) throws ParseExce /** * Parses a {@code String tag} into a {@code Tag}. * Leading and trailing whitespaces will be trimmed. - * * @throws ParseException if the given {@code tag} is invalid. */ public static Tag parseTag(String tag) throws ParseException { diff --git a/src/main/java/seedu/address/model/module/TutorialClass.java b/src/main/java/seedu/address/model/module/TutorialClass.java index 93d06a5043f..ab1141bf17a 100644 --- a/src/main/java/seedu/address/model/module/TutorialClass.java +++ b/src/main/java/seedu/address/model/module/TutorialClass.java @@ -54,7 +54,7 @@ public TutorialClass(String tutorialClass) { /** * A constructor for TutorialClass. Creates a tutorial class with students. * @param tutorialClass to be added - * @param students in the tutorial class + * @param students in the tutorial class */ public TutorialClass(String tutorialClass, ArrayList students) { requireAllNonNull(tutorialClass); @@ -112,6 +112,7 @@ public ArrayList getStudents() { /** * Adds a student to the tutorial class. + * @param student */ public void addStudent(Person student) { students.add(student); @@ -119,7 +120,7 @@ public void addStudent(Person student) { /** * Removes a student from the tutorial class if it exists. - * + * @param student * @return true if the student was removed */ public boolean deleteStudent(Person student) { @@ -141,7 +142,6 @@ public boolean hasStudent(Person student) { public ArrayList getTeams() { return this.teams; } - /** * Adds a team to the tutorial class. * @param team @@ -157,6 +157,7 @@ public void addTeam(TutorialTeam team) { public boolean hasTeam(TutorialTeam team) { return teams.contains(team); } + @Override public String toString() { return tutorialName; diff --git a/src/main/java/seedu/address/model/module/TutorialTeam.java b/src/main/java/seedu/address/model/module/TutorialTeam.java index 219d918fb64..fd79131e86d 100644 --- a/src/main/java/seedu/address/model/module/TutorialTeam.java +++ b/src/main/java/seedu/address/model/module/TutorialTeam.java @@ -10,13 +10,15 @@ /** * Represents a Module's tutorial team. * Guarantees: immutable; is valid as declared in + * {@link #isValidTeamName(String)} + * */ public class TutorialTeam { public static final String MESSAGE_CONSTRAINTS = "Please enter a valid tutorial team name " - + "eg. Team 1, and it should not be blank"; + + "eg. Team 1, and it should not be blank"; public static final String MESSAGE_NAME_CONSTRAINTS = "Team names should only contain alphanumeric " - + "characters and spaces, and it should not be blank"; + + "characters and spaces, and it should not be blank"; public static final String MESSAGE_SIZE_CONSTRAINTS = "Team size should be a positive integer"; public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; diff --git a/src/main/java/seedu/address/storage/JsonAdaptedTutorialClass.java b/src/main/java/seedu/address/storage/JsonAdaptedTutorialClass.java index 19867499d86..b630044761d 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedTutorialClass.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedTutorialClass.java @@ -39,6 +39,7 @@ public JsonAdaptedTutorialClass(@JsonProperty("tutorialName") String tutorialNam */ public JsonAdaptedTutorialClass(TutorialClass source) { this.tutorialName = source.tutorialName; + this.teams = source.getTeams().stream().map(JsonAdaptedTutorialTeam::new).collect(Collectors.toList()); this.students = source.getStudents().stream().map(JsonAdaptedPerson::new).collect(Collectors.toList()); this.teams = source.getTeams().stream().map(JsonAdaptedTutorialTeam::new).collect(Collectors.toList()); } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedTutorialTeam.java b/src/main/java/seedu/address/storage/JsonAdaptedTutorialTeam.java index 2dcd8c0df74..7f6c5510543 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedTutorialTeam.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedTutorialTeam.java @@ -26,8 +26,13 @@ public class JsonAdaptedTutorialTeam { */ @JsonCreator public JsonAdaptedTutorialTeam(@JsonProperty("teamName") String teamName, +<<<<<<< HEAD @JsonProperty("teamSize") int teamSize, @JsonProperty("students") List students) { +======= + @JsonProperty("teamSize") int teamSize, + @JsonProperty("students") List students) { +>>>>>>> origin/Ui-update this.teamName = teamName; this.students = students != null ? new ArrayList<>(students) : new ArrayList<>(); this.teamSize = teamSize; @@ -85,6 +90,10 @@ public boolean equals(Object other) { JsonAdaptedTutorialTeam otherTutorialTeam = (JsonAdaptedTutorialTeam) other; return teamName.equals(otherTutorialTeam.teamName) && students.equals(otherTutorialTeam.students) +<<<<<<< HEAD && teamSize == otherTutorialTeam.teamSize; +======= + && teamSize == otherTutorialTeam.teamSize; +>>>>>>> origin/Ui-update } } diff --git a/src/main/java/seedu/address/ui/ModuleCard.java b/src/main/java/seedu/address/ui/ModuleCard.java index 8de5e65c77f..5a8091da4aa 100644 --- a/src/main/java/seedu/address/ui/ModuleCard.java +++ b/src/main/java/seedu/address/ui/ModuleCard.java @@ -48,7 +48,7 @@ public ModuleCard(ModuleCode moduleCode) { * to enhance visual appearance. */ public void updateImage() { - Image moduleImage = new Image("images/group4.png"); + Image moduleImage = new Image("images/damith3.png"); circle.setStroke(Color.ROSYBROWN); circle.setFill(new ImagePattern(moduleImage)); circle.setEffect(new DropShadow(+10d, 0d, +2d, Color.ROSYBROWN)); diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index 635a4170125..ad7eb6ebdbc 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -85,7 +85,7 @@ public void updateImage() { String path = "images/" + person.getName().toString() + ".png"; File file = new File(path); if (!file.exists()) { - Image defaultImage = new Image("images/student.png"); + Image defaultImage = new Image("images/damith1.png"); circle.setStroke(Color.ROSYBROWN); circle.setFill(new ImagePattern(defaultImage)); circle.setEffect(new DropShadow(+10d, 0d, +2d, Color.ROSYBROWN)); diff --git a/src/main/java/seedu/address/ui/TutorialClassCard.java b/src/main/java/seedu/address/ui/TutorialClassCard.java index 1e106c80415..e98830542d5 100644 --- a/src/main/java/seedu/address/ui/TutorialClassCard.java +++ b/src/main/java/seedu/address/ui/TutorialClassCard.java @@ -43,7 +43,7 @@ public TutorialClassCard(TutorialClass tutorialClass) { * to the circle for enhanced visual appearance. */ public void updateImage() { - Image moduleImage = new Image("images/class.png"); + Image moduleImage = new Image("images/damith2.png"); circle.setStroke(Color.ROSYBROWN); circle.setFill(new ImagePattern(moduleImage)); circle.setEffect(new DropShadow(+10d, 0d, +2d, Color.ROSYBROWN)); diff --git a/src/main/resources/images/damith1.png b/src/main/resources/images/damith1.png new file mode 100644 index 00000000000..a11d24c1d15 Binary files /dev/null and b/src/main/resources/images/damith1.png differ diff --git a/src/main/resources/images/damith2.png b/src/main/resources/images/damith2.png new file mode 100644 index 00000000000..7860d408cd9 Binary files /dev/null and b/src/main/resources/images/damith2.png differ diff --git a/src/main/resources/images/damith3.png b/src/main/resources/images/damith3.png new file mode 100644 index 00000000000..8705648bdb1 Binary files /dev/null and b/src/main/resources/images/damith3.png differ diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml index d6408825f08..052be961709 100644 --- a/src/main/resources/view/MainWindow.fxml +++ b/src/main/resources/view/MainWindow.fxml @@ -1,5 +1,4 @@ - @@ -10,11 +9,11 @@ - - + + + title="Address App" minWidth="0" minHeight="0" onCloseRequest="#handleExit"> @@ -24,58 +23,70 @@ - - - - - - - - - - - -
- - - - + + + + + + + + + + + +
+ + + + + - - + - + + + + + - - + - + + + + + - + - - -
- - - - - - - + +
+
+
+ + + + + + + +
diff --git a/src/test/java/seedu/address/logic/commands/AddStudentToClassCommandIntegrationTest.java b/src/test/java/seedu/address/logic/commands/AddStudentToClassCommandIntegrationTest.java index 6ad3bc2d907..39507dbcdf3 100644 --- a/src/test/java/seedu/address/logic/commands/AddStudentToClassCommandIntegrationTest.java +++ b/src/test/java/seedu/address/logic/commands/AddStudentToClassCommandIntegrationTest.java @@ -26,7 +26,7 @@ /** * Contains integration tests (interaction with the Model) for - * {@code AddCommand}. + * {@code AddStudentToClassCommand}. */ public class AddStudentToClassCommandIntegrationTest { diff --git a/src/test/java/seedu/address/logic/commands/AddStudentToClassCommandTest.java b/src/test/java/seedu/address/logic/commands/AddStudentToClassCommandTest.java index 99b26f87727..813f091a6b3 100644 --- a/src/test/java/seedu/address/logic/commands/AddStudentToClassCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddStudentToClassCommandTest.java @@ -38,7 +38,7 @@ /** * Contains integration tests (interaction with the Model) and unit tests for - * {@code DeleteCommand}. + * {@code AddStudentToClassCommand}. */ public class AddStudentToClassCommandTest { diff --git a/src/test/java/seedu/address/logic/commands/AddTeamCommandIntegrationTest.java b/src/test/java/seedu/address/logic/commands/AddTeamCommandIntegrationTest.java new file mode 100644 index 00000000000..8edf10cf5b0 --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/AddTeamCommandIntegrationTest.java @@ -0,0 +1,85 @@ +package seedu.address.logic.commands; + +import static seedu.address.logic.commands.CommandTestUtil.VALID_MODULE_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_MODULE_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TEAM_NAME_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TEAM_SIZE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TUTORIAL_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TUTORIAL_BOB; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import seedu.address.logic.messages.ModuleMessages; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; +import seedu.address.model.module.ModuleCode; +import seedu.address.model.module.TutorialClass; + +/** + * Contains integration tests (interaction with the Model) for + * {@code AddTeamCommand}. + */ +public class AddTeamCommandIntegrationTest { + + private Model model; + private ModuleCode testModule; + private TutorialClass testTutorial; + + @BeforeEach + public void setUp() { + model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + ModuleCode newModule = new ModuleCode(VALID_MODULE_AMY); + model.addModule(newModule); + this.testModule = newModule; + TutorialClass newTutorialClass = new TutorialClass(VALID_TUTORIAL_AMY); + newModule.addTutorialClass(newTutorialClass); + this.testTutorial = newTutorialClass; + } + + @Test + public void execute_addTeamWithNoSize_success() { + Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); + + assertCommandSuccess(new AddTeamCommand(testModule, testTutorial, VALID_TEAM_NAME_AMY), + model, + String.format(AddTeamCommand.MESSAGE_ADD_TEAM_SUCCESS_WITHOUT_SIZE, VALID_TEAM_NAME_AMY, + testModule, testTutorial), + expectedModel); + } + + @Test + public void execute_addTeamWithSize_success() { + Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); + + assertCommandSuccess(new AddTeamCommand(testModule, testTutorial, VALID_TEAM_NAME_AMY, VALID_TEAM_SIZE), + model, + String.format(AddTeamCommand.MESSAGE_ADD_TEAM_SUCCESS_WITH_SIZE, VALID_TEAM_NAME_AMY, VALID_TEAM_SIZE, + testModule, testTutorial), + expectedModel); + } + + @Test + public void execute_addTeamToInvalidModule_throwsCommandException() { + Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); + + ModuleCode invalidModule = new ModuleCode(VALID_MODULE_BOB); + assertCommandFailure(new AddTeamCommand(invalidModule, testTutorial, VALID_TEAM_NAME_AMY), + expectedModel, + String.format(ModuleMessages.MESSAGE_MODULE_NOT_FOUND, invalidModule)); + } + + @Test + public void execute_addTeamToInvalidTutorial_throwsCommandException() { + Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); + + TutorialClass invalidTutorial = new TutorialClass(VALID_TUTORIAL_BOB); + assertCommandFailure(new AddTeamCommand(testModule, invalidTutorial, VALID_TEAM_NAME_AMY), + expectedModel, + String.format(ModuleMessages.MESSAGE_TUTORIAL_DOES_NOT_BELONG_TO_MODULE, invalidTutorial, testModule)); + } +} diff --git a/src/test/java/seedu/address/logic/commands/AddTeamCommandTest.java b/src/test/java/seedu/address/logic/commands/AddTeamCommandTest.java new file mode 100644 index 00000000000..35c2ac09086 --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/AddTeamCommandTest.java @@ -0,0 +1,94 @@ +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.AddTeamCommand.MESSAGE_ADD_TEAM_SUCCESS_WITHOUT_SIZE; +import static seedu.address.logic.commands.AddTeamCommand.MESSAGE_ADD_TEAM_SUCCESS_WITH_SIZE; +import static seedu.address.logic.commands.AddTeamCommand.MESSAGE_DUPLICATE_TEAM; +import static seedu.address.logic.commands.CommandTestUtil.VALID_MODULE_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TEAM_NAME_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TEAM_NAME_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TEAM_SIZE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TUTORIAL_AMY; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; +import seedu.address.model.module.ModuleCode; +import seedu.address.model.module.TutorialClass; +import seedu.address.model.module.TutorialTeam; + +/** + * Contains integration tests (interaction with the Model) and unit tests for + * {@code AddTeamCommand}. + */ +public class AddTeamCommandTest { + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + private TutorialClass tutorialClass; + + @BeforeEach + public void setUp() { + model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + ModuleCode module = new ModuleCode(VALID_MODULE_AMY); + model.addModule(module); + TutorialClass tutorialClass = new TutorialClass(VALID_TUTORIAL_AMY); + module.addTutorialClass(tutorialClass); + this.tutorialClass = tutorialClass; + } + + @Test + public void execute_addTeamWithSizesuccess() { + assertCommandSuccess(new AddTeamCommand(new ModuleCode(VALID_MODULE_AMY), + new TutorialClass(VALID_TUTORIAL_AMY), VALID_TEAM_NAME_AMY, VALID_TEAM_SIZE), model, + String.format(MESSAGE_ADD_TEAM_SUCCESS_WITH_SIZE, VALID_TEAM_NAME_AMY, VALID_TEAM_SIZE, + VALID_MODULE_AMY, VALID_TUTORIAL_AMY), + model); + } + + @Test + public void execute_addTeamWithoutSizesuccess() { + + assertCommandSuccess(new AddTeamCommand(new ModuleCode(VALID_MODULE_AMY), + new TutorialClass(VALID_TUTORIAL_AMY), VALID_TEAM_NAME_AMY), model, + String.format(MESSAGE_ADD_TEAM_SUCCESS_WITHOUT_SIZE, VALID_TEAM_NAME_AMY, VALID_MODULE_AMY, + VALID_TUTORIAL_AMY), + model); + } + + @Test + public void execute_duplicateTeam_fail() { + TutorialTeam team = new TutorialTeam(VALID_TEAM_NAME_AMY, VALID_TEAM_SIZE); + tutorialClass.addTeam(team); + + assertCommandFailure(new AddTeamCommand(new ModuleCode(VALID_MODULE_AMY), + new TutorialClass(VALID_TUTORIAL_AMY), VALID_TEAM_NAME_AMY), model, + String.format(MESSAGE_DUPLICATE_TEAM, VALID_TEAM_NAME_AMY, VALID_MODULE_AMY, VALID_TUTORIAL_AMY)); + } + + @Test + public void equals() { + final AddTeamCommand standardCommand = new AddTeamCommand(new ModuleCode(VALID_MODULE_AMY), + new TutorialClass(VALID_TUTORIAL_AMY), VALID_TEAM_NAME_AMY, VALID_TEAM_SIZE); + + // same values -> returns true + AddTeamCommand commandWithSameValues = new AddTeamCommand(new ModuleCode(VALID_MODULE_AMY), + new TutorialClass(VALID_TUTORIAL_AMY), VALID_TEAM_NAME_AMY, VALID_TEAM_SIZE); + assertTrue(standardCommand.equals(commandWithSameValues)); + + // same object -> returns true + assertTrue(standardCommand.equals(standardCommand)); + + // null -> returns false + assertFalse(standardCommand.equals(null)); + + // different team name -> returns false + assertFalse(standardCommand.equals(new AddTeamCommand(new ModuleCode(VALID_MODULE_AMY), + new TutorialClass(VALID_TUTORIAL_AMY), VALID_TEAM_NAME_BOB, VALID_TEAM_SIZE))); + } +} diff --git a/src/test/java/seedu/address/logic/commands/AllocateStudentToTeamCommandTest.java b/src/test/java/seedu/address/logic/commands/AllocateStudentToTeamCommandTest.java index 550481701f1..3fa44f901dc 100644 --- a/src/test/java/seedu/address/logic/commands/AllocateStudentToTeamCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AllocateStudentToTeamCommandTest.java @@ -1,2 +1,4 @@ -package seedu.address.logic.commands;public class AllocateStudentToTeamCommandTest { +package seedu.address.logic.commands; + +public class AllocateStudentToTeamCommandTest { } diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index 1113a6212ae..5599bf61c76 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -8,6 +8,7 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; import static seedu.address.logic.parser.CliSyntax.PREFIX_STUDENTID; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TEAM_SIZE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TUTORIALCLASS; import static seedu.address.testutil.Assert.assertThrows; @@ -61,6 +62,15 @@ public class CommandTestUtil { public static final String INVALID_PERSON_EMAIL = "test@example.com"; public static final String INVALID_PERSON_STUDENT_ID = "A2222222A"; + // Team related constants + public static final String VALID_TEAM_NAME_AMY = "Team 1"; + public static final String VALID_TEAM_NAME_BOB = "Team 2"; + public static final int VALID_TEAM_SIZE = 5; + public static final String TEAM_NAME_DESC_AMY = " " + PREFIX_NAME + VALID_TEAM_NAME_AMY; + public static final String TEAM_SIZE_DESC = " " + PREFIX_TEAM_SIZE + VALID_TEAM_SIZE; + public static final String INVALID_TEAM_NAME = "Team 1!"; + public static final int INVALID_TEAM_SIZE = -1; + // '&' not allowed in names public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "James&"; diff --git a/src/test/java/seedu/address/logic/parser/AddTeamCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddTeamCommandParserTest.java new file mode 100644 index 00000000000..201c1608e88 --- /dev/null +++ b/src/test/java/seedu/address/logic/parser/AddTeamCommandParserTest.java @@ -0,0 +1,59 @@ +package seedu.address.logic.parser; + +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.commands.CommandTestUtil.MODULE_DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.TEAM_NAME_DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.TEAM_SIZE_DESC; +import static seedu.address.logic.commands.CommandTestUtil.TUTORIAL_DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_MODULE_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TEAM_NAME_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TEAM_SIZE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TUTORIAL_AMY; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; + +import org.junit.jupiter.api.Test; + +import seedu.address.logic.commands.AddTeamCommand; +import seedu.address.model.module.ModuleCode; +import seedu.address.model.module.TutorialClass; +import seedu.address.model.module.TutorialTeam; + +/** + * Contains unit tests for AddTeamCommandParser. + */ +public class AddTeamCommandParserTest { + private final AddTeamCommandParser parser = new AddTeamCommandParser(); + + @Test + public void parse_teamWithNoSize_success() { + String userInput = MODULE_DESC_AMY + TUTORIAL_DESC_AMY + TEAM_NAME_DESC_AMY; + AddTeamCommand expectedCommand = new AddTeamCommand(new ModuleCode(VALID_MODULE_AMY), + new TutorialClass(VALID_TUTORIAL_AMY), VALID_TEAM_NAME_AMY); + assertParseSuccess(parser, userInput, expectedCommand); + } + + @Test + public void parse_teamWithSize_success() { + String userInput = MODULE_DESC_AMY + TUTORIAL_DESC_AMY + TEAM_NAME_DESC_AMY + TEAM_SIZE_DESC; + AddTeamCommand expectedCommand = new AddTeamCommand(new ModuleCode(VALID_MODULE_AMY), + new TutorialClass(VALID_TUTORIAL_AMY), VALID_TEAM_NAME_AMY, VALID_TEAM_SIZE); + assertParseSuccess(parser, userInput, expectedCommand); + } + + @Test + public void parse_teamWithInvalidName_failure() { + String expectedMessage = TutorialTeam.MESSAGE_NAME_CONSTRAINTS; + String userInput = MODULE_DESC_AMY + TUTORIAL_DESC_AMY + " " + PREFIX_NAME + " "; + assertParseFailure(parser, userInput, expectedMessage); + } + + @Test + public void parse_teamWithNoName_failure() { + String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddTeamCommand.MESSAGE_USAGE); + String userInput = MODULE_DESC_AMY + TUTORIAL_DESC_AMY; + assertParseFailure(parser, userInput, expectedMessage); + } + +} diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index adbb70cc3f7..53cea1c0c0b 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -160,7 +160,7 @@ public void parseCommand_addStudentToClass() throws Exception { public void parseCommand_unrecognisedInput_throwsParseException() { assertThrows(ParseException.class, String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE), ( - ) -> parser.parseCommand("")); + ) -> parser.parseCommand("")); } @Test diff --git a/src/test/java/seedu/address/model/module/TutorialTeamTest.java b/src/test/java/seedu/address/model/module/TutorialTeamTest.java new file mode 100644 index 00000000000..17fd04baa38 --- /dev/null +++ b/src/test/java/seedu/address/model/module/TutorialTeamTest.java @@ -0,0 +1,106 @@ +package seedu.address.model.module; + +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.model.module.TutorialTeam.isValidSize; +import static seedu.address.model.module.TutorialTeam.isValidTeamName; +import static seedu.address.testutil.Assert.assertThrows; + +import org.junit.jupiter.api.Test; + +/** + * Contains unit tests for the TutorialTeam class. + */ +public class TutorialTeamTest { + + public static final String VALID_TEAM_NAME_1 = "Team 1"; + public static final String VALID_TEAM_NAME_2 = "Team 2"; + public static final String INVALID_TEAM_NAME = "Team 3!!!!"; + public static final int VALID_TEAM_SIZE = 5; + public static final int INVALID_TEAM_SIZE = -1; + + + /** + * Test cases to check the equality of two TutorialTeam objects + */ + @Test + public void equals() { + TutorialTeam team = new TutorialTeam(VALID_TEAM_NAME_1, VALID_TEAM_SIZE); + + // same object -> returns true + assertTrue(team.equals(team)); + + // same values -> returns true + TutorialTeam teamCopy = new TutorialTeam(VALID_TEAM_NAME_1, VALID_TEAM_SIZE); + assertTrue(team.equals(teamCopy)); + + // different types -> returns false + assertFalse(team.equals(1)); + + // null -> returns false + assertFalse(team.equals(null)); + + // different remark -> returns false + TutorialTeam differentTeam = new TutorialTeam(VALID_TEAM_NAME_2, VALID_TEAM_SIZE); + assertFalse(team.equals(differentTeam)); + } + + /** + * Tests isValidTeamName with a valid team name. + */ + @Test + void isValidModuleCode_success() { + assertTrue(isValidTeamName(VALID_TEAM_NAME_1)); + } + + /** + * Tests isValidTeamName with an invalid team name. + */ + @Test + void isValidTeamName_failure() { + assertFalse(isValidTeamName(INVALID_TEAM_NAME)); + } + + /** + * Tests isValidSize with a valid team size. + */ + @Test + void isValidSize_success() { + assertTrue(isValidSize(VALID_TEAM_SIZE)); + } + + /** + * Tests isValidSize with an invalid team size. + */ + @Test + void isValidSize_failure() { + assertFalse(isValidSize(INVALID_TEAM_SIZE)); + } + + /** + * Tests the constructor of TutorialTeam with a valid team name and team size. + */ + @Test + void constructor_validTeamNameAndSize_success() { + TutorialTeam team = new TutorialTeam(VALID_TEAM_NAME_1, VALID_TEAM_SIZE); + assertEquals(VALID_TEAM_NAME_1, team.getTeamName()); + assertEquals(VALID_TEAM_SIZE, team.getTeamSize()); + } + + /** + * Tests the constructor of TutorialTeam with an invalid team name. + */ + @Test + void constructor_invalidTeamName_failure() { + assertThrows(IllegalArgumentException.class, () -> new TutorialTeam(INVALID_TEAM_NAME, VALID_TEAM_SIZE)); + } + + /** + * Tests the constructor of TutorialTeam with an invalid team size. + */ + @Test + void constructor_invalidTeamSize_failure() { + assertThrows(IllegalArgumentException.class, () -> new TutorialTeam(VALID_TEAM_NAME_1, INVALID_TEAM_SIZE)); + } +} diff --git a/src/test/java/seedu/address/storage/JsonAdaptedTutorialClassTest.java b/src/test/java/seedu/address/storage/JsonAdaptedTutorialClassTest.java index 950583ef283..9f5680e1ad6 100644 --- a/src/test/java/seedu/address/storage/JsonAdaptedTutorialClassTest.java +++ b/src/test/java/seedu/address/storage/JsonAdaptedTutorialClassTest.java @@ -21,6 +21,8 @@ class JsonAdaptedTutorialClassTest { Arrays.asList(new PersonBuilder().build(), new PersonBuilder().build())).stream() .map(JsonAdaptedPerson::new) .collect(Collectors.toList()); + private static final List VALID_TEAMS_LIST = new ArrayList<>( + Arrays.asList(new JsonAdaptedTutorialTeam("Team 1", 1, VALID_STUDENTS_LIST))); @Test void toModelType_success() throws Exception { @@ -32,7 +34,7 @@ void toModelType_success() throws Exception { @Test void toModelType_invalidTutorialName_throwsIllegalValueException() { JsonAdaptedTutorialClass jsonTutorialClass = new JsonAdaptedTutorialClass(INVALID_TUTORIAL_NAME, - VALID_STUDENTS_LIST); + VALID_TEAMS_LIST, VALID_STUDENTS_LIST); String expectedMessage = TutorialClass.MESSAGE_CONSTRAINTS; assertThrows(IllegalArgumentException.class, expectedMessage, jsonTutorialClass::toModelType); } diff --git a/src/test/java/seedu/address/storage/JsonAdaptedTutorialTeamTest.java b/src/test/java/seedu/address/storage/JsonAdaptedTutorialTeamTest.java new file mode 100644 index 00000000000..c5a642c91e9 --- /dev/null +++ b/src/test/java/seedu/address/storage/JsonAdaptedTutorialTeamTest.java @@ -0,0 +1,50 @@ +package seedu.address.storage; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static seedu.address.testutil.Assert.assertThrows; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.junit.jupiter.api.Test; + +import seedu.address.model.module.TutorialTeam; +import seedu.address.testutil.PersonBuilder; + +class JsonAdaptedTutorialTeamTest { + + private static final String VALID_TEAM_NAME = "Team 1"; + private static final String INVALID_TEAM_NAME = ""; + private static final int VALID_TEAM_SIZE = 10; + private static final int INVALID_TEAM_SIZE = -1; + private static final List VALID_STUDENTS_LIST = new ArrayList<>( + Arrays.asList(new PersonBuilder().build(), new PersonBuilder().build())).stream() + .map(JsonAdaptedPerson::new) + .collect(Collectors.toList()); + + @Test + void toModelType_success() throws Exception { + TutorialTeam tutorialTeam = new TutorialTeam(VALID_TEAM_NAME, VALID_TEAM_SIZE); + JsonAdaptedTutorialTeam jsonTutorialTeam = new JsonAdaptedTutorialTeam(tutorialTeam); + assertEquals(tutorialTeam, jsonTutorialTeam.toModelType()); + } + + @Test + void toModelType_invalidTeamName_throwsIllegalValueException() { + JsonAdaptedTutorialTeam jsonTutorialTeam = new JsonAdaptedTutorialTeam(INVALID_TEAM_NAME, VALID_TEAM_SIZE, + VALID_STUDENTS_LIST); + String expectedMessage = TutorialTeam.MESSAGE_NAME_CONSTRAINTS; + assertThrows(IllegalArgumentException.class, expectedMessage, jsonTutorialTeam::toModelType); + } + + @Test + void toModelType_invalidTeamSize_throwsIllegalValueException() { + JsonAdaptedTutorialTeam jsonTutorialTeam = new JsonAdaptedTutorialTeam(VALID_TEAM_NAME, INVALID_TEAM_SIZE, + VALID_STUDENTS_LIST); + String expectedMessage = TutorialTeam.MESSAGE_SIZE_CONSTRAINTS; + assertThrows(IllegalArgumentException.class, expectedMessage, jsonTutorialTeam::toModelType); + } + +}