Skip to content

Commit

Permalink
Merge pull request #547 from Ferusel/tingkai/fix-grammar-sort-find
Browse files Browse the repository at this point in the history
Fix grammar
  • Loading branch information
bryanljx authored Nov 7, 2022
2 parents ef0d62f + a5561e0 commit e5d817f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
12 changes: 9 additions & 3 deletions src/main/java/seedu/foodrem/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ public class Messages {
public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command. Enter \"help\" to view all commands.";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_ITEMS_DISPLAYED_INDEX = "The item index provided is invalid.";
// TODO: Fix "1 items listed" grammar bug instead of "1 item listed"
public static final String MESSAGE_ITEMS_LISTED_OVERVIEW = "%1$d items listed!";
// TODO: Fix "1 items sorted" grammar bug instead of "1 item sorted"

// Singular
public static final String MESSAGE_ITEMS_LISTED_OVERVIEW = "%1$d item listed!";
public static final String MESSAGE_ITEM_SORTED_OVERVIEW = "%1$d item sorted!";
public static final String MESSAGE_ITEM_FILTERED_OVERVIEW = "%1$d item after filtering!";

// Plural or Zero
public static final String MESSAGE_ITEM_LISTED_OVERVIEW = "%1$d items listed!";
public static final String MESSAGE_ITEMS_SORTED_OVERVIEW = "%1$d items sorted!";
public static final String MESSAGE_ITEMS_FILTERED_OVERVIEW = "%1$d items after filtering!";

public static final String MESSAGE_NON_POSITIVE_INDEX =
"The index of an item should be a positive number.";
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public CommandResult<FilterByTag> execute(Model model) throws CommandException {

model.updateFilteredItemList(predicate);
String primaryMessage = "Filtered by tag:";
String secondaryMessage = String.format("%s items filtered", model.getCurrentList().size());
String secondaryMessage = String.format(model.getCurrentList().size() == 1
? "%s item filtered"
: "%s items filtered",
model.getCurrentList().size());
return CommandResult.from(new FilterByTag(tag, primaryMessage, secondaryMessage));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ public CommandResult<String> execute(Model model) {
requireNonNull(model);
model.updateFilteredItemList(predicate);
return CommandResult.from(
String.format(Messages.MESSAGE_ITEMS_LISTED_OVERVIEW, model.getCurrentList().size()));
String.format(model.getCurrentList().size() == 1
? Messages.MESSAGE_ITEM_FILTERED_OVERVIEW
: Messages.MESSAGE_ITEMS_FILTERED_OVERVIEW,
model.getCurrentList().size()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public SortCommand(Comparator<Item> comparator) {
public CommandResult<String> execute(Model model) {
requireNonNull(model);
model.updateSortedItemList(comparator);
return CommandResult.from(String.format(Messages.MESSAGE_ITEMS_SORTED_OVERVIEW,
return CommandResult.from(String.format(model.getCurrentList().size() == 1
? Messages.MESSAGE_ITEM_SORTED_OVERVIEW
: Messages.MESSAGE_ITEMS_SORTED_OVERVIEW,
model.getCurrentList().size()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static seedu.foodrem.commons.core.Messages.MESSAGE_ITEMS_LISTED_OVERVIEW;
import static seedu.foodrem.commons.core.Messages.MESSAGE_ITEMS_FILTERED_OVERVIEW;
import static seedu.foodrem.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.foodrem.testutil.TypicalFoodRem.getTypicalFoodRem;
import static seedu.foodrem.testutil.TypicalItems.CUCUMBERS;
Expand Down Expand Up @@ -54,7 +54,7 @@ public void equals() {

@Test
public void execute_zeroKeywords_noItemsFound() {
String expectedMessage = String.format(MESSAGE_ITEMS_LISTED_OVERVIEW, 2);
String expectedMessage = String.format(MESSAGE_ITEMS_FILTERED_OVERVIEW, 2);
NameContainsKeywordsPredicate predicate = preparePredicate(" ");
FindCommand command = new FindCommand(predicate);
expectedModel.updateFilteredItemList(predicate);
Expand All @@ -63,8 +63,8 @@ public void execute_zeroKeywords_noItemsFound() {
}

@Test
public void execute_multipleKeywords_multipleItemsFound() {
String expectedMessage = String.format(MESSAGE_ITEMS_LISTED_OVERVIEW, 0);
public void execute_multipleKeywords_zeroItemsFound() {
String expectedMessage = String.format(MESSAGE_ITEMS_FILTERED_OVERVIEW, 0);
NameContainsKeywordsPredicate predicate = preparePredicate("Potatoes Cucumbers Carrots");
FindCommand command = new FindCommand(predicate);
expectedModel.updateFilteredItemList(predicate);
Expand Down

0 comments on commit e5d817f

Please sign in to comment.