Skip to content

Commit

Permalink
Merge branch 'master' into fix-bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
qinxutan authored Apr 10, 2024
2 parents ae438b1 + 7bc9b98 commit 8b6f9c7
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 119 deletions.
4 changes: 1 addition & 3 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ confidence to make full use of TAHelper's features.
5. Launching TAHelper
- Type `java -jar tahelper.jar` command and hit Enter to run TAHelper.<br>
- It should look something like this (in this case my jar file is in a folder called tahelper):
- ![cmd](images/cmdwinguide2.png)


- ![cmd](images/cmdwinguide2.png)
- A GUI similar to the below should appear in a few seconds.<br>
- ![Ui](images/Ui.png) (to update!!).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
public class AddStudentCommandTest {

@Test
public void constructor_nullPerson_throwsNullPointerException() {
public void execute_addNullPerson_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> new AddStudentCommand(null));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL;
import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_MODULE_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_STUDENT_ID;
import static seedu.address.logic.commands.CommandTestUtil.VALID_STUDENT_ID_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TEAM_NAME;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TEAM_NAME_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TEAM_NAME_NEW;
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.ALICE;
import static seedu.address.testutil.TypicalPersons.AMY;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

import org.junit.jupiter.api.BeforeEach;
Expand All @@ -30,6 +25,7 @@
import seedu.address.logic.messages.PersonMessages;
import seedu.address.logic.messages.TutorialClassMessages;
import seedu.address.logic.messages.TutorialTeamMessages;
import seedu.address.model.AddressBook;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
Expand All @@ -39,70 +35,64 @@
import seedu.address.model.person.Email;
import seedu.address.model.person.Person;
import seedu.address.model.person.StudentId;
import seedu.address.testutil.PersonBuilder;
import seedu.address.testutil.ModuleBuilder;

public class AllocateStudentToTeamCommandTest {
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
private TutorialClass tutorialClass;
private Person validPerson;
private Person validOtherPerson;
private ModuleCode newModule;
private TutorialTeam newTeam;
private TutorialTeam tutTeam;

@BeforeEach
public void setUp() {
validPerson = new PersonBuilder(AMY).build();
validOtherPerson = new PersonBuilder(ALICE)
.withStudentId(VALID_STUDENT_ID_BOB).withEmail(VALID_EMAIL_BOB).build();
newModule = new ModuleCode(VALID_MODULE_AMY);
// create a new test module and add it to model
newModule = new ModuleBuilder().build();
model.addModule(newModule);
model.addPerson(validPerson);
model.addPerson(validOtherPerson);
TutorialClass newTutorialClass = new TutorialClass(VALID_TUTORIAL_AMY);
newModule.addTutorialClass(newTutorialClass);
tutorialClass = newTutorialClass;
newTeam = new TutorialTeam(VALID_TEAM_NAME, 1);
tutTeam = new TutorialTeam(VALID_TEAM_NAME_BOB, 3);
tutorialClass.addTeam(tutTeam);
tutorialClass.addTeam(newTeam);
int newTeamSizeTest = 1;
int tutTeamSizeTest = 3;
newTeam = new TutorialTeam(VALID_TEAM_NAME, newTeamSizeTest);
tutTeam = new TutorialTeam(VALID_TEAM_NAME_BOB, tutTeamSizeTest);
newModule.getTutorialClasses().get(0).addTeam(tutTeam);
newModule.getTutorialClasses().get(0).addTeam(newTeam);
}

@Test
public void invalidAllocationToTeam_indexNotInSystem_failure() {
Index index = Index.fromOneBased(1000);
AllocateStudentToTeamByIndexCommand allocateStudentToTeamByIndexCommand =
new AllocateStudentToTeamByIndexCommand(index, newModule, tutorialClass, newTeam);
Index index = Index.fromOneBased(10);
TutorialClass tutorialClass = newModule.getTutorialClasses().get(0);
AllocateStudentToTeamByIndexCommand allocateStudentToTeamByIndexCommand = new
AllocateStudentToTeamByIndexCommand(index,
newModule, tutorialClass, newTeam);
assertCommandFailure(allocateStudentToTeamByIndexCommand, model,
String.format(TutorialClassMessages.MESSAGE_PERSON_INDEX_NOT_FOUND_IN_CLASS,
index.getOneBased(), tutorialClass));
}

@Test
public void invalidAllocationToTeam_teamSizeExceeded_failure() {
TutorialClass tutorialClass = newModule.getTutorialClasses().get(0);
Person validPerson = model.getAddressBook().getPersonList().get(0);
Person otherValidPerson = model.getAddressBook().getPersonList().get(1);
tutorialClass.addStudent(validPerson);
tutorialClass.addStudent(otherValidPerson);
newTeam.addStudent(validPerson);
tutorialClass.addStudent(validOtherPerson);
AllocateStudentToTeamByStuIdCommand allocateStudentToTeamByStuIdCommand =
new AllocateStudentToTeamByStuIdCommand(validOtherPerson.getStudentId(), newModule,
tutorialClass, newTeam);
AllocateStudentToTeamByEmailCommand allocateStudentToTeamByEmailCommand =
new AllocateStudentToTeamByEmailCommand(validOtherPerson.getEmail(), newModule,
tutorialClass, newTeam);
AllocateStudentToTeamByStuIdCommand allocateStudentToTeamByStuIdCommand = new
AllocateStudentToTeamByStuIdCommand(otherValidPerson.getStudentId(), newModule, tutorialClass, newTeam);
AllocateStudentToTeamByEmailCommand allocateStudentToTeamByEmailCommand = new
AllocateStudentToTeamByEmailCommand(otherValidPerson.getEmail(), newModule, tutorialClass, newTeam);
assertCommandFailure(allocateStudentToTeamByStuIdCommand, model,
String.format(TutorialTeamMessages.MESSAGE_TEAM_SIZE_EXCEEDED, newTeam.getTeamSize()));
assertCommandFailure(allocateStudentToTeamByEmailCommand, model,
String.format(TutorialTeamMessages.MESSAGE_TEAM_SIZE_EXCEEDED, newTeam.getTeamSize()));
}

@Test
public void invalidAllocationToTeam_studentNull_failure() {
AllocateStudentToTeamByStuIdCommand allocateStudentToTeamByStuIdCommand =
new AllocateStudentToTeamByStuIdCommand(
new StudentId(VALID_STUDENT_ID), newModule, tutorialClass, newTeam);
AllocateStudentToTeamByEmailCommand allocateStudentToTeamByEmailCommand =
new AllocateStudentToTeamByEmailCommand(
new Email(VALID_EMAIL), newModule, tutorialClass, newTeam);
public void invalidAllocationToTeam_studentDoesNotExist_failure() {
TutorialClass tutorialClass = newModule.getTutorialClasses().get(0);
AllocateStudentToTeamByStuIdCommand allocateStudentToTeamByStuIdCommand = new
AllocateStudentToTeamByStuIdCommand(new StudentId(VALID_STUDENT_ID), newModule, tutorialClass, newTeam);
AllocateStudentToTeamByEmailCommand allocateStudentToTeamByEmailCommand = new
AllocateStudentToTeamByEmailCommand(new Email(VALID_EMAIL), newModule, tutorialClass, newTeam);
assertCommandFailure(allocateStudentToTeamByStuIdCommand, model,
String.format(PersonMessages.MESSAGE_PERSON_STUDENT_ID_NOT_FOUND, VALID_STUDENT_ID));
assertCommandFailure(allocateStudentToTeamByEmailCommand, model,
Expand All @@ -112,6 +102,8 @@ public void invalidAllocationToTeam_studentNull_failure() {
@Test
public void invalidAllocationToTeam_tutorialTeamNotExist_failure() {
TutorialTeam team = new TutorialTeam(VALID_TEAM_NAME_NEW);
Person validPerson = model.getAddressBook().getPersonList().get(0);
TutorialClass tutorialClass = newModule.getTutorialClasses().get(0);

AllocateStudentToTeamByStuIdCommand allocateStudentToTeamByStuIdCommand =
new AllocateStudentToTeamByStuIdCommand(
Expand All @@ -127,14 +119,18 @@ public void invalidAllocationToTeam_tutorialTeamNotExist_failure() {

@Test
public void invalidAllocationToTeam_studentAlreadyInTeam_failure() {
Person validPerson = model.getAddressBook().getPersonList().get(0);
TutorialClass tutorialClass = newModule.getTutorialClasses().get(0);
tutorialClass.addStudent(validPerson);
newTeam.addStudent(validPerson);
AllocateStudentToTeamByStuIdCommand allocateStudentToTeamByStuIdCommand =
new AllocateStudentToTeamByStuIdCommand(
validPerson.getStudentId(), newModule, tutorialClass, tutTeam);
AllocateStudentToTeamByEmailCommand allocateStudentToTeamByEmailCommand =
new AllocateStudentToTeamByEmailCommand(
validPerson.getEmail(), newModule, tutorialClass, tutTeam);

// try to allocate again but duplicate entry to team.
AllocateStudentToTeamByStuIdCommand allocateStudentToTeamByStuIdCommand = new
AllocateStudentToTeamByStuIdCommand(validPerson.getStudentId(), newModule, tutorialClass,
tutTeam);
AllocateStudentToTeamByEmailCommand allocateStudentToTeamByEmailCommand = new
AllocateStudentToTeamByEmailCommand(validPerson.getEmail(), newModule, tutorialClass,
tutTeam);
assertCommandFailure(allocateStudentToTeamByStuIdCommand, model,
String.format(TutorialTeamMessages.MESSAGE_DUPLICATE_PERSON_IN_TEAM,
Messages.format(validPerson), tutorialClass));
Expand All @@ -144,40 +140,60 @@ public void invalidAllocationToTeam_studentAlreadyInTeam_failure() {
}

@Test
public void validAllocationToTeam_byEmailOrStudentId_success() {
public void validAllocationToTeam_byEmail_success() {
Person validPerson = model.getAddressBook().getPersonList().get(0);
TutorialClass tutorialClass = newModule.getTutorialClasses().get(0);
tutorialClass.addStudent(validPerson);
tutorialClass.addStudent(validOtherPerson);
AllocateStudentToTeamByStuIdCommand allocateStudentToTeamByStuIdCommand =
new AllocateStudentToTeamByStuIdCommand(validPerson.getStudentId(),
newModule, tutorialClass, tutTeam);
AllocateStudentToTeamByEmailCommand allocateStudentToTeamByEmailCommand =
new AllocateStudentToTeamByEmailCommand(validOtherPerson.getEmail(),
newModule, tutorialClass, tutTeam);
AllocateStudentToTeamByStuIdCommand allocateStudentToTeamByStuIdCommand = new
AllocateStudentToTeamByStuIdCommand(validPerson.getStudentId(),
newModule, tutorialClass, tutTeam);

Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModel.addModule(newModule);

assertCommandSuccess(allocateStudentToTeamByStuIdCommand, model,
String.format(AllocateStudentToTeamByIndexCommand.MESSAGE_SUCCESS, tutTeam), model);
String.format(AllocateStudentToTeamByIndexCommand.MESSAGE_SUCCESS, tutTeam), expectedModel);
}

@Test
public void validAllocationToTeam_byStudentId_success() {
Person validPerson = model.getAddressBook().getPersonList().get(0);
TutorialClass tutorialClass = newModule.getTutorialClasses().get(0);
tutorialClass.addStudent(validPerson);
AllocateStudentToTeamByEmailCommand allocateStudentToTeamByEmailCommand = new
AllocateStudentToTeamByEmailCommand(validPerson.getEmail(),
newModule, tutorialClass, tutTeam);

Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModel.addModule(newModule);
assertCommandSuccess(allocateStudentToTeamByEmailCommand, model,
String.format(AllocateStudentToTeamByEmailCommand.MESSAGE_SUCCESS, tutTeam), model);
String.format(AllocateStudentToTeamByEmailCommand.MESSAGE_SUCCESS, tutTeam), expectedModel);
}

@Test
public void validAllocationToTeam_indexInSystem_success() {
Person validPerson = model.getAddressBook().getPersonList().get(0);
TutorialClass tutorialClass = newModule.getTutorialClasses().get(0);
tutorialClass.addStudent(validPerson);
tutorialClass.addStudent(validOtherPerson);
Index index = Index.fromZeroBased(1);
AllocateStudentToTeamByIndexCommand allocateStudentToTeamByIndexCommand =
new AllocateStudentToTeamByIndexCommand(index, newModule, tutorialClass, newTeam);
Index index = Index.fromZeroBased(0);
AllocateStudentToTeamByIndexCommand allocateStudentToTeamByIndexCommand = new
AllocateStudentToTeamByIndexCommand(index,
newModule, tutorialClass, newTeam);

Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModel.addModule(newModule);
assertCommandSuccess(allocateStudentToTeamByIndexCommand, model,
String.format(AllocateStudentToTeamByIndexCommand.MESSAGE_SUCCESS, newTeam), model);
String.format(AllocateStudentToTeamByIndexCommand.MESSAGE_SUCCESS, newTeam), expectedModel);
}

@Test
public void invalidAllocationToTeam_studentNotInTutorialClass_failure() {
AllocateStudentToTeamByStuIdCommand allocateStudentToTeamByStuIdCommand =
new AllocateStudentToTeamByStuIdCommand(
validPerson.getStudentId(), newModule, tutorialClass, newTeam);
AllocateStudentToTeamByEmailCommand allocateStudentToTeamByEmailCommand =
new AllocateStudentToTeamByEmailCommand(
validPerson.getEmail(), newModule, tutorialClass, newTeam);
Person validPerson = model.getAddressBook().getPersonList().get(0);
TutorialClass tutorialClass = newModule.getTutorialClasses().get(0);
AllocateStudentToTeamByStuIdCommand allocateStudentToTeamByStuIdCommand = new
AllocateStudentToTeamByStuIdCommand(validPerson.getStudentId(), newModule, tutorialClass, newTeam);
AllocateStudentToTeamByEmailCommand allocateStudentToTeamByEmailCommand = new
AllocateStudentToTeamByEmailCommand(validPerson.getEmail(), newModule, tutorialClass, newTeam);
assertCommandFailure(allocateStudentToTeamByStuIdCommand, model,
String.format(AllocateStudentToTeamCommand.MESSAGE_STUDENT_NOT_IN_TUTORIAL));
assertCommandFailure(allocateStudentToTeamByEmailCommand, model,
Expand All @@ -186,13 +202,15 @@ public void invalidAllocationToTeam_studentNotInTutorialClass_failure() {

@Test
public void toString_test() {
Person validPerson = model.getAddressBook().getPersonList().get(0);
TutorialClass tutorialClass = newModule.getTutorialClasses().get(0);
tutorialClass.addStudent(validPerson);
AllocateStudentToTeamByStuIdCommand allocateStudentToTeamByStuIdCommand =
new AllocateStudentToTeamByStuIdCommand(
validPerson.getStudentId(), newModule, tutorialClass, newTeam);
AllocateStudentToTeamByEmailCommand allocateOtherStudentToTeamByEmailCommand =
new AllocateStudentToTeamByEmailCommand(
validOtherPerson.getEmail(), newModule, tutorialClass, newTeam);
new AllocateStudentToTeamByEmailCommand(validPerson.getEmail(),
newModule, tutorialClass, newTeam);
AllocateStudentToTeamByIndexCommand allocateStudentToTeamByIndexCommand =
new AllocateStudentToTeamByIndexCommand(
Index.fromZeroBased(0), newModule, tutorialClass, newTeam);
Expand All @@ -202,11 +220,16 @@ public void toString_test() {
allocateStudentToTeamByStuIdCommand.toString());
assertEquals(allocateStudentToTeamByIndexCommand.toString(),
allocateStudentToTeamByIndexCommand.toString());

assertNotEquals(allocateStudentToTeamByIndexCommand.toString(), allocateStudentToTeamByStuIdCommand.toString());
assertNotEquals(allocateStudentToTeamByIndexCommand.toString(),
allocateOtherStudentToTeamByEmailCommand.toString());
}

@Test
public void equals() {
Person validPerson = model.getAddressBook().getPersonList().get(0);
Person validOtherPerson = model.getAddressBook().getPersonList().get(1);
TutorialClass tutorialClass = newModule.getTutorialClasses().get(0);
tutorialClass.addStudent(validPerson);
tutorialClass.addStudent(validOtherPerson);
// creation of 2 allocation command based on 2 different student ID adding to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_SIZE;
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_TEAMNAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TUTORIALCLASS;
import static seedu.address.testutil.Assert.assertThrows;

Expand Down Expand Up @@ -81,9 +82,10 @@ public class CommandTestUtil {
public static final String VALID_TEAM_NAME_NEW = "Team 3";
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_SIZE + VALID_TEAM_SIZE;
public static final String TEAM_DESC_AMY = " " + PREFIX_TEAMNAME + VALID_TEAM_NAME_AMY;
public static final String INVALID_TEAM_NAME = "Team 1!";
public static final int INVALID_TEAM_SIZE = -1;
public static final String INVALID_TEAM_DESC_AMY = " " + PREFIX_TEAMNAME + INVALID_TEAM_NAME;
public static final String TEAM_SIZE_DESC = " " + PREFIX_SIZE + VALID_TEAM_SIZE;

// '&' not allowed in names
public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "James&";
Expand Down
Loading

0 comments on commit 8b6f9c7

Please sign in to comment.