From 6a7b95c64024af51c701a1ea16d960939b20e2de Mon Sep 17 00:00:00 2001 From: Khoo Kay Leng Desmond Date: Mon, 31 Oct 2016 22:19:03 +0800 Subject: [PATCH 1/2] Add tags as part of search field in find function. Additionally, find function returns the results which the find keywords are a substring of their attributes. For instance. find man will return a task that has manpower, woman, etc --- .../malitio/commons/util/StringUtil.java | 27 ++++++++++++++++--- .../seedu/malitio/model/ModelManager.java | 9 +++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/main/java/seedu/malitio/commons/util/StringUtil.java b/src/main/java/seedu/malitio/commons/util/StringUtil.java index e5ce75d314f9..3dcf017c3a15 100644 --- a/src/main/java/seedu/malitio/commons/util/StringUtil.java +++ b/src/main/java/seedu/malitio/commons/util/StringUtil.java @@ -9,11 +9,25 @@ * Helper functions for handling strings. */ public class StringUtil { + + //@@author a0126633j + /** + * Checks whether any of the query is part of the source string. + */ public static boolean containsIgnoreCase(String source, String query) { - String[] split = source.toLowerCase().split("\\s+"); - List strings = Arrays.asList(split); - return strings.stream().filter(s -> s.equals(query.toLowerCase())).count() > 0; + String[] splitSource = source.toLowerCase().split("\\s+"); + String[] splitQuery = query.toLowerCase().split("\\s+"); + + for(int i = 0; i < splitQuery.length; i++) { + for(int j = 0; j < splitSource.length; j++) { + if (splitSource[j].contains(splitQuery[i])) { + return true; + } + } + } + return false; } + //@@author /** * Returns a detailed message of the t, including the stack trace. @@ -54,4 +68,11 @@ public static String removeSlashesAtBeginningOfString(String arg) { } return arg; } + /** + * Reformats a tag string into a string separated by white space. + * e.g. "[cs2103], [cs1010e]" into "cs2103 cs1010e". + */ + public static String reformatTagString(String arg) { + return arg.replaceAll(",", "").replaceAll("\\[|\\]", " "); + } } diff --git a/src/main/java/seedu/malitio/model/ModelManager.java b/src/main/java/seedu/malitio/model/ModelManager.java index 537da3011259..ce50f128a339 100644 --- a/src/main/java/seedu/malitio/model/ModelManager.java +++ b/src/main/java/seedu/malitio/model/ModelManager.java @@ -359,11 +359,13 @@ private class NameQualifier implements Qualifier { NameQualifier(Set nameKeyWords) { this.nameKeyWords = nameKeyWords; } - + + //@@author a0126633j @Override public boolean run(ReadOnlyFloatingTask task) { return nameKeyWords.stream() - .filter(keyword -> StringUtil.containsIgnoreCase(task.getName().fullName, keyword)) + .filter(keyword -> StringUtil.containsIgnoreCase(task.getName().fullName + + " " + StringUtil.reformatTagString(task.tagsString()), keyword)) .findAny() .isPresent(); } @@ -372,6 +374,7 @@ public boolean run(ReadOnlyFloatingTask task) { public boolean run(ReadOnlyDeadline deadline) { return nameKeyWords.stream() .filter(keyword -> StringUtil.containsIgnoreCase(deadline.getName().fullName + + " " + StringUtil.reformatTagString(deadline.tagsString()) + " " + deadline.getDue().toString(), keyword)) .findAny() @@ -382,6 +385,7 @@ public boolean run(ReadOnlyDeadline deadline) { public boolean run(ReadOnlyEvent event) { return nameKeyWords.stream() .filter(keyword -> StringUtil.containsIgnoreCase(event.getName().fullName + + " " + StringUtil.reformatTagString(event.tagsString()) + " " + event.getStart().toString() + " " + event.getEnd().toString(), keyword)) @@ -395,6 +399,7 @@ public String toString() { return "name=" + String.join(", ", nameKeyWords); } } + //@@author private class TimeQualifier implements Qualifier { private DateTime timeKeyWord; From 6d7f0e649949cfac771bb535f97a7e34bddaf3dc Mon Sep 17 00:00:00 2001 From: Khoo Kay Leng Desmond Date: Mon, 31 Oct 2016 22:54:00 +0800 Subject: [PATCH 2/2] Update find test cases --- src/test/java/guitests/FindCommandTest.java | 37 +++++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/test/java/guitests/FindCommandTest.java b/src/test/java/guitests/FindCommandTest.java index 1c4ebef3a029..46badc7a31fa 100644 --- a/src/test/java/guitests/FindCommandTest.java +++ b/src/test/java/guitests/FindCommandTest.java @@ -15,11 +15,22 @@ //@@author a0126633j public class FindCommandTest extends MalitioGuiTest { + //In the tests below, we assume event,floating task and deadline lists are identical, hence to save resources only work on them equally @Test public void find_nonEmptyList() throws IllegalArgumentException, IllegalValueException { - assertFindEventResult("find with", td.event1, td.event2); //multiple results - assertFindEventResult("find hello"); //no result + assertFindEventResult("find e with", td.event1, td.event2); //multiple results + assertResultMessage("2 tasks found!"); + + assertFindFloatingTaskResult("find peN HOMEWORK", td.floatingTask2); + assertFindDeadlineResult("find peN HOMEWORK", td.deadline3, td.deadline5); + assertResultMessage("3 tasks found!"); + + assertFindDeadlineResult("find 12-25", td.deadline4); //find dates + assertFindEventResult("find 12-25", td.event5); + assertResultMessage("2 tasks found!"); + + assertFindEventResult("find wedding"); //no result //find after deleting one result commandBox.runCommand("list"); @@ -30,9 +41,7 @@ public void find_nonEmptyList() throws IllegalArgumentException, IllegalValueExc @Test public void find_emptyList() throws IllegalArgumentException, IllegalValueException { commandBox.runCommand("clear"); - assertFindFloatingTaskResult("find eat"); //no results - assertFindDeadlineResult("find eat"); - assertFindEventResult("find eat"); + assertFindEventResult("find eat"); //no result } @Test @@ -43,32 +52,38 @@ public void find_invalidCommand_fail() { @Test public void find_specificTasks() throws IllegalArgumentException, IllegalValueException { - assertFindDeadlineResult("find d SOME", td.deadline2); - assertFindFloatingTaskResult("find f tell", td.floatingTask3); - + assertFindEventResult("find e with", td.event1, td.event2); //multiple results + assertResultMessage("2 tasks found!"); + + assertFindDeadlineResult("find d H", td.deadline1, td.deadline4, td.deadline5); + assertResultMessage("3 tasks found!"); + + assertFindFloatingTaskResult("find f tell", td.floatingTask3); + assertResultMessage("1 tasks found!"); + commandBox.runCommand("find e"); assertResultMessage(String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); // recognise as finding in event but no keywords } + /** + * Overload functions to assert result in each floating task, deadline and event list is correct + */ private void assertFindFloatingTaskResult(String command, TestFloatingTask... expectedHits ) { commandBox.runCommand(command); assertFloatingTaskListSize(expectedHits.length); - assertResultMessage(expectedHits.length + " tasks found!"); assertTrue(floatingTaskListPanel.isListMatching(expectedHits)); } private void assertFindDeadlineResult(String command, TestDeadline... expectedHits ) { commandBox.runCommand(command); assertDeadlineListSize(expectedHits.length); - assertResultMessage(expectedHits.length + " tasks found!"); assertTrue(deadlineListPanel.isListMatching(expectedHits)); } private void assertFindEventResult(String command, TestEvent... expectedHits ) throws IllegalArgumentException, IllegalValueException { commandBox.runCommand(command); assertEventListSize(expectedHits.length); - assertResultMessage(expectedHits.length + " tasks found!"); assertTrue(eventListPanel.isListMatching(expectedHits)); }