Skip to content

Commit

Permalink
Merge pull request #93 from avrilmohh/unmark-assignment-tests
Browse files Browse the repository at this point in the history
Create test cases for unmark assignment
  • Loading branch information
avrilmohh authored Oct 16, 2024
2 parents a51fc13 + f8c6d98 commit db72c15
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public class MarkAssignmentCommandTest {
@Test
public void execute_validStudentAndAssignmentIndex_markSuccessful() {
Assignment assignment = new AssignmentBuilder()
.withAssignmentName("Math Homework")
.withMaxScore(100)
.build();
Student student = new StudentBuilder().withAssignments(new ArrayList<>()).build().addAssignment(assignment);
model.addStudent(student);
Expand All @@ -40,12 +38,9 @@ public void execute_validStudentAndAssignmentIndex_markSuccessful() {
"Math Homework", student.getName());
Model expectedModel = new ModelManager(new AddressBook(), model.getUserPrefs());
Assignment expectedAssignment = new AssignmentBuilder()
.withAssignmentName("Math Homework")
.withMaxScore(100)
.withHasSubmitted(true)
.build();
Student expectedStudent = new StudentBuilder().withAssignments(new ArrayList<>()).build()
.addAssignment(expectedAssignment);
Student expectedStudent = new StudentBuilder().build().addAssignment(expectedAssignment);
expectedModel.addStudent(expectedStudent);
assertCommandSuccess(markAssignmentCommand, model, expectedMessage, expectedModel);
assertTrue(student.getAssignmentList().get(INDEX_FIRST_ASSIGNMENT.getZeroBased()).getHasSubmitted());
Expand All @@ -54,10 +49,8 @@ public void execute_validStudentAndAssignmentIndex_markSuccessful() {
@Test
public void execute_invalidStudentIndex_markFailure() {
Assignment assignment = new AssignmentBuilder()
.withAssignmentName("Math Homework")
.withMaxScore(100)
.build();
Student student = new StudentBuilder().withAssignments(new ArrayList<>()).build().addAssignment(assignment);
Student student = new StudentBuilder().build().addAssignment(assignment);
model.addStudent(student);
MarkAssignmentCommand markAssignmentCommand = new MarkAssignmentCommand(
Index.fromOneBased(2),
Expand All @@ -69,10 +62,8 @@ public void execute_invalidStudentIndex_markFailure() {
@Test
public void execute_invalidAssignmentIndex_markFailure() {
Assignment assignment = new AssignmentBuilder()
.withAssignmentName("Math Homework")
.withMaxScore(100)
.build();
Student student = new StudentBuilder().withAssignments(new ArrayList<>()).build().addAssignment(assignment);
Student student = new StudentBuilder().build().addAssignment(assignment);
model.addStudent(student);
MarkAssignmentCommand markAssignmentCommand = new MarkAssignmentCommand(
INDEX_FIRST_STUDENT,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package seedu.address.logic.commands;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_ASSIGNMENT;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_STUDENT;

import java.util.ArrayList;

import org.junit.jupiter.api.Test;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.Messages;
import seedu.address.model.AddressBook;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
import seedu.address.model.assignment.Assignment;
import seedu.address.model.student.Student;
import seedu.address.testutil.AssignmentBuilder;
import seedu.address.testutil.StudentBuilder;

public class UnmarkAssignmentCommandTest {

private Model model = new ModelManager(new AddressBook(), new UserPrefs());

@Test
public void execute_validStudentAndAssignmentIndex_unmarkSuccessful() {
Assignment assignment = new AssignmentBuilder()
.withHasSubmitted(true)
.build();
Student student = new StudentBuilder().withAssignments(new ArrayList<>()).build().addAssignment(assignment);
model.addStudent(student);
UnmarkAssignmentCommand unmarkAssignmentCommand = new UnmarkAssignmentCommand(
INDEX_FIRST_STUDENT, INDEX_FIRST_ASSIGNMENT);
String expectedMessage = String.format(UnmarkAssignmentCommand.MESSAGE_UNMARK_SUCCESS,
"Math Homework", student.getName().fullName);
Model expectedModel = new ModelManager(new AddressBook(), model.getUserPrefs());
Assignment expectedAssignment = new AssignmentBuilder()
.build();
Student expectedStudent = new StudentBuilder().build().addAssignment(expectedAssignment);
expectedModel.addStudent(expectedStudent);
assertCommandSuccess(unmarkAssignmentCommand, model, expectedMessage, expectedModel);
assertEquals(false, student.getAssignmentList().get(INDEX_FIRST_ASSIGNMENT.getZeroBased()).getHasSubmitted());
assertEquals(0, student.getAssignmentList().get(INDEX_FIRST_ASSIGNMENT.getZeroBased()).getScore());
}

@Test
public void execute_invalidStudentIndex_throwsCommandException() {
Assignment assignment = new AssignmentBuilder()
.withHasSubmitted(true)
.build();
Student student = new StudentBuilder().withAssignments(new ArrayList<>()).build().addAssignment(assignment);
model.addStudent(student);
UnmarkAssignmentCommand unmarkAssignmentCommand = new UnmarkAssignmentCommand(
Index.fromOneBased(2), INDEX_FIRST_ASSIGNMENT);
assertCommandFailure(unmarkAssignmentCommand, model, Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX);
}

@Test
public void execute_invalidAssignmentIndex_throwsCommandException() {
Assignment assignment = new AssignmentBuilder()
.withHasSubmitted(true)
.build();
Student student = new StudentBuilder().withAssignments(new ArrayList<>()).build().addAssignment(assignment);
model.addStudent(student);
UnmarkAssignmentCommand unmarkAssignmentCommand = new UnmarkAssignmentCommand(
INDEX_FIRST_STUDENT, Index.fromOneBased(2));
assertCommandFailure(unmarkAssignmentCommand, model, Messages.MESSAGE_INVALID_ASSIGNMENT_INDEX);
}

}

0 comments on commit db72c15

Please sign in to comment.