forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from AY2324S2-CS2103T-W12-2/brandon/add-parse…
…r-tests test: add tests for parser
- Loading branch information
Showing
10 changed files
with
400 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/test/java/seedu/address/logic/parser/AddStudentModuleCommandParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.commands.CommandTestUtil.MODULE_CODE_DESC_CS2103T; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_MODULE_CODE_CS2103T; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_STUDENT_ID; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_STUDENT; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.AddStudentModuleCommand; | ||
import seedu.address.model.module.ModuleCode; | ||
|
||
public class AddStudentModuleCommandParserTest { | ||
private AddStudentModuleCommandParser parser = new AddStudentModuleCommandParser(); | ||
|
||
@Test | ||
public void parse_allFieldsPresent_success() { | ||
Index targetIndex = INDEX_FIRST_STUDENT; | ||
String userInput = " " + PREFIX_STUDENT_ID + targetIndex.getOneBased() + MODULE_CODE_DESC_CS2103T; | ||
|
||
AddStudentModuleCommand expectedCommand = new AddStudentModuleCommand( | ||
targetIndex, new ModuleCode(VALID_MODULE_CODE_CS2103T)); | ||
|
||
assertParseSuccess(parser, userInput, expectedCommand); | ||
} | ||
|
||
@Test | ||
public void parse_compulsoryFieldMissing_failure() { | ||
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddStudentModuleCommand.MESSAGE_USAGE); | ||
|
||
// missing index prefix | ||
assertParseFailure(parser, | ||
" " + INDEX_FIRST_STUDENT.getOneBased() + MODULE_CODE_DESC_CS2103T, | ||
expectedMessage); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/test/java/seedu/address/logic/parser/AddStudentModuleTimingCommandParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.commands.CommandTestUtil.DAY_DESC_MON; | ||
import static seedu.address.logic.commands.CommandTestUtil.END_TIMING_DESC_1600; | ||
import static seedu.address.logic.commands.CommandTestUtil.MODULE_CODE_DESC_CS2103T; | ||
import static seedu.address.logic.commands.CommandTestUtil.START_TIMING_DESC_0800; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_DAY_MON; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_MODULE_CODE_CS2103T; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_TIMING_0800; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_TIMING_1600; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_STUDENT_ID; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_STUDENT; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.AddStudentModuleTimingCommand; | ||
import seedu.address.model.module.Day; | ||
import seedu.address.model.module.ModuleCode; | ||
import seedu.address.model.module.ModuleTiming; | ||
import seedu.address.model.module.Timing; | ||
|
||
public class AddStudentModuleTimingCommandParserTest { | ||
private AddStudentModuleTimingCommandParser parser = new AddStudentModuleTimingCommandParser(); | ||
|
||
@Test | ||
public void parse_allFieldsPresent_success() { | ||
Index targetIndex = INDEX_FIRST_STUDENT; | ||
String userInput = " " + PREFIX_STUDENT_ID + targetIndex.getOneBased() | ||
+ MODULE_CODE_DESC_CS2103T | ||
+ DAY_DESC_MON | ||
+ START_TIMING_DESC_0800 | ||
+ END_TIMING_DESC_1600; | ||
|
||
|
||
ModuleTiming expectedModuleTiming = new ModuleTiming( | ||
new ModuleCode(VALID_MODULE_CODE_CS2103T), | ||
new Day(VALID_DAY_MON), | ||
new Timing(VALID_TIMING_0800), | ||
new Timing(VALID_TIMING_1600) | ||
); | ||
AddStudentModuleTimingCommand expectedCommand = new AddStudentModuleTimingCommand( | ||
targetIndex, | ||
new ModuleCode(VALID_MODULE_CODE_CS2103T), | ||
expectedModuleTiming); | ||
|
||
assertParseSuccess(parser, userInput, expectedCommand); | ||
} | ||
|
||
@Test | ||
public void parse_compulsoryFieldMissing_failure() { | ||
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
AddStudentModuleTimingCommand.MESSAGE_USAGE); | ||
|
||
// missing index prefix | ||
assertParseFailure(parser, | ||
" " + INDEX_FIRST_STUDENT.getOneBased() + MODULE_CODE_DESC_CS2103T | ||
+ START_TIMING_DESC_0800 + END_TIMING_DESC_1600, | ||
expectedMessage); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/test/java/seedu/address/logic/parser/DeleteStudentModuleCommandParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.commands.CommandTestUtil.MODULE_CODE_DESC_CS2103T; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_MODULE_CODE_CS2103T; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_STUDENT_ID; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_STUDENT; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.DeleteStudentModuleCommand; | ||
import seedu.address.model.module.ModuleCode; | ||
|
||
public class DeleteStudentModuleCommandParserTest { | ||
private DeleteStudentModuleCommandParser parser = new DeleteStudentModuleCommandParser(); | ||
|
||
@Test | ||
public void parse_allFieldsPresent_success() { | ||
Index targetIndex = INDEX_FIRST_STUDENT; | ||
String userInput = " " + PREFIX_STUDENT_ID + targetIndex.getOneBased() + MODULE_CODE_DESC_CS2103T; | ||
|
||
DeleteStudentModuleCommand expectedCommand = new DeleteStudentModuleCommand( | ||
targetIndex, new ModuleCode(VALID_MODULE_CODE_CS2103T)); | ||
|
||
assertParseSuccess(parser, userInput, expectedCommand); | ||
} | ||
|
||
@Test | ||
public void parse_compulsoryFieldMissing_failure() { | ||
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
DeleteStudentModuleCommand.MESSAGE_USAGE); | ||
|
||
// missing index prefix | ||
assertParseFailure(parser, | ||
" " + INDEX_FIRST_STUDENT.getOneBased() + MODULE_CODE_DESC_CS2103T, | ||
expectedMessage); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/test/java/seedu/address/logic/parser/DeleteStudentModuleTimingCommandParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.commands.CommandTestUtil.DAY_DESC_MON; | ||
import static seedu.address.logic.commands.CommandTestUtil.END_TIMING_DESC_1600; | ||
import static seedu.address.logic.commands.CommandTestUtil.MODULE_CODE_DESC_CS2103T; | ||
import static seedu.address.logic.commands.CommandTestUtil.START_TIMING_DESC_0800; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_DAY_MON; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_MODULE_CODE_CS2103T; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_TIMING_0800; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_TIMING_1600; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_STUDENT_ID; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_STUDENT; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.DeleteStudentModuleTimingCommand; | ||
import seedu.address.model.module.Day; | ||
import seedu.address.model.module.ModuleCode; | ||
import seedu.address.model.module.ModuleTiming; | ||
import seedu.address.model.module.Timing; | ||
|
||
public class DeleteStudentModuleTimingCommandParserTest { | ||
private DeleteStudentModuleTimingCommandParser parser = new DeleteStudentModuleTimingCommandParser(); | ||
|
||
@Test | ||
public void parse_allFieldsPresent_success() { | ||
Index targetIndex = INDEX_FIRST_STUDENT; | ||
String userInput = " " + PREFIX_STUDENT_ID + targetIndex.getOneBased() | ||
+ MODULE_CODE_DESC_CS2103T | ||
+ DAY_DESC_MON | ||
+ START_TIMING_DESC_0800 | ||
+ END_TIMING_DESC_1600; | ||
|
||
|
||
ModuleTiming expectedModuleTiming = new ModuleTiming( | ||
new ModuleCode(VALID_MODULE_CODE_CS2103T), | ||
new Day(VALID_DAY_MON), | ||
new Timing(VALID_TIMING_0800), | ||
new Timing(VALID_TIMING_1600) | ||
); | ||
DeleteStudentModuleTimingCommand expectedCommand = new DeleteStudentModuleTimingCommand( | ||
targetIndex, | ||
new ModuleCode(VALID_MODULE_CODE_CS2103T), | ||
expectedModuleTiming); | ||
|
||
assertParseSuccess(parser, userInput, expectedCommand); | ||
} | ||
|
||
@Test | ||
public void parse_compulsoryFieldMissing_failure() { | ||
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
DeleteStudentModuleTimingCommand.MESSAGE_USAGE); | ||
|
||
// missing index prefix | ||
assertParseFailure(parser, | ||
" " + INDEX_FIRST_STUDENT.getOneBased() + MODULE_CODE_DESC_CS2103T | ||
+ START_TIMING_DESC_0800 + END_TIMING_DESC_1600, | ||
expectedMessage); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/test/java/seedu/address/logic/parser/FindFreeTimeCommandParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.commands.CommandTestUtil.DAY_DESC_MON; | ||
import static seedu.address.logic.commands.CommandTestUtil.END_TIMING_DESC_1600; | ||
import static seedu.address.logic.commands.CommandTestUtil.INVALID_DAY_DESC; | ||
import static seedu.address.logic.commands.CommandTestUtil.INVALID_END_TIMING_DESC; | ||
import static seedu.address.logic.commands.CommandTestUtil.INVALID_START_TIMING_DESC; | ||
import static seedu.address.logic.commands.CommandTestUtil.START_TIMING_DESC_0800; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_DAY_MON; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_TIMING_0800; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_TIMING_1600; | ||
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.FindFreeTimeCommand; | ||
import seedu.address.model.module.Day; | ||
import seedu.address.model.module.Timing; | ||
import seedu.address.model.student.IsFreePredicate; | ||
|
||
public class FindFreeTimeCommandParserTest { | ||
private FindFreeTimeCommandParser parser = new FindFreeTimeCommandParser(); | ||
|
||
@Test | ||
public void parse_allFieldsPresent_success() { | ||
String userInput = DAY_DESC_MON | ||
+ START_TIMING_DESC_0800 | ||
+ END_TIMING_DESC_1600; | ||
|
||
|
||
IsFreePredicate expectedIsFreePredicate = new IsFreePredicate( | ||
new Timing(VALID_TIMING_0800), | ||
new Timing(VALID_TIMING_1600), | ||
new Day(VALID_DAY_MON) | ||
); | ||
FindFreeTimeCommand expectedCommand = new FindFreeTimeCommand(expectedIsFreePredicate); | ||
|
||
assertParseSuccess(parser, userInput, expectedCommand); | ||
} | ||
|
||
@Test | ||
public void parse_compulsoryFieldMissing_failure() { | ||
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindFreeTimeCommand.MESSAGE_USAGE); | ||
|
||
// missing day prefix | ||
assertParseFailure(parser, VALID_DAY_MON + START_TIMING_DESC_0800 + END_TIMING_DESC_1600, | ||
expectedMessage); | ||
} | ||
|
||
@Test | ||
public void parse_invalidValue_failure() { | ||
// invalid day | ||
assertParseFailure(parser, INVALID_DAY_DESC + START_TIMING_DESC_0800 + END_TIMING_DESC_1600, | ||
Day.MESSAGE_CONSTRAINTS); | ||
|
||
// invalid start time | ||
assertParseFailure(parser, DAY_DESC_MON + INVALID_START_TIMING_DESC + END_TIMING_DESC_1600, | ||
Timing.MESSAGE_CONSTRAINTS); | ||
|
||
// invalid end time | ||
assertParseFailure(parser, DAY_DESC_MON + START_TIMING_DESC_0800 + INVALID_END_TIMING_DESC, | ||
Timing.MESSAGE_CONSTRAINTS); | ||
} | ||
} |
Oops, something went wrong.