forked from nusCS2113-AY1819S1/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 3
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 #169 from CS2113-AY1819S1-T09-4/Writing_Sort_Tests
SortCommand and Parser Tests Done
- Loading branch information
Showing
7 changed files
with
195 additions
and
33 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
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
85 changes: 85 additions & 0 deletions
85
src/test/java/seedu/planner/logic/commands/SortCommandTest.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,85 @@ | ||
package seedu.planner.logic.commands; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotEquals; | ||
import static seedu.planner.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
import static seedu.planner.logic.commands.SortCommand.MESSAGE_SUCCESS; | ||
import static seedu.planner.testutil.TypicalRecords.getTypicalFinancialPlanner; | ||
|
||
import org.junit.Test; | ||
|
||
import seedu.planner.logic.CommandHistory; | ||
import seedu.planner.model.Model; | ||
import seedu.planner.model.ModelManager; | ||
import seedu.planner.model.UserPrefs; | ||
import seedu.planner.testutil.FinancialPlannerBuilder; | ||
|
||
public class SortCommandTest { | ||
|
||
private Model model = new ModelManager(getTypicalFinancialPlanner(), new UserPrefs()); | ||
private Model emptyModel = new ModelManager(new FinancialPlannerBuilder().build(), new UserPrefs()); | ||
private Model expectedEmptyModel = new ModelManager(new FinancialPlannerBuilder().build(), new UserPrefs()); | ||
|
||
private CommandHistory commandHistory = new CommandHistory(); | ||
|
||
@Test | ||
public void equals() { | ||
SortCommand sortCommandOne = new SortCommand(SortCommand.CATEGORY_NAME, true); | ||
SortCommand sortCommandTwo = new SortCommand(SortCommand.CATEGORY_MONEY, false); | ||
SortCommand sortCommandOneCopy = new SortCommand(SortCommand.CATEGORY_NAME, true); | ||
SortCommand sortCommandDateTrue = new SortCommand(SortCommand.CATEGORY_DATE, true); | ||
SortCommand sortCommandNameFalse = new SortCommand(SortCommand.CATEGORY_NAME, false); | ||
|
||
// same object -> returns true | ||
assertEquals(sortCommandOne, sortCommandOne); | ||
// same values -> returns true | ||
assertEquals(sortCommandOne, sortCommandOneCopy); | ||
|
||
// different values -> return false | ||
assertNotEquals(sortCommandOne, sortCommandDateTrue); | ||
assertNotEquals(sortCommandOne, sortCommandNameFalse); | ||
assertNotEquals(sortCommandOne, sortCommandTwo); | ||
|
||
// different kind of objects -> return false | ||
assertNotEquals(sortCommandOne, null); | ||
assertNotEquals(sortCommandOne, "not_equal_string"); | ||
} | ||
|
||
@Test | ||
public void execute_emptyList_listIsUnchanged() { | ||
SortCommand command = new SortCommand("name", true); | ||
String expectedMessage = String.format(SortCommand.MESSAGE_SUCCESS, "name", "ascending"); | ||
|
||
assertCommandSuccess(command, emptyModel, commandHistory, expectedMessage, expectedEmptyModel); | ||
} | ||
|
||
@Test | ||
public void execute_unsortedList_listIsSorted() { | ||
SortCommand command = new SortCommand(SortCommand.CATEGORY_DATE, false); | ||
String expectedMessage = String.format(MESSAGE_SUCCESS, SortCommand.CATEGORY_DATE, | ||
SortCommand.ORDER_DESCENDING); | ||
// sort the initial model | ||
Model expectedSortedModel = getSortedModel(model, SortCommand.CATEGORY_DATE, SortCommand.ORDER_DESCENDING); | ||
|
||
assertCommandSuccess(command, model, commandHistory, expectedMessage, expectedSortedModel); | ||
} | ||
|
||
@Test | ||
public void execute_sortedList_listIsUnchanged() { | ||
SortCommand command = new SortCommand(SortCommand.CATEGORY_MONEY, true); | ||
String expectedMessage = String.format(SortCommand.MESSAGE_SUCCESS, SortCommand.CATEGORY_MONEY, | ||
SortCommand.ORDER_ASCENDING); | ||
// obtain a sorted model | ||
Model initialSortedModel = getSortedModel(model, SortCommand.CATEGORY_MONEY, SortCommand.ORDER_ASCENDING); | ||
/// try to sorted it again, result should be identical model | ||
Model expectedModel = getSortedModel(initialSortedModel, SortCommand.CATEGORY_MONEY, | ||
SortCommand.ORDER_ASCENDING); | ||
|
||
assertCommandSuccess(command, initialSortedModel, commandHistory, expectedMessage, expectedModel); | ||
} | ||
|
||
public Model getSortedModel(Model preSortedModel, String category, String order) { | ||
preSortedModel.sortFilteredRecordList(category, (order == SortCommand.ORDER_ASCENDING)); | ||
return model; | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/test/java/seedu/planner/logic/parser/SortCommandParserTest.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,83 @@ | ||
package seedu.planner.logic.parser; | ||
|
||
import static seedu.planner.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.planner.logic.parser.CommandParserTestUtil.assertParseFailure; | ||
import static seedu.planner.logic.parser.CommandParserTestUtil.assertParseSuccess; | ||
|
||
import org.junit.Test; | ||
|
||
import seedu.planner.logic.commands.Command; | ||
import seedu.planner.logic.commands.SortCommand; | ||
|
||
public class SortCommandParserTest { | ||
private SortCommandParser parser = new SortCommandParser(); | ||
|
||
@Test | ||
public void parse_firstFieldsPresent_success() { | ||
// Category specified | ||
Command command = new SortCommand(SortCommand.CATEGORY_MONEY, true); | ||
String inputCommand = SortCommand.CATEGORY_MONEY; | ||
assertParseSuccess(parser, inputCommand, command); | ||
|
||
// Order specified | ||
command = new SortCommand(SortCommand.CATEGORY_NAME, false); | ||
inputCommand = SortCommand.DESCENDING_CONDITION; | ||
assertParseSuccess(parser, inputCommand, command); | ||
|
||
// Order specified | ||
command = new SortCommand(SortCommand.CATEGORY_NAME, true); | ||
inputCommand = SortCommand.ASCENDING_CONDITION; | ||
assertParseSuccess(parser, inputCommand, command); | ||
} | ||
|
||
@Test | ||
public void parse_bothFieldsPresent_success() { | ||
// Category and order specified | ||
Command command = new SortCommand(SortCommand.CATEGORY_MONEY, false); | ||
String inputCommand = SortCommand.CATEGORY_MONEY + " " | ||
+ SortCommand.DESCENDING_CONDITION; | ||
assertParseSuccess(parser, inputCommand, command); | ||
|
||
// Order and category specified | ||
command = new SortCommand(SortCommand.CATEGORY_DATE, true); | ||
inputCommand = SortCommand.ASCENDING_CONDITION + " " | ||
+ SortCommand.CATEGORY_DATE; | ||
assertParseSuccess(parser, inputCommand, command); | ||
} | ||
|
||
@Test | ||
public void parse_additionalWhitespacesPresent_success() { | ||
Command command = new SortCommand(SortCommand.CATEGORY_MONEYFLOW, false); | ||
String inputCommand = " " + SortCommand.CATEGORY_MONEYFLOW + " " | ||
+ SortCommand.DESCENDING_CONDITION + " "; | ||
assertParseSuccess(parser, inputCommand, command); | ||
} | ||
|
||
|
||
@Test | ||
public void parse_noFieldsPresent_failure() { | ||
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, SortCommand.MESSAGE_USAGE); | ||
String inputCommand = ""; | ||
|
||
assertParseFailure(parser, inputCommand, expectedMessage); | ||
} | ||
|
||
@Test | ||
public void parse_invalidFieldPresent_failure() { | ||
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, SortCommand.MESSAGE_USAGE); | ||
String inputCommand = "invalidword"; | ||
assertParseFailure(parser, inputCommand, expectedMessage); | ||
|
||
expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, SortCommand.MESSAGE_USAGE); | ||
inputCommand = SortCommand.ASCENDING_CONDITION + " " + "invalidword"; | ||
assertParseFailure(parser, inputCommand, expectedMessage); | ||
} | ||
|
||
@Test | ||
public void parse_tooManyFieldsPresent_failure() { | ||
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, SortCommand.MESSAGE_USAGE); | ||
String inputCommand = SortCommand.DESCENDING_CONDITION + " " + SortCommand.CATEGORY_DATE + " " | ||
+ "unnecessarystring" + " " + "morestrings"; | ||
assertParseFailure(parser, inputCommand, expectedMessage); | ||
} | ||
} |
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