Skip to content

Commit

Permalink
Merge pull request #242 from kwangthiag/sortparsers
Browse files Browse the repository at this point in the history
Add Tests for Sort Command parsers and Add equals to Sort Command
  • Loading branch information
trgao authored Nov 9, 2023
2 parents 9b9d947 + 215e7fa commit 391da1b
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,19 @@ private static String order(boolean isAscending) {
return "descending";
}
}

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

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

SortCommand e = (SortCommand) other;
return attribute.equals(e.attribute) && isAscending == e.isAscending;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,19 @@ private static String order(boolean isAscending) {
return "descending";
}
}

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

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

SortPatientCommand e = (SortPatientCommand) other;
return attribute.equals(e.attribute) && isAscending == e.isAscending;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,8 @@ public SortCommand parse(String args) throws ParseException {

return new SortCommand(isAscending, attribute);
}
public static String printAttributes() {
return Arrays.toString(ATTRIBUTES);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ public SortPatientCommand parse(String args) throws ParseException {
return new SortPatientCommand(isAscending, attribute);
}

public static String printAttributes() {
return Arrays.toString(ATTRIBUTES);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package seedu.address.logic.parser.appointmentparser;

import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.Messages.MESSAGE_INVALID_SORT_ATTRIBUTE;
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.appointmentcommands.SortCommand;

public class SortCommandParserTest {

private static final String INVALID_PREAMBLE_1 = " descending";
private static final String INVALID_ATTRIBUTE_DESC = " by= friend";
private static final String VALID_PREAMBLE_1 = " desc";
private static final String VALID_ATTRIBUTE_DESC = " by= time";
private static final String VALID_ATTRIBUTE_1 = "time";
private SortCommandParser parser = new SortCommandParser();
@Test
public void parse_invalidPreamble_failure() {
assertParseFailure(parser, INVALID_PREAMBLE_1 + VALID_ATTRIBUTE_DESC,
String.format(MESSAGE_INVALID_COMMAND_FORMAT, SortCommand.MESSAGE_USAGE));
}
@Test
public void parse_invalidAttribute_failure() {
assertParseFailure(parser, VALID_PREAMBLE_1 + INVALID_ATTRIBUTE_DESC,
String.format(MESSAGE_INVALID_SORT_ATTRIBUTE, SortCommandParser.printAttributes()));
}

@Test
public void parse_validPreambleAndAttribute_success() {
SortCommand expectedSortCommand = new SortCommand(false, VALID_ATTRIBUTE_1);
assertParseSuccess(parser, VALID_PREAMBLE_1 + VALID_ATTRIBUTE_DESC, expectedSortCommand);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package seedu.address.logic.parser.personparser;

import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.Messages.MESSAGE_INVALID_SORT_ATTRIBUTE;
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.personcommands.SortPatientCommand;

public class SortPatientCommandParserTest {

private static final String INVALID_PREAMBLE_1 = " ascending";
private static final String INVALID_ATTRIBUTE_DESC = " by= friend";
private static final String VALID_PREAMBLE_1 = " asc";
private static final String VALID_ATTRIBUTE_DESC = " by= name";
private static final String VALID_ATTRIBUTE_1 = "name";
private SortPatientCommandParser parser = new SortPatientCommandParser();
@Test
public void parse_invalidPreamble_failure() {
assertParseFailure(parser, INVALID_PREAMBLE_1 + VALID_ATTRIBUTE_DESC,
String.format(MESSAGE_INVALID_COMMAND_FORMAT, SortPatientCommand.MESSAGE_USAGE));
}
@Test
public void parse_invalidAttribute_failure() {
assertParseFailure(parser, VALID_PREAMBLE_1 + INVALID_ATTRIBUTE_DESC,
String.format(MESSAGE_INVALID_SORT_ATTRIBUTE, SortPatientCommandParser.printAttributes()));
}

@Test
public void parse_validPreambleAndAttribute_success() {
SortPatientCommand expectedSortPatientCommand = new SortPatientCommand(true, VALID_ATTRIBUTE_1);
assertParseSuccess(parser, VALID_PREAMBLE_1 + VALID_ATTRIBUTE_DESC, expectedSortPatientCommand);
}
}

0 comments on commit 391da1b

Please sign in to comment.