Skip to content

Commit

Permalink
Adds sort command
Browse files Browse the repository at this point in the history
Adds case insensitive
Adds logic tests for sort command
Update case insensitive tests
Updates the user guid
Updates display of help command
  • Loading branch information
LinusMelb committed Sep 19, 2017
1 parent 5a6c8a2 commit 5f02b62
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 13 deletions.
4 changes: 4 additions & 0 deletions doc/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Examples:
Shows a list of all persons in the address book.<br>
Format: `list`

## Listing all persons : `sort`
Shows a sorted list of all persons in the address book.<br>
Format: `sort`

## Finding all persons containing any keyword in their name: `find`
Finds persons whose names contain any of the given keywords.<br>
Format: `find KEYWORD [MORE_KEYWORDS]`
Expand Down
10 changes: 10 additions & 0 deletions src/seedu/addressbook/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ public static String getMessageForPersonListShownSummary(List<? extends ReadOnly
return String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, personsDisplayed.size());
}

/**
* Constructs a feedback message to summarise an operation that displayed a sorted listing of persons.
*
* @param personsDisplayed used to generate summary
* @return summary message for persons displayed
*/
public static String getMessageForPersonSortShownSummary(List<? extends ReadOnlyPerson> personsDisplayed) {
return String.format(Messages.MESSAGE_PERSONS_SORTED_OVERVIEW, personsDisplayed.size());
}

/**
* Executes the command and returns the result.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/seedu/addressbook/commands/SortCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public CommandResult execute() {

List<Person> SortAllPersons = addressBook.getAllPersons().SortAllPersons();

return new CommandResult(getMessageForPersonListShownSummary(SortAllPersons), SortAllPersons);
return new CommandResult(getMessageForPersonSortShownSummary(SortAllPersons), SortAllPersons);

}
}
7 changes: 3 additions & 4 deletions src/seedu/addressbook/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@
*/
public class Parser {

public static final Pattern PERSON_INDEX_ARGS_FORMAT = Pattern.compile("(?<targetIndex>.+)");
private static final Pattern PERSON_INDEX_ARGS_FORMAT = Pattern.compile("(?<targetIndex>.+)");

public static final Pattern KEYWORDS_ARGS_FORMAT =
private static final Pattern KEYWORDS_ARGS_FORMAT =
Pattern.compile("(?<keywords>\\S+(?:\\s+\\S+)*)"); // one or more keywords separated by whitespace

public static final Pattern PERSON_DATA_ARGS_FORMAT = // '/' forward slashes are reserved for delimiter prefixes
private static final Pattern PERSON_DATA_ARGS_FORMAT = // '/' forward slashes are reserved for delimiter prefixes
Pattern.compile("(?<name>[^/]+)"
+ " (?<isPhonePrivate>p?)p/(?<phone>[^/]+)"
+ " (?<isEmailPrivate>p?)e/(?<email>[^/]+)"
+ " (?<isAddressPrivate>p?)a/(?<address>[^/]+)"
+ "(?<tagArguments>(?: t/[^/]+)*)"); // variable number of tags


/**
* Signals that the user input could not be parsed.
*/
Expand Down
6 changes: 2 additions & 4 deletions src/seedu/addressbook/ui/Gui.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import javafx.stage.Stage;
import seedu.addressbook.logic.Logic;
import seedu.addressbook.Main;

import java.io.File;
import java.io.IOException;

/**
Expand All @@ -17,8 +15,8 @@ public class Gui {
/** Offset required to convert between 1-indexing and 0-indexing. */
public static final int DISPLAYED_INDEX_OFFSET = 1;

public static final int INITIAL_WINDOW_WIDTH = 800;
public static final int INITIAL_WINDOW_HEIGHT = 600;
private static final int INITIAL_WINDOW_WIDTH = 800;
private static final int INITIAL_WINDOW_HEIGHT = 600;
private final Logic logic;

private MainWindow mainWindow;
Expand Down
26 changes: 22 additions & 4 deletions test/java/seedu/addressbook/logic/LogicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public void execute_clear() throws Exception {
addressBook.addPerson(helper.generatePerson(1, true));
addressBook.addPerson(helper.generatePerson(2, true));
addressBook.addPerson(helper.generatePerson(3, true));
addressBook.addPerson(helper.generatePerson(4, true));

assertCommandBehavior("clear", ClearCommand.MESSAGE_SUCCESS, AddressBook.empty(), false, Collections.emptyList());
}
Expand Down Expand Up @@ -201,6 +202,23 @@ public void execute_list_showsAllPersons() throws Exception {
expectedList);
}

@Test
public void execute_sort_showsAllPersons() throws Exception {
// prepare expectations
TestDataHelper helper = new TestDataHelper();
AddressBook expectedAB = helper.generateAddressBook(false, true);
List<? extends ReadOnlyPerson> expectedList = expectedAB.getAllPersons().SortAllPersons();

// prepare address book state
helper.addToAddressBook(addressBook, false, true);

assertCommandBehavior("sort",
Command.getMessageForPersonSortShownSummary(expectedList),
expectedAB,
true,
expectedList);
}

@Test
public void execute_view_invalidArgsFormat() throws Exception {
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE);
Expand Down Expand Up @@ -418,16 +436,16 @@ public void execute_find_onlyMatchesFullWordsInNames() throws Exception {
}

@Test
public void execute_find_isCaseSensitive() throws Exception {
public void execute_find_isCaseInSensitive() throws Exception {
TestDataHelper helper = new TestDataHelper();
Person pTarget1 = helper.generatePersonWithName("bla bla KEY bla");
Person pTarget2 = helper.generatePersonWithName("bla KEY bla bceofeia");
Person p1 = helper.generatePersonWithName("key key");
Person p1 = helper.generatePersonWithName("Kay KAAY");
Person p2 = helper.generatePersonWithName("KEy sduauo");

List<Person> fourPersons = helper.generatePersonList(p1, pTarget1, p2, pTarget2);
AddressBook expectedAB = helper.generateAddressBook(fourPersons);
List<Person> expectedList = helper.generatePersonList(pTarget1, pTarget2);
List<Person> expectedList = helper.generatePersonList(pTarget1, p2, pTarget2);
helper.addToAddressBook(addressBook, fourPersons);

assertCommandBehavior("find KEY",
Expand All @@ -447,7 +465,7 @@ public void execute_find_matchesIfAnyKeywordPresent() throws Exception {

List<Person> fourPersons = helper.generatePersonList(p1, pTarget1, p2, pTarget2);
AddressBook expectedAB = helper.generateAddressBook(fourPersons);
List<Person> expectedList = helper.generatePersonList(pTarget1, pTarget2);
List<Person> expectedList = helper.generatePersonList(p1, pTarget1, p2, pTarget2);
helper.addToAddressBook(addressBook, fourPersons);

assertCommandBehavior("find KEY rAnDoM",
Expand Down
6 changes: 6 additions & 0 deletions test/java/seedu/addressbook/parser/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ public void listCommand_parsedCorrectly() {
parseAndAssertCommandType(input, ListCommand.class);
}

@Test
public void sortCommand_parsedCorrectly(){
final String input = "sort";
parseAndAssertCommandType(input, SortCommand.class);
}

@Test
public void exitCommand_parsedCorrectly() {
final String input = "exit";
Expand Down

0 comments on commit 5f02b62

Please sign in to comment.