Skip to content

Commit

Permalink
Merge pull request #99 from avrilmohh/mark-assignment-parser-tests
Browse files Browse the repository at this point in the history
Create mark assignment parser tests
  • Loading branch information
avrilmohh authored Oct 17, 2024
2 parents 3a2a658 + ff35459 commit eb9e835
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public MarkAssignmentCommand parse(String args) throws ParseException {
}
Index studentIndex;
Index assignmentIndex;

argumentMultimap.verifyNoDuplicatePrefixesFor(PREFIX_STUDENT_INDEX, PREFIX_ASSIGNMENT_INDEX);
try {
studentIndex = ParserUtil.parseIndex(argumentMultimap.getValue(PREFIX_STUDENT_INDEX).get());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package seedu.address.logic.parser;

import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ASSIGNMENT_INDEX;
import static seedu.address.logic.parser.CliSyntax.PREFIX_STUDENT_INDEX;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_ASSIGNMENT;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_STUDENT;
import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_ASSIGNMENT;
import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_STUDENT;

import org.junit.jupiter.api.Test;

import seedu.address.logic.Messages;
import seedu.address.logic.commands.MarkAssignmentCommand;

public class MarkAssignmentCommandParserTest {

private final MarkAssignmentCommandParser parser = new MarkAssignmentCommandParser();

@Test
public void parse_validArgs_returnsMarkAssignmentCommand() {
String userInput = " " + PREFIX_STUDENT_INDEX + INDEX_FIRST_STUDENT.getOneBased() + " "
+ PREFIX_ASSIGNMENT_INDEX + INDEX_FIRST_ASSIGNMENT.getOneBased();
assertParseSuccess(parser, userInput, new MarkAssignmentCommand(INDEX_FIRST_STUDENT, INDEX_FIRST_ASSIGNMENT));
}

@Test
public void parse_invalidArgs_throwsParseException() {
assertParseFailure(parser, "a", String.format(MESSAGE_INVALID_COMMAND_FORMAT,
MarkAssignmentCommand.MESSAGE_USAGE));
}

@Test
public void parse_missingPrefixes_throwsParseException() {
// Missing both prefixes
String userInput = "1 1";
assertParseFailure(parser, userInput, String.format(MESSAGE_INVALID_COMMAND_FORMAT,
MarkAssignmentCommand.MESSAGE_USAGE));

// Missing student prefix
userInput = "1 " + PREFIX_ASSIGNMENT_INDEX + "1";
assertParseFailure(parser, userInput, String.format(MESSAGE_INVALID_COMMAND_FORMAT,
MarkAssignmentCommand.MESSAGE_USAGE));

// Missing assignment prefix
userInput = PREFIX_STUDENT_INDEX + "1";
assertParseFailure(parser, userInput, String.format(MESSAGE_INVALID_COMMAND_FORMAT,
MarkAssignmentCommand.MESSAGE_USAGE));
}

@Test
public void parse_duplicatePrefixes_throwsParseException() {
// Duplicate student prefix
String duplicateStudentInput = " " + PREFIX_STUDENT_INDEX + INDEX_FIRST_STUDENT.getOneBased() + " "
+ PREFIX_STUDENT_INDEX + INDEX_SECOND_STUDENT + " " + PREFIX_ASSIGNMENT_INDEX + INDEX_FIRST_ASSIGNMENT;
Prefix[] duplicatedStudentPrefixes = { PREFIX_STUDENT_INDEX };
assertParseFailure(parser, duplicateStudentInput,
Messages.getErrorMessageForDuplicatePrefixes(duplicatedStudentPrefixes));

// Duplicate assignment prefix
String duplicateAssignmentInput = " " + PREFIX_STUDENT_INDEX + INDEX_FIRST_STUDENT.getOneBased() + " "
+ PREFIX_ASSIGNMENT_INDEX + INDEX_FIRST_ASSIGNMENT + " "
+ PREFIX_ASSIGNMENT_INDEX + INDEX_SECOND_ASSIGNMENT;
Prefix[] duplicatedAssignmentPrefixes = { PREFIX_ASSIGNMENT_INDEX };
assertParseFailure(parser, duplicateAssignmentInput,
Messages.getErrorMessageForDuplicatePrefixes(duplicatedAssignmentPrefixes));
}

@Test
public void parse_nonNumericIndexes_throwsParseException() {
// Non-numeric student index
String userInput = PREFIX_STUDENT_INDEX + "a " + PREFIX_ASSIGNMENT_INDEX + "1";
assertParseFailure(parser, userInput, String.format(MESSAGE_INVALID_COMMAND_FORMAT,
MarkAssignmentCommand.MESSAGE_USAGE));

// Non-numeric assignment index
userInput = PREFIX_STUDENT_INDEX + "1 " + PREFIX_ASSIGNMENT_INDEX + "b";
assertParseFailure(parser, userInput, String.format(MESSAGE_INVALID_COMMAND_FORMAT,
MarkAssignmentCommand.MESSAGE_USAGE));
}

@Test
public void parse_emptyInput_throwsParseException() {
// Empty input
assertParseFailure(parser, "", String.format(MESSAGE_INVALID_COMMAND_FORMAT,
MarkAssignmentCommand.MESSAGE_USAGE));
}

}

0 comments on commit eb9e835

Please sign in to comment.