Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add tests for parser #132

Merged
merged 4 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,19 @@
}
return new CommandResult(sb.toString());
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;

Check warning on line 49 in src/main/java/seedu/address/logic/commands/module/ListModulesCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/module/ListModulesCommand.java#L49

Added line #L49 was not covered by tests
}

// instanceof handles nulls
if (!(other instanceof ListModulesCommand)) {
return false;

Check warning on line 54 in src/main/java/seedu/address/logic/commands/module/ListModulesCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/module/ListModulesCommand.java#L54

Added line #L54 was not covered by tests
}

ListModulesCommand otherListModulesCommand = (ListModulesCommand) other;
return modulePrefix.equals(otherListModulesCommand.modulePrefix);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,19 @@
sb.append(String.format(Messages.MESSAGE_STUDENTS_LISTED_OVERVIEW, model.getFilteredStudentList().size()));
return new CommandResult(sb.toString());
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;

Check warning on line 45 in src/main/java/seedu/address/logic/commands/module/ModuleSearchCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/module/ModuleSearchCommand.java#L45

Added line #L45 was not covered by tests
}

// instanceof handles nulls
if (!(other instanceof ModuleSearchCommand)) {
return false;

Check warning on line 50 in src/main/java/seedu/address/logic/commands/module/ModuleSearchCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/module/ModuleSearchCommand.java#L50

Added line #L50 was not covered by tests
}

ModuleSearchCommand otherModuleSearchCommand = (ModuleSearchCommand) other;
return moduleCode.equals(otherModuleSearchCommand.moduleCode);
}
}
18 changes: 18 additions & 0 deletions src/test/java/seedu/address/logic/commands/CommandTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DAY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_END_TIME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_MODULE_CODE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_START_TIME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.testutil.Assert.assertThrows;

Expand Down Expand Up @@ -36,6 +40,11 @@ public class CommandTestUtil {
public static final String VALID_ADDRESS_BOB = "Block 123, Bobby Street 3";
public static final String VALID_TAG_HUSBAND = "husband";
public static final String VALID_TAG_FRIEND = "friend";
public static final String VALID_MODULE_CODE_CS2103T = "CS2103T";
public static final String VALID_DAY_MON = "Mon";
public static final String VALID_TIMING_0800 = "0800";
public static final String VALID_TIMING_1600 = "1600";


public static final String NAME_DESC_AMY = " " + PREFIX_NAME + VALID_NAME_AMY;
public static final String NAME_DESC_BOB = " " + PREFIX_NAME + VALID_NAME_BOB;
Expand All @@ -47,12 +56,21 @@ public class CommandTestUtil {
public static final String ADDRESS_DESC_BOB = " " + PREFIX_ADDRESS + VALID_ADDRESS_BOB;
public static final String TAG_DESC_FRIEND = " " + PREFIX_TAG + VALID_TAG_FRIEND;
public static final String TAG_DESC_HUSBAND = " " + PREFIX_TAG + VALID_TAG_HUSBAND;
public static final String MODULE_CODE_DESC_CS2103T = " " + PREFIX_MODULE_CODE + VALID_MODULE_CODE_CS2103T;
public static final String DAY_DESC_MON = " " + PREFIX_DAY + VALID_DAY_MON;
public static final String START_TIMING_DESC_0800 = " " + PREFIX_START_TIME + VALID_TIMING_0800;
public static final String END_TIMING_DESC_1600 = " " + PREFIX_END_TIME + VALID_TIMING_1600;

public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "James&"; // '&' not allowed in names
public static final String INVALID_PHONE_DESC = " " + PREFIX_PHONE + "911a"; // 'a' not allowed in phones
public static final String INVALID_EMAIL_DESC = " " + PREFIX_EMAIL + "bob!yahoo"; // missing '@' symbol
public static final String INVALID_ADDRESS_DESC = " " + PREFIX_ADDRESS; // empty string not allowed for addresses
public static final String INVALID_TAG_DESC = " " + PREFIX_TAG + "hubby*"; // '*' not allowed in tags
public static final String INVALID_MODULE_CODE = "ABCDEFG";
public static final String INVALID_MODULE_CODE_DESC = " " + PREFIX_MODULE_CODE + INVALID_MODULE_CODE;
public static final String INVALID_DAY_DESC = " " + PREFIX_DAY + "mond";
public static final String INVALID_START_TIMING_DESC = " " + PREFIX_START_TIME + "0899";
public static final String INVALID_END_TIMING_DESC = " " + PREFIX_END_TIME + "2500";

public static final String PREAMBLE_WHITESPACE = "\t \r \n";
public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble";
Expand Down
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Loading
Loading