Skip to content

Commit

Permalink
Update test cases based on new tutorial team name class
Browse files Browse the repository at this point in the history
  • Loading branch information
qinxutan committed Mar 28, 2024
1 parent 0f85b3d commit 88860a0
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,12 @@ public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
ModuleTutorialPair moduleAndTutorialClass = getModuleAndTutorialClass(model);
ModuleCode module = moduleAndTutorialClass.getModule();
TutorialClass tutorialClass = moduleAndTutorialClass.getTutorialClass();
TutorialClass existingTutorialClass = moduleAndTutorialClass.getTutorialClass();

TutorialTeam existingTeam = tutorialClass.findTeamByNameAndSize(teamName, teamSize);

if (existingTeam != null) {
TutorialTeam newTeam = new TutorialTeam(teamName, teamSize);
if (existingTutorialClass.hasTeam(newTeam)) {
throw new CommandException(String.format(MESSAGE_DUPLICATE_TEAM, teamName, module, tutorialClass));
} else {
TutorialTeam newTeam = new TutorialTeam(teamName, teamSize);
tutorialClass.addTeam(newTeam);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public boolean equals(Object other) {
}

DeleteTeamCommand e = (DeleteTeamCommand) other;
return module.equals(e.module) && tutorialClass.equals(e.tutorialClass) && team.equals(e.team);
return module.equals(e.module) && tutorialClass.equals(e.tutorialClass)
&& team.getTeamName().equalsIgnoreCase(e.team.getTeamName());
}
}
13 changes: 11 additions & 2 deletions src/main/java/seedu/address/logic/commands/ViewTeamCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public class ViewTeamCommand extends Command {
public static final String COMMAND_WORD = "/view_teams";
public static final String MESSAGE_EMPTY = "No teams available in %1$s %2$s";
public static final String MESSAGE_NO_TUTORIAL_CLASSES = "No tutorial classes available in %1$s";
private static final String MESSAGE_NO_MODULE = "Module not available";
public static final String MESSAGE_TEAM_NOT_FOUND = "Team with %1$s %2$s not found!";
private static final String MESSAGE_NO_MODULE = "Module not available";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": View teams of the tutorial class "
+ "based on their name or index. \n"
+ "Parameters: [name/NAME | index/TEAM_INDEX]"
Expand All @@ -44,7 +44,16 @@ public class ViewTeamCommand extends Command {
private final String predicateValue;
private final ModuleCode moduleCode;
private final TutorialClass tutorialClass;

/**
* Constructs a ViewTeamCommand object with the specified predicate type, predicate value, module code,
* and tutorial class.
*
* @param predicateType The type of predicate used for filtering teams (either PREFIX_NAME or PREFIX_INDEX).
* @param predicateValue The value associated with the predicate (either team name or team index).
* @param moduleCode The code of the module to which the tutorial class belongs.
* @param tutorialClass The tutorial class to filter teams from.
* @throws NullPointerException if any of the arguments are null.
*/
public ViewTeamCommand(Prefix predicateType, String predicateValue, ModuleCode moduleCode,
TutorialClass tutorialClass) {
requireAllNonNull(predicateType, predicateValue, moduleCode, tutorialClass);
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ public ObservableList<TutorialClass> getTutorialList() {
return FXCollections.observableList(tutorialClasses);
}
@Override
public ObservableList<TutorialTeam> getTeamList() { return FXCollections.observableList(tutorialTeams); }
public ObservableList<TutorialTeam> getTeamList() {
return FXCollections.observableList(tutorialTeams);
}
@Override
public boolean equals(Object other) {
if (other == this) {
Expand All @@ -307,10 +309,6 @@ public boolean equals(Object other) {
public int hashCode() {
return persons.hashCode();
}
public boolean hasTeam(TutorialTeam tutorialTeam) {
requireNonNull(tutorialTeam);
return tutorialTeams.contains(tutorialTeam);
}

/**
* Returns true if a person with the same identity as {@code person} exists in
Expand Down
21 changes: 9 additions & 12 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import seedu.address.model.module.ModuleCode;
import seedu.address.model.module.TutorialClass;
import seedu.address.model.module.TutorialTeam;
import seedu.address.model.module.TutorialTeamName;
import seedu.address.model.person.Email;
import seedu.address.model.person.Person;
import seedu.address.model.person.StudentId;
Expand Down Expand Up @@ -251,17 +250,15 @@ public boolean equals(Object other) {
&& filteredPersons.equals(otherModelManager.filteredPersons);
}

public boolean hasTeamWithStudentId(TutorialTeamName teamName) {
requireNonNull(teamName);
requireNonNull(teamName);
for (TutorialTeam team : filteredTeams) {
if (team.getTeamName().equalsIgnoreCase(teamName.toString())) {
return true;
}
}
return false;
}

/**
* Searches for a tutorial team within the specified tutorial class and module using the given predicate.
*
* @param predicate The predicate used to filter teams.
* @param tutorialClass The tutorial class to search within.
* @param moduleCode The code of the module containing the tutorial class.
* @return The tutorial team that matches the predicate, or {@code null} if no team matches the predicate.
* @throws NullPointerException if the predicate is null.
*/
public TutorialTeam searchTeamByPredicate(Predicate<TutorialTeam> predicate, TutorialClass tutorialClass,
ModuleCode moduleCode) {
requireNonNull(predicate);
Expand Down
17 changes: 0 additions & 17 deletions src/main/java/seedu/address/model/module/TutorialClass.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package seedu.address.model.module;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;

Expand Down Expand Up @@ -201,20 +200,4 @@ public boolean equals(Object other) {
public int hashCode() {
return tutorialName.hashCode();
}

/**
* Finds a team in the tutorial class with the specified name and size.
* Returns the team if found, otherwise returns null.
* @param teamName The name of the team to find.
* @param teamSize The size of the team to find.
* @return The team with the specified name and size, or null if not found.
*/
public TutorialTeam findTeamByNameAndSize(String teamName, int teamSize) {
for (TutorialTeam team : teams) {
if (team.getTeamName().equalsIgnoreCase(teamName) && team.getTeamSize() == teamSize) {
return team;
}
}
return null;
}
}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/module/TutorialTeam.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public boolean equals(Object other) {
}

TutorialTeam otherTutorialTeam = (TutorialTeam) other;
return teamName.equals(otherTutorialTeam.teamName) && teamSize == otherTutorialTeam.teamSize;
return teamName.toString().equalsIgnoreCase(otherTutorialTeam.teamName.toString());
}

@Override
Expand Down
19 changes: 14 additions & 5 deletions src/test/java/seedu/address/logic/commands/AddTeamCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
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.Assert.assertThrows;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
Expand Down Expand Up @@ -66,9 +66,18 @@ 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));
// Create a new model and add the module and tutorial class with the existing team
Model model = new ModelManager();
ModuleCode module = new ModuleCode(VALID_MODULE_AMY);
TutorialClass tutorialClass = new TutorialClass(VALID_TUTORIAL_AMY);
module.addTutorialClass(tutorialClass);
tutorialClass.addTeam(team);

// Create and execute the AddTeamCommand
AddTeamCommand addTeamCommand = new AddTeamCommand(new ModuleCode(VALID_MODULE_AMY),
new TutorialClass(VALID_TUTORIAL_AMY), VALID_TEAM_NAME_AMY);

assertThrows(CommandException.class, () -> addTeamCommand.execute(model));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.messages.ModuleMessages;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
Expand Down Expand Up @@ -44,14 +45,13 @@ public void setUp() {
}

@Test
public void execute_deleteTeam_success() {
public void execute_deleteTeam_success() throws CommandException {
Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());

assertCommandSuccess(new DeleteTeamCommand(testModule, testTutorial, VALID_TEAM_NAME_AMY),
model,
String.format(DeleteTeamCommand.MESSAGE_DELETE_TEAM_SUCCESS, VALID_TEAM_NAME_AMY,
testModule, testTutorial),
expectedModel);
model,
String.format(DeleteTeamCommand.MESSAGE_DELETE_TEAM_SUCCESS, VALID_TEAM_NAME_AMY,
testModule, testTutorial),
expectedModel);
}

@Test
Expand Down
27 changes: 17 additions & 10 deletions src/test/java/seedu/address/logic/commands/ViewTeamCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package seedu.address.logic.commands;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;

import java.util.HashSet;

import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.module.ModuleCode;
import seedu.address.model.module.ModuleCode;
import seedu.address.model.module.TutorialClass;
import seedu.address.model.module.TutorialTeam;
import seedu.address.model.module.TutorialTeamName;
Expand All @@ -14,11 +20,6 @@
import seedu.address.model.person.Person;
import seedu.address.model.person.StudentId;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import java.util.HashSet;

public class ViewTeamCommandTest {

@Test
Expand All @@ -31,8 +32,10 @@ public void execute_validInput_teamFound() throws Exception {

TutorialTeamName teamName = new TutorialTeamName("Team A");
TutorialTeam team = new TutorialTeam(teamName.fullName, 2);
Person john = new Person(new Name("John"), new Email("[email protected]"), new StudentId("A1234561Z"), new HashSet<>());
Person alice = new Person(new Name("Alice"), new Email("[email protected]"), new StudentId("A1234562Z"), new HashSet<>());
Person john = new Person(new Name("John"), new Email("[email protected]"),
new StudentId("A1234561Z"), new HashSet<>());
Person alice = new Person(new Name("Alice"), new Email("[email protected]"),
new StudentId("A1234562Z"), new HashSet<>());
team.addStudent(john);
team.addStudent(alice);
tutorialClass.addTeam(team);
Expand All @@ -54,8 +57,12 @@ public void execute_invalidTeamName_exceptionThrown() {

TutorialTeamName teamName = new TutorialTeamName("Team A");
TutorialTeam team = new TutorialTeam(teamName.fullName, 2);
Person john = new Person(new Name("John"), new Email("[email protected]"), new StudentId("A1234561Z"), new HashSet<>());
Person alice = new Person(new Name("Alice"), new Email("[email protected]"), new StudentId("A1234562Z"), new HashSet<>());
Person john = new Person(new Name("John"), new Email("[email protected]"),
new StudentId("A1234561Z"), new HashSet<>());
Person alice = new Person(new Name("Alice"), new Email("[email protected]"),
new StudentId("A1234562Z"), new HashSet<>());
team.addStudent(john);
team.addStudent(alice);
tutorialClass.addTeam(team);

ViewTeamCommand command = new ViewTeamCommand(PREFIX_NAME, "Team B", moduleCode, tutorialClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class DeleteTeamCommandParserTest {
public void parse_deleteTeam_success() {
String userInput = MODULE_DESC_AMY + TUTORIAL_DESC_AMY + TEAM_NAME_DESC_AMY;
DeleteTeamCommand expectedCommand = new DeleteTeamCommand(new ModuleCode(VALID_MODULE_AMY),
new TutorialClass(VALID_TUTORIAL_AMY), VALID_TEAM_NAME_AMY);
new TutorialClass(VALID_TUTORIAL_AMY), VALID_TEAM_NAME_AMY);
assertParseSuccess(parser, userInput, expectedCommand);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package seedu.address.logic.parser;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static seedu.address.logic.parser.CliSyntax.PREFIX_INDEX;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;

import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.ViewTeamCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.module.ModuleCode;
import seedu.address.model.module.TutorialClass;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static seedu.address.logic.parser.CliSyntax.PREFIX_INDEX;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;

public class ViewTeamCommandParserTest {

private final ViewTeamCommandParser parser = new ViewTeamCommandParser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public void equals() {
// null -> returns false
assertFalse(team.equals(null));

// different team name -> returns false
TutorialTeam differentTeamSameSize = new TutorialTeam(VALID_TEAM_NAME_2, VALID_TEAM_SIZE);
assertFalse(team.equals(differentTeamSameSize));


// different remark -> returns false
TutorialTeam differentTeam = new TutorialTeam(VALID_TEAM_NAME_2, VALID_TEAM_SIZE);
assertFalse(team.equals(differentTeam));
Expand Down

0 comments on commit 88860a0

Please sign in to comment.