From c984b9806e6fcf8aa6da68aa7549075303944efc Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 7 Apr 2024 05:35:15 +0800 Subject: [PATCH 01/59] Changed User Guide to include Quote Command --- src/main/java/seedu/binbash/command/QuoteCommand.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/main/java/seedu/binbash/command/QuoteCommand.java diff --git a/src/main/java/seedu/binbash/command/QuoteCommand.java b/src/main/java/seedu/binbash/command/QuoteCommand.java new file mode 100644 index 0000000000..4b66bdd866 --- /dev/null +++ b/src/main/java/seedu/binbash/command/QuoteCommand.java @@ -0,0 +1,4 @@ +package seedu.binbash.command; + +public class QuoteCommand { +} From 225e1fea8bf63f6bf9142def1a9670cb84c5507b Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 7 Apr 2024 05:36:14 +0800 Subject: [PATCH 02/59] Updated User Guide with Quote Command --- docs/UserGuide.md | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 5eabd5be4c..57068e8aac 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -324,7 +324,7 @@ Examples: Noted! I have added the following item into your inventory: [P][O] milk - description: to make cofee + description: to make coffee quantity: 2 cost price: $1.30 expiry date: 03-10-2024 @@ -651,6 +651,18 @@ Format: `bye` * [Back to table of contents](#table-of-contents) --- +### Getting Inspirational Quotes: `quote` + +> This command fetches a random quote to uplift your spirits. + +Need a little motivation? The quote command retrieves a random inspirational message to brighten your day. Whether you're feeling stuck or just need a boost, BinBash has got you covered! + +Format: `quote` + +> ℹ️ BinBash brings you a variety of inspiring messages to keep you motivated throughout your inventory management journey. So go ahead, type quote and let the positivity flow! +* [Back to table of contents](#table-of-contents) +--- + ### Saving and Loading data Unsure as to how you can save your BinBash data? Don't worry! Your data is automatically saved to your local storage. No manual saving of data is required. @@ -668,15 +680,16 @@ Similarly, your saved data will be automatically loaded into BinBash when you st ## Command Summary -| **Commands** | **Usage** | -|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| **add** | `add -n ITEM_NAME -d ITEM_DESCRIPTION -q ITEM_QUANTITY -e EXPIRATION_DATE -s SALE_PRICE -c COST_PRICE` `add -op -n ITEM_NAME -d ITEM_DESCRIPTION -q ITEM_QUANTITY -e EXPIRY_DATE -s SALE_PRICE -t THRESHOLD` | -|**search** | `search KEYWORD` | -| **list** | `list` `list -c` `list -s` `list -e` | -| **delete** | `delete ITEM_INDEX` , `delete ITEM_NAME` | -| **profit** | `profit` | -| **bye** | `bye` | -| **sell** | `sell -n ITEM_NAME -q ITEM_QUANTITY` `sell -n ITEM_INDEX -q ITEM_QUANTITY` +| **Commands** | **Usage** | +|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| **add** | `add -n ITEM_NAME -d ITEM_DESCRIPTION -q ITEM_QUANTITY -e EXPIRATION_DATE -s SALE_PRICE -c COST_PRICE` `add -op -n ITEM_NAME -d ITEM_DESCRIPTION -q ITEM_QUANTITY -e EXPIRY_DATE -s SALE_PRICE -t THRESHOLD` | +| **search** | `search KEYWORD` | +| **list** | `list` `list -c` `list -s` `list -e` | +| **delete** | `delete ITEM_INDEX` , `delete ITEM_NAME` | +| **profit** | `profit` | +| **bye** | `bye` | +| **quote** | `quote` | +| **sell** | `sell -n ITEM_NAME -q ITEM_QUANTITY` `sell -n ITEM_INDEX -q ITEM_QUANTITY` | * [Back to table of contents](#table-of-contents) --- From 7d8f58298a9be1902446f8650fe72c955048f86f Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 7 Apr 2024 05:38:17 +0800 Subject: [PATCH 03/59] Added in Quote Command --- src/main/java/seedu/binbash/BinBash.java | 20 +++-- .../seedu/binbash/command/QuoteCommand.java | 30 ++++++- .../java/seedu/binbash/parser/Parser.java | 18 ++-- src/main/java/seedu/binbash/ui/Ui.java | 83 +++++++++++++++++-- 4 files changed, 128 insertions(+), 23 deletions(-) diff --git a/src/main/java/seedu/binbash/BinBash.java b/src/main/java/seedu/binbash/BinBash.java index 7481ffc916..ea98c19487 100644 --- a/src/main/java/seedu/binbash/BinBash.java +++ b/src/main/java/seedu/binbash/BinBash.java @@ -2,6 +2,7 @@ import seedu.binbash.command.ByeCommand; +import seedu.binbash.command.QuoteCommand; import seedu.binbash.command.Command; import seedu.binbash.exceptions.BinBashException; import seedu.binbash.inventory.ItemList; @@ -11,11 +12,11 @@ import seedu.binbash.ui.Ui; public class BinBash { - private Ui userInterface; - private ItemList itemList; - private Parser inputParser; - private Storage storage; - private BinBashLogger logger; + private final Ui userInterface; + private final ItemList itemList; + private final Parser inputParser; + private final Storage storage; + private final BinBashLogger logger; public BinBash() { logger = new BinBashLogger(BinBash.class.getName()); @@ -30,14 +31,18 @@ private void run() { userInterface.greet(); userInterface.talk(itemList.getProfitMargin()); + userInterface.talk(userInterface.getRandomMessage()); while (userInterface.isUserActive()) { String userInput = userInterface.readUserCommand(); + userInterface.handleUserInput(userInput, itemList); // Call handleUserInput try { Command userCommand = inputParser.parseCommand(userInput); if (userCommand instanceof ByeCommand) { userInterface.setUserAsInactive(); + } else if (userCommand instanceof QuoteCommand) { // Handle QuoteCommand + userCommand.execute(itemList); } userCommand.execute(itemList); @@ -49,11 +54,14 @@ private void run() { } catch (BinBashException e) { userInterface.talk(e.getMessage()); + logger.warning("BinBashException occurred: " + e.getMessage()); // Logging + } catch (Exception e) { + logger.severe("Unexpected error occurred: " + e.getMessage()); // Logging } } logger.info("BinBash exiting..."); } - + /** * Main entry-point for the BinBash application. */ diff --git a/src/main/java/seedu/binbash/command/QuoteCommand.java b/src/main/java/seedu/binbash/command/QuoteCommand.java index 4b66bdd866..fce66bf44d 100644 --- a/src/main/java/seedu/binbash/command/QuoteCommand.java +++ b/src/main/java/seedu/binbash/command/QuoteCommand.java @@ -1,4 +1,32 @@ package seedu.binbash.command; -public class QuoteCommand { +import seedu.binbash.inventory.ItemList; +import seedu.binbash.ui.Ui; +import seedu.binbash.logger.BinBashLogger; + +public class QuoteCommand extends Command { + private Ui ui; + + public QuoteCommand() { + commandLogger = new BinBashLogger(QuoteCommand.class.getName()); + commandLogger.info("Creating Quote Command..."); + } + + @Override + public boolean execute(ItemList itemList) { + if (ui == null) { + throw new IllegalStateException("Ui is not initialized. Please initialize it before calling execute()"); + } + + String randomMessage = ui.getRandomMessage(); + ui.talk(randomMessage); + executionUiOutput = randomMessage; + hasToSave = false; // Assuming you don't need to save after executing the Quote command + return true; + } + + // Setter method to initialize Ui + public void setUi(Ui ui) { + this.ui = ui; + } } diff --git a/src/main/java/seedu/binbash/parser/Parser.java b/src/main/java/seedu/binbash/parser/Parser.java index 771dbafc68..95b40975cd 100644 --- a/src/main/java/seedu/binbash/parser/Parser.java +++ b/src/main/java/seedu/binbash/parser/Parser.java @@ -8,6 +8,7 @@ import seedu.binbash.command.SearchCommand; import seedu.binbash.command.ListCommand; import seedu.binbash.command.ProfitCommand; +import seedu.binbash.command.QuoteCommand; import seedu.binbash.exceptions.InvalidCommandException; import seedu.binbash.exceptions.InvalidArgumentException; @@ -24,13 +25,13 @@ */ public class Parser { protected static final DateTimeFormatter EXPECTED_INPUT_DATE_FORMAT = DateTimeFormatter.ofPattern("dd-MM-yyyy"); - private AddCommandParser addCommandParser; - private SearchCommandParser searchCommandParser; - private RestockCommandParser restockCommandParser; - private SellCommandParser sellCommandParser; - private ListCommandParser listCommandParser; - private UpdateCommandParser updateCommandParser; - private DeleteCommandParser deleteCommandParser; + private final AddCommandParser addCommandParser; + private final SearchCommandParser searchCommandParser; + private final RestockCommandParser restockCommandParser; + private final SellCommandParser sellCommandParser; + private final ListCommandParser listCommandParser; + private final UpdateCommandParser updateCommandParser; + private final DeleteCommandParser deleteCommandParser; public Parser() { addCommandParser = new AddCommandParser(); @@ -95,6 +96,8 @@ public Command parseCommand(String userInput) throws InvalidCommandException { return parseUpdateCommand(commandArgs); case "profit": return new ProfitCommand(); + case "quote": + return new QuoteCommand(); default: throw new InvalidCommandException("Invalid command: " + commandString); } @@ -159,4 +162,5 @@ private ListCommand parseListCommand(String[] commandArgs) throws InvalidCommand throw new InvalidCommandException(e.getMessage()); } } + } diff --git a/src/main/java/seedu/binbash/ui/Ui.java b/src/main/java/seedu/binbash/ui/Ui.java index e80d58781f..dcc96ec084 100644 --- a/src/main/java/seedu/binbash/ui/Ui.java +++ b/src/main/java/seedu/binbash/ui/Ui.java @@ -1,5 +1,8 @@ package seedu.binbash.ui; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Random; import org.jline.reader.LineReader; import org.jline.reader.LineReaderBuilder; import org.jline.reader.EndOfFileException; @@ -7,9 +10,9 @@ import org.jline.builtins.Completers.OptDesc; import org.jline.terminal.Terminal; import org.jline.terminal.TerminalBuilder; - +import seedu.binbash.command.QuoteCommand; +import seedu.binbash.inventory.ItemList; import seedu.binbash.logger.BinBashLogger; - import java.io.IOException; import java.util.ArrayList; @@ -23,21 +26,65 @@ public class Ui { private static final String WELCOME_MESSAGE = "Welcome to BinBash!"; private static final String LINE_DIVIDER = "-------------------------------------------------------------"; private static final BinBashLogger UILOGGER = new BinBashLogger(Ui.class.getName()); + private static final Random RANDOM = new Random(); private static LineReader inputReader; private static boolean isUserActive; + private static final String[] CUSTOM_MESSAGES = { + "Hope you have a good day of inventory management.", + "Have a nice day!", + "Welcome back to BinBash!", + "Make today amazing!", + "Enjoy your time with BinBash!", + "Wishing you a productive day!", + "Get ready for some BinBash fun!", + "Let's make today great!", + "Time to conquer your inventory!", + "Sending positive vibes your way!", + "Welcome to another BinBash adventure!", + "Stay positive and keep BinBashing!", + "Today's a good day to organize!", + "You've got this!", + "Hope your day is BinBash-tastic!", + "Get ready to rock your inventory!", + "BinBash is here to help!", + "Hope you find everything you need!", + "Have a wonderful day ahead!", + "Start your day with a smile!", + "Sending you BinBash blessings!", + "Let's make magic happen!", + "Embrace the BinBash journey!", + "You're awesome, just like BinBash!", + "Seize the day with BinBash!", + "Welcome to BinBash excellence!", + "Time to unleash your inventory power!", + "Hope you have a blast with BinBash!", + "Today's a good day to BinBash!", + "Stay motivated and BinBash on!", + "Enjoy every moment with BinBash!", + "Make today memorable!", + "Let's create some BinBash miracles!", + "Believe in yourself and BinBash!", + "Welcome to the world of BinBash!", + "Today's forecast: BinBash brilliance!", + "BinBash wishes you a fantastic day!", + "May your day be filled with BinBash joy!", + "Let's make today legendary!", + "Stay positive and BinBash strong!" + }; + public Ui(ArrayList> allCommandsOptionDescriptions) { System.setProperty("org.jline.terminal.exec.redirectPipeCreationMode", "native"); try { Terminal userTerminal = TerminalBuilder.builder() - .system(true) - .dumb(true) // TODO: omit and catch using logger - .build(); + .system(true) + .dumb(true) // TODO: omit and catch using logger + .build(); inputReader = LineReaderBuilder.builder() - .terminal(userTerminal) - .completer(new CommandCompleter(allCommandsOptionDescriptions)) - .build(); + .terminal(userTerminal) + .completer(new CommandCompleter(allCommandsOptionDescriptions)) + .build(); } catch (IOException e) { UILOGGER.info("failed to get system terminal!"); throw new RuntimeException(e); @@ -66,10 +113,28 @@ public String readUserCommand() { } public void greet() { - talk(LOGO + WELCOME_MESSAGE); + LocalDateTime now = LocalDateTime.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + String formattedDateTime = now.format(formatter); + + String startupMessage = "BinBash started on: " + formattedDateTime; + talk(startupMessage + NEWLINE + LOGO + WELCOME_MESSAGE); } public void talk(String line) { System.out.println(LINE_DIVIDER + NEWLINE + line + NEWLINE + LINE_DIVIDER); } + + public String getRandomMessage() { + int randomIndex = RANDOM.nextInt(CUSTOM_MESSAGES.length); + return CUSTOM_MESSAGES[randomIndex]; + } + + public void handleUserInput(String userInput, ItemList itemList) { + if (userInput.trim().equalsIgnoreCase("quote")) { + QuoteCommand quoteCommand = new QuoteCommand(); + quoteCommand.setUi(this); // Assuming 'this' refers to the current Ui object + quoteCommand.execute(itemList); + } + } } From 93f2da315348a31c2614b9652d06e1f959d6dd1b Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 7 Apr 2024 06:08:19 +0800 Subject: [PATCH 04/59] Removed unecessary code --- src/main/java/seedu/binbash/BinBash.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/seedu/binbash/BinBash.java b/src/main/java/seedu/binbash/BinBash.java index ea98c19487..2e699c6503 100644 --- a/src/main/java/seedu/binbash/BinBash.java +++ b/src/main/java/seedu/binbash/BinBash.java @@ -55,8 +55,6 @@ private void run() { } catch (BinBashException e) { userInterface.talk(e.getMessage()); logger.warning("BinBashException occurred: " + e.getMessage()); // Logging - } catch (Exception e) { - logger.severe("Unexpected error occurred: " + e.getMessage()); // Logging } } logger.info("BinBash exiting..."); From 5a749db05f283b5c8bb575972342d02d624eef72 Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 7 Apr 2024 07:27:35 +0800 Subject: [PATCH 05/59] Added Quotes Command --- docs/UserGuide.md | 12 ++++++------ src/main/java/seedu/binbash/BinBash.java | 9 ++++++--- .../{QuoteCommand.java => QuotesCommand.java} | 10 +++++----- src/main/java/seedu/binbash/parser/Parser.java | 6 +++--- src/main/java/seedu/binbash/ui/Ui.java | 6 +++--- 5 files changed, 23 insertions(+), 20 deletions(-) rename src/main/java/seedu/binbash/command/{QuoteCommand.java => QuotesCommand.java} (74%) diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 57068e8aac..185c02a87e 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -651,15 +651,15 @@ Format: `bye` * [Back to table of contents](#table-of-contents) --- -### Getting Inspirational Quotes: `quote` +### Getting Inspirational Quotes: `quotes` -> This command fetches a random quote to uplift your spirits. +> This command fetches random quotes to uplift your spirits. -Need a little motivation? The quote command retrieves a random inspirational message to brighten your day. Whether you're feeling stuck or just need a boost, BinBash has got you covered! +Need a little motivation? The quote command retrieves random inspirational messages to brighten your day. Whether you're feeling stuck or just need a boost, BinBash has got you covered! -Format: `quote` +Format: `quotes` -> ℹ️ BinBash brings you a variety of inspiring messages to keep you motivated throughout your inventory management journey. So go ahead, type quote and let the positivity flow! +> ℹ️ BinBash brings you a variety of inspiring messages to keep you motivated throughout your inventory management journey. So go ahead, type quotes and let the positivity flow! * [Back to table of contents](#table-of-contents) --- @@ -688,7 +688,7 @@ Similarly, your saved data will be automatically loaded into BinBash when you st | **delete** | `delete ITEM_INDEX` , `delete ITEM_NAME` | | **profit** | `profit` | | **bye** | `bye` | -| **quote** | `quote` | +| **quotes** | `quotes` | | **sell** | `sell -n ITEM_NAME -q ITEM_QUANTITY` `sell -n ITEM_INDEX -q ITEM_QUANTITY` | * [Back to table of contents](#table-of-contents) diff --git a/src/main/java/seedu/binbash/BinBash.java b/src/main/java/seedu/binbash/BinBash.java index 2e699c6503..df498968c7 100644 --- a/src/main/java/seedu/binbash/BinBash.java +++ b/src/main/java/seedu/binbash/BinBash.java @@ -2,7 +2,7 @@ import seedu.binbash.command.ByeCommand; -import seedu.binbash.command.QuoteCommand; +import seedu.binbash.command.QuotesCommand; import seedu.binbash.command.Command; import seedu.binbash.exceptions.BinBashException; import seedu.binbash.inventory.ItemList; @@ -41,11 +41,14 @@ private void run() { if (userCommand instanceof ByeCommand) { userInterface.setUserAsInactive(); - } else if (userCommand instanceof QuoteCommand) { // Handle QuoteCommand + } else if (userCommand instanceof QuotesCommand) { // Handle QuoteCommand + // Initialize Ui before executing QuoteCommand + ((QuotesCommand) userCommand).setUi(userInterface); + userCommand.execute(itemList); + } else { userCommand.execute(itemList); } - userCommand.execute(itemList); userInterface.talk(userCommand.getExecutionUiOutput()); if (userCommand.hasToSave()) { diff --git a/src/main/java/seedu/binbash/command/QuoteCommand.java b/src/main/java/seedu/binbash/command/QuotesCommand.java similarity index 74% rename from src/main/java/seedu/binbash/command/QuoteCommand.java rename to src/main/java/seedu/binbash/command/QuotesCommand.java index fce66bf44d..be4fe4363c 100644 --- a/src/main/java/seedu/binbash/command/QuoteCommand.java +++ b/src/main/java/seedu/binbash/command/QuotesCommand.java @@ -4,12 +4,12 @@ import seedu.binbash.ui.Ui; import seedu.binbash.logger.BinBashLogger; -public class QuoteCommand extends Command { +public class QuotesCommand extends Command { private Ui ui; - public QuoteCommand() { - commandLogger = new BinBashLogger(QuoteCommand.class.getName()); - commandLogger.info("Creating Quote Command..."); + public QuotesCommand() { + commandLogger = new BinBashLogger(QuotesCommand.class.getName()); + commandLogger.info("Creating Quotes Command..."); } @Override @@ -21,7 +21,7 @@ public boolean execute(ItemList itemList) { String randomMessage = ui.getRandomMessage(); ui.talk(randomMessage); executionUiOutput = randomMessage; - hasToSave = false; // Assuming you don't need to save after executing the Quote command + hasToSave = false; // Assuming you don't need to save after executing the Quotes command return true; } diff --git a/src/main/java/seedu/binbash/parser/Parser.java b/src/main/java/seedu/binbash/parser/Parser.java index 95b40975cd..7619744d4e 100644 --- a/src/main/java/seedu/binbash/parser/Parser.java +++ b/src/main/java/seedu/binbash/parser/Parser.java @@ -8,7 +8,7 @@ import seedu.binbash.command.SearchCommand; import seedu.binbash.command.ListCommand; import seedu.binbash.command.ProfitCommand; -import seedu.binbash.command.QuoteCommand; +import seedu.binbash.command.QuotesCommand; import seedu.binbash.exceptions.InvalidCommandException; import seedu.binbash.exceptions.InvalidArgumentException; @@ -96,8 +96,8 @@ public Command parseCommand(String userInput) throws InvalidCommandException { return parseUpdateCommand(commandArgs); case "profit": return new ProfitCommand(); - case "quote": - return new QuoteCommand(); + case "quotes": + return new QuotesCommand(); default: throw new InvalidCommandException("Invalid command: " + commandString); } diff --git a/src/main/java/seedu/binbash/ui/Ui.java b/src/main/java/seedu/binbash/ui/Ui.java index dcc96ec084..c3736ad6e2 100644 --- a/src/main/java/seedu/binbash/ui/Ui.java +++ b/src/main/java/seedu/binbash/ui/Ui.java @@ -10,7 +10,7 @@ import org.jline.builtins.Completers.OptDesc; import org.jline.terminal.Terminal; import org.jline.terminal.TerminalBuilder; -import seedu.binbash.command.QuoteCommand; +import seedu.binbash.command.QuotesCommand; import seedu.binbash.inventory.ItemList; import seedu.binbash.logger.BinBashLogger; import java.io.IOException; @@ -131,8 +131,8 @@ public String getRandomMessage() { } public void handleUserInput(String userInput, ItemList itemList) { - if (userInput.trim().equalsIgnoreCase("quote")) { - QuoteCommand quoteCommand = new QuoteCommand(); + if (userInput.trim().equalsIgnoreCase("quotes")) { + QuotesCommand quoteCommand = new QuotesCommand(); quoteCommand.setUi(this); // Assuming 'this' refers to the current Ui object quoteCommand.execute(itemList); } From fcb92a003003785cf4e3d4f0834b292b3cb605b8 Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 7 Apr 2024 19:10:40 +0800 Subject: [PATCH 06/59] Added Quote Command --- docs/UserGuide.md | 10 +++++----- src/main/java/seedu/binbash/BinBash.java | 7 +++---- .../{QuotesCommand.java => QuoteCommand.java} | 7 +++---- src/main/java/seedu/binbash/parser/Parser.java | 6 +++--- src/main/java/seedu/binbash/ui/Ui.java | 12 +----------- 5 files changed, 15 insertions(+), 27 deletions(-) rename src/main/java/seedu/binbash/command/{QuotesCommand.java => QuoteCommand.java} (80%) diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 185c02a87e..a9801d3c1e 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -651,15 +651,15 @@ Format: `bye` * [Back to table of contents](#table-of-contents) --- -### Getting Inspirational Quotes: `quotes` +### Getting Inspirational Quotes: `quote` -> This command fetches random quotes to uplift your spirits. +> This command fetches a random quote to uplift your spirits. Need a little motivation? The quote command retrieves random inspirational messages to brighten your day. Whether you're feeling stuck or just need a boost, BinBash has got you covered! -Format: `quotes` +Format: `quote` -> ℹ️ BinBash brings you a variety of inspiring messages to keep you motivated throughout your inventory management journey. So go ahead, type quotes and let the positivity flow! +> ℹ️ BinBash brings you a variety of inspiring messages to keep you motivated throughout your inventory management journey. So go ahead, type quote and let the positivity flow! * [Back to table of contents](#table-of-contents) --- @@ -688,7 +688,7 @@ Similarly, your saved data will be automatically loaded into BinBash when you st | **delete** | `delete ITEM_INDEX` , `delete ITEM_NAME` | | **profit** | `profit` | | **bye** | `bye` | -| **quotes** | `quotes` | +| **quote** | `quote` | | **sell** | `sell -n ITEM_NAME -q ITEM_QUANTITY` `sell -n ITEM_INDEX -q ITEM_QUANTITY` | * [Back to table of contents](#table-of-contents) diff --git a/src/main/java/seedu/binbash/BinBash.java b/src/main/java/seedu/binbash/BinBash.java index df498968c7..eaea1a3587 100644 --- a/src/main/java/seedu/binbash/BinBash.java +++ b/src/main/java/seedu/binbash/BinBash.java @@ -2,7 +2,7 @@ import seedu.binbash.command.ByeCommand; -import seedu.binbash.command.QuotesCommand; +import seedu.binbash.command.QuoteCommand; import seedu.binbash.command.Command; import seedu.binbash.exceptions.BinBashException; import seedu.binbash.inventory.ItemList; @@ -35,15 +35,14 @@ private void run() { while (userInterface.isUserActive()) { String userInput = userInterface.readUserCommand(); - userInterface.handleUserInput(userInput, itemList); // Call handleUserInput try { Command userCommand = inputParser.parseCommand(userInput); if (userCommand instanceof ByeCommand) { userInterface.setUserAsInactive(); - } else if (userCommand instanceof QuotesCommand) { // Handle QuoteCommand + } else if (userCommand instanceof QuoteCommand) { // Handle QuoteCommand // Initialize Ui before executing QuoteCommand - ((QuotesCommand) userCommand).setUi(userInterface); + ((QuoteCommand) userCommand).setUi(userInterface); userCommand.execute(itemList); } else { userCommand.execute(itemList); diff --git a/src/main/java/seedu/binbash/command/QuotesCommand.java b/src/main/java/seedu/binbash/command/QuoteCommand.java similarity index 80% rename from src/main/java/seedu/binbash/command/QuotesCommand.java rename to src/main/java/seedu/binbash/command/QuoteCommand.java index be4fe4363c..a54d83fa4f 100644 --- a/src/main/java/seedu/binbash/command/QuotesCommand.java +++ b/src/main/java/seedu/binbash/command/QuoteCommand.java @@ -4,11 +4,11 @@ import seedu.binbash.ui.Ui; import seedu.binbash.logger.BinBashLogger; -public class QuotesCommand extends Command { +public class QuoteCommand extends Command { private Ui ui; - public QuotesCommand() { - commandLogger = new BinBashLogger(QuotesCommand.class.getName()); + public QuoteCommand() { + commandLogger = new BinBashLogger(QuoteCommand.class.getName()); commandLogger.info("Creating Quotes Command..."); } @@ -19,7 +19,6 @@ public boolean execute(ItemList itemList) { } String randomMessage = ui.getRandomMessage(); - ui.talk(randomMessage); executionUiOutput = randomMessage; hasToSave = false; // Assuming you don't need to save after executing the Quotes command return true; diff --git a/src/main/java/seedu/binbash/parser/Parser.java b/src/main/java/seedu/binbash/parser/Parser.java index 7619744d4e..95b40975cd 100644 --- a/src/main/java/seedu/binbash/parser/Parser.java +++ b/src/main/java/seedu/binbash/parser/Parser.java @@ -8,7 +8,7 @@ import seedu.binbash.command.SearchCommand; import seedu.binbash.command.ListCommand; import seedu.binbash.command.ProfitCommand; -import seedu.binbash.command.QuotesCommand; +import seedu.binbash.command.QuoteCommand; import seedu.binbash.exceptions.InvalidCommandException; import seedu.binbash.exceptions.InvalidArgumentException; @@ -96,8 +96,8 @@ public Command parseCommand(String userInput) throws InvalidCommandException { return parseUpdateCommand(commandArgs); case "profit": return new ProfitCommand(); - case "quotes": - return new QuotesCommand(); + case "quote": + return new QuoteCommand(); default: throw new InvalidCommandException("Invalid command: " + commandString); } diff --git a/src/main/java/seedu/binbash/ui/Ui.java b/src/main/java/seedu/binbash/ui/Ui.java index c3736ad6e2..46d30b0211 100644 --- a/src/main/java/seedu/binbash/ui/Ui.java +++ b/src/main/java/seedu/binbash/ui/Ui.java @@ -10,8 +10,6 @@ import org.jline.builtins.Completers.OptDesc; import org.jline.terminal.Terminal; import org.jline.terminal.TerminalBuilder; -import seedu.binbash.command.QuotesCommand; -import seedu.binbash.inventory.ItemList; import seedu.binbash.logger.BinBashLogger; import java.io.IOException; import java.util.ArrayList; @@ -31,7 +29,7 @@ public class Ui { private static LineReader inputReader; private static boolean isUserActive; - private static final String[] CUSTOM_MESSAGES = { + private final String[] CUSTOM_MESSAGES = { "Hope you have a good day of inventory management.", "Have a nice day!", "Welcome back to BinBash!", @@ -129,12 +127,4 @@ public String getRandomMessage() { int randomIndex = RANDOM.nextInt(CUSTOM_MESSAGES.length); return CUSTOM_MESSAGES[randomIndex]; } - - public void handleUserInput(String userInput, ItemList itemList) { - if (userInput.trim().equalsIgnoreCase("quotes")) { - QuotesCommand quoteCommand = new QuotesCommand(); - quoteCommand.setUi(this); // Assuming 'this' refers to the current Ui object - quoteCommand.execute(itemList); - } - } } From 253780c34d43451190ea1f02fa57fbd1cc3c21fa Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 7 Apr 2024 19:46:35 +0800 Subject: [PATCH 07/59] Fixed Checkstyle Error --- src/main/java/seedu/binbash/ui/Ui.java | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/seedu/binbash/ui/Ui.java b/src/main/java/seedu/binbash/ui/Ui.java index 46d30b0211..84cb1e3a3c 100644 --- a/src/main/java/seedu/binbash/ui/Ui.java +++ b/src/main/java/seedu/binbash/ui/Ui.java @@ -1,7 +1,5 @@ package seedu.binbash.ui; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; import java.util.Random; import org.jline.reader.LineReader; import org.jline.reader.LineReaderBuilder; @@ -29,7 +27,7 @@ public class Ui { private static LineReader inputReader; private static boolean isUserActive; - private final String[] CUSTOM_MESSAGES = { + private final String[] customMessages = { "Hope you have a good day of inventory management.", "Have a nice day!", "Welcome back to BinBash!", @@ -72,6 +70,14 @@ public class Ui { "Stay positive and BinBash strong!" }; + /** + * Constructor; note that it need only be called once as there should be no more than a single + * instance per program run. + * + * @param allCommandsOptionDescriptions A list of option descriptions for all commands in this program. + * @return The current instance of Ui. + * @throws RuntimeException If fails to get an instance of the system terminal. + */ public Ui(ArrayList> allCommandsOptionDescriptions) { System.setProperty("org.jline.terminal.exec.redirectPipeCreationMode", "native"); try { @@ -111,11 +117,7 @@ public String readUserCommand() { } public void greet() { - LocalDateTime now = LocalDateTime.now(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - String formattedDateTime = now.format(formatter); - - String startupMessage = "BinBash started on: " + formattedDateTime; + String startupMessage = "BinBash started up!"; talk(startupMessage + NEWLINE + LOGO + WELCOME_MESSAGE); } @@ -124,7 +126,7 @@ public void talk(String line) { } public String getRandomMessage() { - int randomIndex = RANDOM.nextInt(CUSTOM_MESSAGES.length); - return CUSTOM_MESSAGES[randomIndex]; + int randomIndex = RANDOM.nextInt(customMessages.length); + return customMessages[randomIndex]; } } From 41782288f208da8376f66208cb332bd0092d0290 Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 7 Apr 2024 19:50:27 +0800 Subject: [PATCH 08/59] merge remote changes --- untitled/.gitignore | 29 +++++++++++++++++++++++++++++ untitled/.idea/.gitignore | 3 +++ untitled/.idea/misc.xml | 6 ++++++ untitled/.idea/modules.xml | 8 ++++++++ untitled/.idea/vcs.xml | 6 ++++++ untitled/src/Main.java | 5 +++++ 6 files changed, 57 insertions(+) create mode 100644 untitled/.gitignore create mode 100644 untitled/.idea/.gitignore create mode 100644 untitled/.idea/misc.xml create mode 100644 untitled/.idea/modules.xml create mode 100644 untitled/.idea/vcs.xml create mode 100644 untitled/src/Main.java diff --git a/untitled/.gitignore b/untitled/.gitignore new file mode 100644 index 0000000000..f68d109965 --- /dev/null +++ b/untitled/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/untitled/.idea/.gitignore b/untitled/.idea/.gitignore new file mode 100644 index 0000000000..26d33521af --- /dev/null +++ b/untitled/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/untitled/.idea/misc.xml b/untitled/.idea/misc.xml new file mode 100644 index 0000000000..e0844bc7be --- /dev/null +++ b/untitled/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/untitled/.idea/modules.xml b/untitled/.idea/modules.xml new file mode 100644 index 0000000000..3007daed6a --- /dev/null +++ b/untitled/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/untitled/.idea/vcs.xml b/untitled/.idea/vcs.xml new file mode 100644 index 0000000000..6c0b863585 --- /dev/null +++ b/untitled/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/untitled/src/Main.java b/untitled/src/Main.java new file mode 100644 index 0000000000..3e59c38fbd --- /dev/null +++ b/untitled/src/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file From 958a56b22fdbd9e4574a11a01749a022692045e4 Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 7 Apr 2024 21:13:27 +0800 Subject: [PATCH 09/59] Fixed Null Error --- README.md | 12 ++++---- src/main/java/seedu/binbash/BinBash.java | 4 +-- .../seedu/binbash/command/QuoteCommand.java | 2 +- untitled/.gitignore | 29 ------------------- untitled/.idea/.gitignore | 3 -- untitled/.idea/misc.xml | 6 ---- untitled/.idea/modules.xml | 8 ----- untitled/.idea/vcs.xml | 6 ---- untitled/src/Main.java | 5 ---- 9 files changed, 8 insertions(+), 67 deletions(-) delete mode 100644 untitled/.gitignore delete mode 100644 untitled/.idea/.gitignore delete mode 100644 untitled/.idea/misc.xml delete mode 100644 untitled/.idea/modules.xml delete mode 100644 untitled/.idea/vcs.xml delete mode 100644 untitled/src/Main.java diff --git a/README.md b/README.md index b47df443d4..520fa880b7 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,8 @@ This is a project template for a greenfield Java project. It's named after the J Prerequisites: JDK 11 (use the exact version), update Intellij to the most recent version. 1. **Ensure Intellij JDK 11 is defined as an SDK**, as described [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk) -- this step is not needed if you have used JDK 11 in a previous Intellij project. -1. **Import the project _as a Gradle project_**, as described [here](https://se-education.org/guides/tutorials/intellijImportGradleProject.html). -1. **Verify the set up**: After the importing is complete, locate the `src/main/java/seedu/duke/Duke.java` file, right-click it, and choose `Run Duke.main()`. If the setup is correct, you should see something like the below: +2. **Import the project _as a Gradle project_**, as described [here](https://se-education.org/guides/tutorials/intellijImportGradleProject.html). +3. **Verify the set-up**: After the importing is complete, locate the `src/main/java/seedu/duke/Duke.java` file, right-click it, and choose `Run Duke.main()`. If the setup is correct, you should see something like the below: ``` > Task :compileJava > Task :processResources NO-SOURCE @@ -58,7 +58,7 @@ The project uses [GitHub actions](https://github.com/features/actions) for CI. W Steps for publishing documentation to the public: 1. If you are using this project template for an individual project, go your fork on GitHub.
If you are using this project template for a team project, go to the team fork on GitHub. -1. Click on the `settings` tab. -1. Scroll down to the `GitHub Pages` section. -1. Set the `source` as `master branch /docs folder`. -1. Optionally, use the `choose a theme` button to choose a theme for your documentation. +2. Click on the `settings` tab. +3. Scroll down to the `GitHub Pages` section. +4. Set the `source` as `master branch /docs folder`. +5. Optionally, use the `choose a theme` button to choose a theme for your documentation. diff --git a/src/main/java/seedu/binbash/BinBash.java b/src/main/java/seedu/binbash/BinBash.java index eaea1a3587..a31e92d35b 100644 --- a/src/main/java/seedu/binbash/BinBash.java +++ b/src/main/java/seedu/binbash/BinBash.java @@ -43,11 +43,9 @@ private void run() { } else if (userCommand instanceof QuoteCommand) { // Handle QuoteCommand // Initialize Ui before executing QuoteCommand ((QuoteCommand) userCommand).setUi(userInterface); - userCommand.execute(itemList); - } else { - userCommand.execute(itemList); } + userCommand.execute(itemList); userInterface.talk(userCommand.getExecutionUiOutput()); if (userCommand.hasToSave()) { diff --git a/src/main/java/seedu/binbash/command/QuoteCommand.java b/src/main/java/seedu/binbash/command/QuoteCommand.java index a54d83fa4f..f87536ac2f 100644 --- a/src/main/java/seedu/binbash/command/QuoteCommand.java +++ b/src/main/java/seedu/binbash/command/QuoteCommand.java @@ -9,7 +9,7 @@ public class QuoteCommand extends Command { public QuoteCommand() { commandLogger = new BinBashLogger(QuoteCommand.class.getName()); - commandLogger.info("Creating Quotes Command..."); + commandLogger.info("Creating Quote Command..."); } @Override diff --git a/untitled/.gitignore b/untitled/.gitignore deleted file mode 100644 index f68d109965..0000000000 --- a/untitled/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -### IntelliJ IDEA ### -out/ -!**/src/main/**/out/ -!**/src/test/**/out/ - -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache -bin/ -!**/src/main/**/bin/ -!**/src/test/**/bin/ - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ - -### VS Code ### -.vscode/ - -### Mac OS ### -.DS_Store \ No newline at end of file diff --git a/untitled/.idea/.gitignore b/untitled/.idea/.gitignore deleted file mode 100644 index 26d33521af..0000000000 --- a/untitled/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/untitled/.idea/misc.xml b/untitled/.idea/misc.xml deleted file mode 100644 index e0844bc7be..0000000000 --- a/untitled/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/untitled/.idea/modules.xml b/untitled/.idea/modules.xml deleted file mode 100644 index 3007daed6a..0000000000 --- a/untitled/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/untitled/.idea/vcs.xml b/untitled/.idea/vcs.xml deleted file mode 100644 index 6c0b863585..0000000000 --- a/untitled/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/untitled/src/Main.java b/untitled/src/Main.java deleted file mode 100644 index 3e59c38fbd..0000000000 --- a/untitled/src/Main.java +++ /dev/null @@ -1,5 +0,0 @@ -public class Main { - public static void main(String[] args) { - System.out.println("Hello world!"); - } -} \ No newline at end of file From c797aaa0946e22cb8ea4c88b6ea76f228c49e799 Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 7 Apr 2024 21:24:16 +0800 Subject: [PATCH 10/59] Added Tests For Quote Command --- src/test/java/seedu/binbash/parser/ParserTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/seedu/binbash/parser/ParserTest.java b/src/test/java/seedu/binbash/parser/ParserTest.java index c26cfcf9c0..9c54ddd2b6 100644 --- a/src/test/java/seedu/binbash/parser/ParserTest.java +++ b/src/test/java/seedu/binbash/parser/ParserTest.java @@ -11,6 +11,7 @@ import seedu.binbash.command.Command; import seedu.binbash.command.ListCommand; import seedu.binbash.command.ByeCommand; +import seedu.binbash.command.QuoteCommand; import seedu.binbash.exceptions.BinBashException; import seedu.binbash.exceptions.InvalidCommandException; import seedu.binbash.item.Item; @@ -40,6 +41,16 @@ public void testParseCommand_validCommandBye_returnsByeCommand() { } } + @Test + public void testParseCommand_validCommandQuote_returnsQuoteCommand() { + try { + Command command = parser.parseCommand("quote"); + assertTrue(command instanceof QuoteCommand); + } catch (BinBashException e) { + fail("Unexpected InvalidCommandException: " + e.getMessage()); + } + } + @Test public void testParseCommand_invalidCommand_throwsInvalidCommandException() { assertThrows(InvalidCommandException.class, () -> parser.parseCommand("invalid")); From 7f47edc7deb9f8fa556993eeced6f5aefe7e23e9 Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 7 Apr 2024 22:25:13 +0800 Subject: [PATCH 11/59] Fixed dos2unix error --- text-ui-test/runtest.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh index 35f240be2f..236a55a033 100755 --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -15,8 +15,8 @@ java -jar $(find ../build/libs/ -mindepth 1 -print -quit) < input.txt &> ACTUAL. cp EXPECTED.TXT EXPECTED-UNIX.TXT dos2unix EXPECTED-UNIX.TXT ACTUAL.TXT -# compare the third line, after logger output onwards -diff <(tail -n +3 ACTUAL.TXT) EXPECTED.TXT +# compare the thirteenth line, after logger output onwards +diff <(tail -n +13 ACTUAL.TXT) EXPECTED.TXT if [ $? -eq 0 ] then echo "Test passed!" From fc20bb612167377721f5fe3583e24a4d25c1fc9f Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 7 Apr 2024 22:33:07 +0800 Subject: [PATCH 12/59] Corrected Expected Output --- text-ui-test/EXPECTED.TXT | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 92b9cc8464..ece05c24bc 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,4 +1,5 @@ ------------------------------------------------------------- +BinBash started up! ____ _ ____ _ | __ )(_)_ __ | __ ) __ _ ___| |__ | _ \| | '_ \| _ \ / _` / __| '_ \ @@ -13,6 +14,9 @@ Here are your metrics: Total Revenue: 0.00 Net Profit: 0.00 +------------------------------------------------------------- +------------------------------------------------------------- + ------------------------------------------------------------- binbash> ------------------------------------------------------------- From 117b050d6f87c43e6b6aeddb65decb3d69207a98 Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 7 Apr 2024 22:51:21 +0800 Subject: [PATCH 13/59] Fixed diff error --- text-ui-test/EXPECTED.TXT | 2 ++ 1 file changed, 2 insertions(+) diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index ece05c24bc..34e913dfe0 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,3 +1,5 @@ + +INFO: Data loaded successfully ------------------------------------------------------------- BinBash started up! ____ _ ____ _ From 9c39c8c144637d79dbc75dfd5b01c3a245f6e5ab Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 7 Apr 2024 23:04:10 +0800 Subject: [PATCH 14/59] Fixed Diff Error --- text-ui-test/EXPECTED.TXT | 2 -- text-ui-test/runtest.sh | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 34e913dfe0..ece05c24bc 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,5 +1,3 @@ - -INFO: Data loaded successfully ------------------------------------------------------------- BinBash started up! ____ _ ____ _ diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh index 236a55a033..55206d9219 100755 --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -15,8 +15,8 @@ java -jar $(find ../build/libs/ -mindepth 1 -print -quit) < input.txt &> ACTUAL. cp EXPECTED.TXT EXPECTED-UNIX.TXT dos2unix EXPECTED-UNIX.TXT ACTUAL.TXT -# compare the thirteenth line, after logger output onwards -diff <(tail -n +13 ACTUAL.TXT) EXPECTED.TXT +# compare the twenty-third line, after quote output onwards +diff <(tail -n +23 ACTUAL.TXT) EXPECTED.TXT if [ $? -eq 0 ] then echo "Test passed!" From fcc0d2c9edad4ca424783af011741d26608effb1 Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 7 Apr 2024 23:08:09 +0800 Subject: [PATCH 15/59] Fixed Diff Error --- text-ui-test/EXPECTED.TXT | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index ece05c24bc..f490846118 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,23 +1,3 @@ -------------------------------------------------------------- -BinBash started up! - ____ _ ____ _ - | __ )(_)_ __ | __ ) __ _ ___| |__ - | _ \| | '_ \| _ \ / _` / __| '_ \ - | |_) | | | | | |_) | (_| \__ \ | | | - |____/|_|_| |_|____/ \__,_|___/_| |_| - -Welcome to BinBash! -------------------------------------------------------------- -------------------------------------------------------------- -Here are your metrics: - Total Cost: 0.00 - Total Revenue: 0.00 - Net Profit: 0.00 - -------------------------------------------------------------- -------------------------------------------------------------- - -------------------------------------------------------------- binbash> ------------------------------------------------------------- ------------------------------------------------------------- From a75c4bb456fd0da3921d18f529f42ff38cf62f87 Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 7 Apr 2024 23:58:30 +0800 Subject: [PATCH 16/59] Solve Diff Error --- text-ui-test/runtest.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh index 55206d9219..fe0b8511a0 100755 --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -14,7 +14,20 @@ rm -rf data log java -jar $(find ../build/libs/ -mindepth 1 -print -quit) < input.txt &> ACTUAL.TXT cp EXPECTED.TXT EXPECTED-UNIX.TXT -dos2unix EXPECTED-UNIX.TXT ACTUAL.TXT + +# Check the operating system and convert line endings accordingly +if [[ $(uname -s) == "Darwin" ]]; then + # macOS + sed -i '' 's/\r$//' EXPECTED-UNIX.TXT ACTUAL.TXT +elif [[ $(uname -s) == "Linux" ]]; then + # Linux + dos2unix EXPECTED-UNIX.TXT ACTUAL.TXT +elif [[ $(uname -s) == "CYGWIN"* || $(uname -s) == "MINGW"* ]]; then + # Windows + unix2dos -n EXPECTED-UNIX.TXT EXPECTED-UNIX-WINDOWS.TXT + unix2dos -n ACTUAL.TXT ACTUAL-WINDOWS.TXT +fi + # compare the twenty-third line, after quote output onwards diff <(tail -n +23 ACTUAL.TXT) EXPECTED.TXT if [ $? -eq 0 ] From 26041af92d433716bc12dde6ffc42f6f9ff5fa3f Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Mon, 8 Apr 2024 14:10:58 +0800 Subject: [PATCH 17/59] Fixed Diff Error --- text-ui-test/runtest.sh | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh index fe0b8511a0..2a840a01b2 100755 --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -14,22 +14,9 @@ rm -rf data log java -jar $(find ../build/libs/ -mindepth 1 -print -quit) < input.txt &> ACTUAL.TXT cp EXPECTED.TXT EXPECTED-UNIX.TXT - -# Check the operating system and convert line endings accordingly -if [[ $(uname -s) == "Darwin" ]]; then - # macOS - sed -i '' 's/\r$//' EXPECTED-UNIX.TXT ACTUAL.TXT -elif [[ $(uname -s) == "Linux" ]]; then - # Linux - dos2unix EXPECTED-UNIX.TXT ACTUAL.TXT -elif [[ $(uname -s) == "CYGWIN"* || $(uname -s) == "MINGW"* ]]; then - # Windows - unix2dos -n EXPECTED-UNIX.TXT EXPECTED-UNIX-WINDOWS.TXT - unix2dos -n ACTUAL.TXT ACTUAL-WINDOWS.TXT -fi - -# compare the twenty-third line, after quote output onwards -diff <(tail -n +23 ACTUAL.TXT) EXPECTED.TXT +dos2unix EXPECTED-UNIX.TXT ACTUAL.TXT +# compare the twenty-secondth line, after quote output onwards +diff <(tail -n +22 ACTUAL.TXT) EXPECTED.TXT if [ $? -eq 0 ] then echo "Test passed!" From 397d9d57bf53d4427a10fe596f881b83d1a5a87b Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Mon, 8 Apr 2024 14:16:50 +0800 Subject: [PATCH 18/59] Fixed Diff Error --- text-ui-test/EXPECTED.TXT | 20 ++++++++++++++++++++ text-ui-test/runtest.sh | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index f490846118..fa360dc429 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,3 +1,23 @@ +------------------------------------------------------------- +BinBash started up! + ____ _ ____ _ + | __ )(_)_ __ | __ ) __ _ ___| |__ + | _ \| | '_ \| _ \ / _` / __| '_ \ + | |_) | | | | | |_) | (_| \__ \ | | | + |____/|_|_| |_|____/ \__,_|___/_| |_| + +Welcome to BinBash! +------------------------------------------------------------- +------------------------------------------------------------- +Here are your metrics: + Total Cost: 0.00 + Total Revenue: 0.00 + Net Profit: 0.00 + +------------------------------------------------------------- +------------------------------------------------------------- + +------------------------------------------------------------- binbash> ------------------------------------------------------------- ------------------------------------------------------------- diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh index 2a840a01b2..35f240be2f 100755 --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -15,8 +15,8 @@ java -jar $(find ../build/libs/ -mindepth 1 -print -quit) < input.txt &> ACTUAL. cp EXPECTED.TXT EXPECTED-UNIX.TXT dos2unix EXPECTED-UNIX.TXT ACTUAL.TXT -# compare the twenty-secondth line, after quote output onwards -diff <(tail -n +22 ACTUAL.TXT) EXPECTED.TXT +# compare the third line, after logger output onwards +diff <(tail -n +3 ACTUAL.TXT) EXPECTED.TXT if [ $? -eq 0 ] then echo "Test passed!" From 93076f0effe5b64d7fcb06c4815986e2d289657f Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Mon, 8 Apr 2024 14:27:01 +0800 Subject: [PATCH 19/59] Fixed Diff Error --- text-ui-test/runtest.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh index 35f240be2f..60de4e242e 100755 --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -15,6 +15,11 @@ java -jar $(find ../build/libs/ -mindepth 1 -print -quit) < input.txt &> ACTUAL. cp EXPECTED.TXT EXPECTED-UNIX.TXT dos2unix EXPECTED-UNIX.TXT ACTUAL.TXT + +# Remove line 19 from both ACTUAL.TXT and EXPECTED-UNIX.TXT, so the quote is not compared +sed -i '19d' ACTUAL.TXT +sed -i '19d' EXPECTED-UNIX.TXT + # compare the third line, after logger output onwards diff <(tail -n +3 ACTUAL.TXT) EXPECTED.TXT if [ $? -eq 0 ] From 97baaa85f8f4b7c8397d801e88416917844b5483 Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Mon, 8 Apr 2024 14:35:25 +0800 Subject: [PATCH 20/59] Fixed Diff Error --- text-ui-test/EXPECTED.TXT | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index fa360dc429..8d863e373f 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -10,13 +10,13 @@ Welcome to BinBash! ------------------------------------------------------------- ------------------------------------------------------------- Here are your metrics: - Total Cost: 0.00 - Total Revenue: 0.00 - Net Profit: 0.00 + Total Cost: 0.00 + Total Revenue: 0.00 + Net Profit: 0.00 ------------------------------------------------------------- ------------------------------------------------------------- - +------------------------------------------------------------- ------------------------------------------------------------- binbash> ------------------------------------------------------------- From 66e0ad33efb28c232baf8f248ffbac679e0949c4 Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Mon, 8 Apr 2024 14:41:28 +0800 Subject: [PATCH 21/59] Fixed Diff Error --- text-ui-test/EXPECTED.TXT | 8 ++++---- text-ui-test/runtest.bat | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 8d863e373f..12b43062f2 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -10,13 +10,13 @@ Welcome to BinBash! ------------------------------------------------------------- ------------------------------------------------------------- Here are your metrics: - Total Cost: 0.00 - Total Revenue: 0.00 - Net Profit: 0.00 + Total Cost: 0.00 + Total Revenue: 0.00 + Net Profit: 0.00 ------------------------------------------------------------- ------------------------------------------------------------- -------------------------------------------------------------- + ------------------------------------------------------------- binbash> ------------------------------------------------------------- diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 6b206793c8..e3a8507772 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -20,4 +20,8 @@ java -jar %jarloc% < ..\..\text-ui-test\input.txt > ..\..\text-ui-test\ACTUAL.TX cd ..\..\text-ui-test +REM Exclude line 19 from both ACTUAL.TXT and EXPECTED.TXT before running comparison +findstr /V /N "^" ACTUAL.TXT | findstr /V /C:"19:" > ACTUAL_TMP.TXT +findstr /V /N "^" EXPECTED.TXT | findstr /V /C:"19:" > EXPECTED_TMP.TXT + FC ACTUAL.TXT EXPECTED.TXT >NUL && ECHO Test passed! || Echo Test failed! From 264c5a87254d886147a200958c2d4959b3e103ed Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Mon, 8 Apr 2024 14:50:43 +0800 Subject: [PATCH 22/59] Fixed Diff Error --- text-ui-test/runtest.bat | 4 ---- text-ui-test/runtest.sh | 5 ----- 2 files changed, 9 deletions(-) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index e3a8507772..6b206793c8 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -20,8 +20,4 @@ java -jar %jarloc% < ..\..\text-ui-test\input.txt > ..\..\text-ui-test\ACTUAL.TX cd ..\..\text-ui-test -REM Exclude line 19 from both ACTUAL.TXT and EXPECTED.TXT before running comparison -findstr /V /N "^" ACTUAL.TXT | findstr /V /C:"19:" > ACTUAL_TMP.TXT -findstr /V /N "^" EXPECTED.TXT | findstr /V /C:"19:" > EXPECTED_TMP.TXT - FC ACTUAL.TXT EXPECTED.TXT >NUL && ECHO Test passed! || Echo Test failed! diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh index 60de4e242e..35f240be2f 100755 --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -15,11 +15,6 @@ java -jar $(find ../build/libs/ -mindepth 1 -print -quit) < input.txt &> ACTUAL. cp EXPECTED.TXT EXPECTED-UNIX.TXT dos2unix EXPECTED-UNIX.TXT ACTUAL.TXT - -# Remove line 19 from both ACTUAL.TXT and EXPECTED-UNIX.TXT, so the quote is not compared -sed -i '19d' ACTUAL.TXT -sed -i '19d' EXPECTED-UNIX.TXT - # compare the third line, after logger output onwards diff <(tail -n +3 ACTUAL.TXT) EXPECTED.TXT if [ $? -eq 0 ] From dbc7bc71c304d6dc8a7a03aaeb62e73ab746c814 Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Mon, 8 Apr 2024 15:02:27 +0800 Subject: [PATCH 23/59] Fixed Diff Error --- text-ui-test/runtest.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh index 35f240be2f..a05ae4caa7 100755 --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -15,8 +15,8 @@ java -jar $(find ../build/libs/ -mindepth 1 -print -quit) < input.txt &> ACTUAL. cp EXPECTED.TXT EXPECTED-UNIX.TXT dos2unix EXPECTED-UNIX.TXT ACTUAL.TXT -# compare the third line, after logger output onwards -diff <(tail -n +3 ACTUAL.TXT) EXPECTED.TXT +# compare lines from the third line, after logger output onwards and excluding quote +diff <(awk 'NR != 21 && NR >= 3' ACTUAL.TXT) <(awk 'NR != 19' EXPECTED.TXT) if [ $? -eq 0 ] then echo "Test passed!" From b0890c64c32bb55a8fab98527535525049dd2d00 Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Mon, 8 Apr 2024 15:13:25 +0800 Subject: [PATCH 24/59] Fixed Diff Error --- text-ui-test/EXPECTED.TXT | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 12b43062f2..ece05c24bc 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -9,7 +9,7 @@ BinBash started up! Welcome to BinBash! ------------------------------------------------------------- ------------------------------------------------------------- -Here are your metrics: +Here are your metrics: Total Cost: 0.00 Total Revenue: 0.00 Net Profit: 0.00 From 3e456cdc5948ae7ad7e4e37b7251537caa4058b0 Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Mon, 8 Apr 2024 15:22:33 +0800 Subject: [PATCH 25/59] Fixed DIff Error --- text-ui-test/runtest.bat | 3 +++ 1 file changed, 3 insertions(+) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 6b206793c8..08a35f72f6 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -20,4 +20,7 @@ java -jar %jarloc% < ..\..\text-ui-test\input.txt > ..\..\text-ui-test\ACTUAL.TX cd ..\..\text-ui-test +REM Skip the first two lines and exclude line 19 from ACTUAL.TXT before comparison +findstr /v /n "^" ACTUAL.TXT | findstr /r /v "^1: ^2: ^19:" > ACTUAL_TEMP.TXT + FC ACTUAL.TXT EXPECTED.TXT >NUL && ECHO Test passed! || Echo Test failed! From 94d479ce4a82b730f4946e3c0849ba2806fed921 Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Mon, 8 Apr 2024 15:25:39 +0800 Subject: [PATCH 26/59] Fixed DIff Error --- text-ui-test/runtest.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 08a35f72f6..7ed4db139b 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -23,4 +23,4 @@ cd ..\..\text-ui-test REM Skip the first two lines and exclude line 19 from ACTUAL.TXT before comparison findstr /v /n "^" ACTUAL.TXT | findstr /r /v "^1: ^2: ^19:" > ACTUAL_TEMP.TXT -FC ACTUAL.TXT EXPECTED.TXT >NUL && ECHO Test passed! || Echo Test failed! +FC ACTUAL_TEMP.TXT EXPECTED.TXT >NUL && ECHO Test passed! || Echo Test failed! From a151f96e62d08c9a028f11c9eb9cbee5b3fb8842 Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:09:56 +0800 Subject: [PATCH 27/59] Update EXPECTED.TXT From 03194acf8b9922f7684a33c7638340e578e6475b Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:17:32 +0800 Subject: [PATCH 28/59] Update runtest.bat --- text-ui-test/runtest.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 7ed4db139b..f195ffc083 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -23,4 +23,4 @@ cd ..\..\text-ui-test REM Skip the first two lines and exclude line 19 from ACTUAL.TXT before comparison findstr /v /n "^" ACTUAL.TXT | findstr /r /v "^1: ^2: ^19:" > ACTUAL_TEMP.TXT -FC ACTUAL_TEMP.TXT EXPECTED.TXT >NUL && ECHO Test passed! || Echo Test failed! +FC ACTUAL_TEMP.TXT EXPECTED.TXT From f63be8a9932410ac9b900d9caf9458502b3581a1 Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:25:55 +0800 Subject: [PATCH 29/59] Update runtest.bat --- text-ui-test/runtest.bat | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index f195ffc083..aa93879f91 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -20,7 +20,4 @@ java -jar %jarloc% < ..\..\text-ui-test\input.txt > ..\..\text-ui-test\ACTUAL.TX cd ..\..\text-ui-test -REM Skip the first two lines and exclude line 19 from ACTUAL.TXT before comparison -findstr /v /n "^" ACTUAL.TXT | findstr /r /v "^1: ^2: ^19:" > ACTUAL_TEMP.TXT - -FC ACTUAL_TEMP.TXT EXPECTED.TXT +FC ACTUAL.TXT EXPECTED.TX From 10aa4086888d66abcaa3418c78d4558323fede72 Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:26:28 +0800 Subject: [PATCH 30/59] Update runtest.bat --- text-ui-test/runtest.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index aa93879f91..4e73c3437b 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -20,4 +20,4 @@ java -jar %jarloc% < ..\..\text-ui-test\input.txt > ..\..\text-ui-test\ACTUAL.TX cd ..\..\text-ui-test -FC ACTUAL.TXT EXPECTED.TX +FC ACTUAL.TXT EXPECTED.TXT From c21b00f0a8885cb55501eec4d18c9d3b13d603d1 Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:30:36 +0800 Subject: [PATCH 31/59] Update runtest.bat --- text-ui-test/runtest.bat | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 4e73c3437b..b6ece9c7fd 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -20,4 +20,8 @@ java -jar %jarloc% < ..\..\text-ui-test\input.txt > ..\..\text-ui-test\ACTUAL.TX cd ..\..\text-ui-test -FC ACTUAL.TXT EXPECTED.TXT +REM Delete line 19 from ACTUAL.TXT +type ACTUAL.TXT | findstr /v /n "^19:" > ACTUAL_TEMP.TXT + +REM Compare ACTUAL_TEMP.TXT with EXPECTED.TXT +FC ACTUAL_TEMP.TXT EXPECTED.TXT From 9fd8eab36082dbd22680ab52903896b218b4a9b4 Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:37:39 +0800 Subject: [PATCH 32/59] Update runtest.bat --- text-ui-test/runtest.bat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index b6ece9c7fd..3ee57b35ea 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -20,8 +20,8 @@ java -jar %jarloc% < ..\..\text-ui-test\input.txt > ..\..\text-ui-test\ACTUAL.TX cd ..\..\text-ui-test -REM Delete line 19 from ACTUAL.TXT -type ACTUAL.TXT | findstr /v /n "^19:" > ACTUAL_TEMP.TXT +REM Delete contents of line 19 in ACTUAL.TXT and replace it with a blank line +for /f "tokens=1,* delims=:" %%A in ('findstr /n "^" ACTUAL.TXT ^| findstr /v /b "19:"') do echo(%%B > ACTUAL_TEMP.TXT REM Compare ACTUAL_TEMP.TXT with EXPECTED.TXT FC ACTUAL_TEMP.TXT EXPECTED.TXT From 9c6016a6baaf9345955625d589991ec60fb322eb Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:42:11 +0800 Subject: [PATCH 33/59] Update runtest.bat --- text-ui-test/runtest.bat | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 3ee57b35ea..8802afa4aa 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -20,8 +20,8 @@ java -jar %jarloc% < ..\..\text-ui-test\input.txt > ..\..\text-ui-test\ACTUAL.TX cd ..\..\text-ui-test -REM Delete contents of line 19 in ACTUAL.TXT and replace it with a blank line -for /f "tokens=1,* delims=:" %%A in ('findstr /n "^" ACTUAL.TXT ^| findstr /v /b "19:"') do echo(%%B > ACTUAL_TEMP.TXT +REM Exclude line 19 from both ACTUAL.TXT and EXPECTED.TXT before comparison +findstr /v /n "^19:" ACTUAL.TXT > ACTUAL_TEMP.TXT +findstr /v /n "^19:" EXPECTED.TXT > EXPECTED_TEMP.TXT -REM Compare ACTUAL_TEMP.TXT with EXPECTED.TXT -FC ACTUAL_TEMP.TXT EXPECTED.TXT +FC ACTUAL_TEMP.TXT EXPECTED_TEMP.TXT From b7b9f302569829b074869f036615fa9c42b69bbb Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:54:30 +0800 Subject: [PATCH 34/59] Update runtest.bat --- text-ui-test/runtest.bat | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 8802afa4aa..f95c7b664f 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -20,8 +20,7 @@ java -jar %jarloc% < ..\..\text-ui-test\input.txt > ..\..\text-ui-test\ACTUAL.TX cd ..\..\text-ui-test -REM Exclude line 19 from both ACTUAL.TXT and EXPECTED.TXT before comparison +REM Exclude line 19 from ACTUAL.TXT before comparison findstr /v /n "^19:" ACTUAL.TXT > ACTUAL_TEMP.TXT -findstr /v /n "^19:" EXPECTED.TXT > EXPECTED_TEMP.TXT -FC ACTUAL_TEMP.TXT EXPECTED_TEMP.TXT +FC ACTUAL_TEMP.TXT EXPECTED.TXT From 67888baf19f484cae02c199ce9981806b5ff4b3e Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Mon, 8 Apr 2024 17:04:55 +0800 Subject: [PATCH 35/59] Update runtest.bat --- text-ui-test/runtest.bat | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index f95c7b664f..c5c7b58a4f 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -20,7 +20,11 @@ java -jar %jarloc% < ..\..\text-ui-test\input.txt > ..\..\text-ui-test\ACTUAL.TX cd ..\..\text-ui-test -REM Exclude line 19 from ACTUAL.TXT before comparison -findstr /v /n "^19:" ACTUAL.TXT > ACTUAL_TEMP.TXT +REM Exclude the 19th line from ACTUAL_TEMP.TXT before comparison +set "line=0" +(for /f "delims=" %%i in (ACTUAL.TXT) do ( + set /a "line+=1" + if "!line!" neq "19" echo %%i +)) > ACTUAL_TEMP.TXT FC ACTUAL_TEMP.TXT EXPECTED.TXT From c1dbdb51c35662f857dd1d63c9cce6b167281e2c Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Mon, 8 Apr 2024 17:07:34 +0800 Subject: [PATCH 36/59] Update runtest.bat --- text-ui-test/runtest.bat | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index c5c7b58a4f..6b206793c8 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -20,11 +20,4 @@ java -jar %jarloc% < ..\..\text-ui-test\input.txt > ..\..\text-ui-test\ACTUAL.TX cd ..\..\text-ui-test -REM Exclude the 19th line from ACTUAL_TEMP.TXT before comparison -set "line=0" -(for /f "delims=" %%i in (ACTUAL.TXT) do ( - set /a "line+=1" - if "!line!" neq "19" echo %%i -)) > ACTUAL_TEMP.TXT - -FC ACTUAL_TEMP.TXT EXPECTED.TXT +FC ACTUAL.TXT EXPECTED.TXT >NUL && ECHO Test passed! || Echo Test failed! From b4b36c4537b7d7bdfdf22084e1b32880713e64d5 Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Mon, 8 Apr 2024 18:18:22 +0800 Subject: [PATCH 37/59] Update runtest.bat --- text-ui-test/runtest.bat | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 6b206793c8..a628ca3f40 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -20,4 +20,8 @@ java -jar %jarloc% < ..\..\text-ui-test\input.txt > ..\..\text-ui-test\ACTUAL.TX cd ..\..\text-ui-test -FC ACTUAL.TXT EXPECTED.TXT >NUL && ECHO Test passed! || Echo Test failed! +REM Exclude line 19 from both ACTUAL.TXT and EXPECTED.TXT before comparison +findstr /v /n "^19:" ACTUAL.TXT > ACTUAL_TEMP.TXT +findstr /v /n "^19:" EXPECTED.TXT > EXPECTED_TEMP.TXT + +FC ACTUAL_TEMP.TXT EXPECTED_TEMP.TXT From c50db75ce5e9e7d31ba4c4ecc3cb0a7198273892 Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Mon, 8 Apr 2024 18:24:12 +0800 Subject: [PATCH 38/59] Update runtest.bat --- text-ui-test/runtest.bat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index a628ca3f40..a7aad2c3cf 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -20,8 +20,8 @@ java -jar %jarloc% < ..\..\text-ui-test\input.txt > ..\..\text-ui-test\ACTUAL.TX cd ..\..\text-ui-test -REM Exclude line 19 from both ACTUAL.TXT and EXPECTED.TXT before comparison +REM Exclude line 19 from ACTUAL.TXT before comparison findstr /v /n "^19:" ACTUAL.TXT > ACTUAL_TEMP.TXT -findstr /v /n "^19:" EXPECTED.TXT > EXPECTED_TEMP.TXT +type EXPECTED.TXT > EXPECTED_TEMP.TXT FC ACTUAL_TEMP.TXT EXPECTED_TEMP.TXT From e6dadcc61bc6efab714a91cbb3c2f4e26086e953 Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Mon, 8 Apr 2024 18:27:51 +0800 Subject: [PATCH 39/59] Update runtest.bat --- text-ui-test/runtest.bat | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index a7aad2c3cf..8c8d9b3c00 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -20,8 +20,9 @@ java -jar %jarloc% < ..\..\text-ui-test\input.txt > ..\..\text-ui-test\ACTUAL.TX cd ..\..\text-ui-test -REM Exclude line 19 from ACTUAL.TXT before comparison findstr /v /n "^19:" ACTUAL.TXT > ACTUAL_TEMP.TXT type EXPECTED.TXT > EXPECTED_TEMP.TXT +set /p line19=> EXPECTED_TEMP.TXT FC ACTUAL_TEMP.TXT EXPECTED_TEMP.TXT From 09c091d1f83cc96ce2349ef1708088228eb7babc Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Mon, 8 Apr 2024 18:35:40 +0800 Subject: [PATCH 40/59] Update runtest.bat --- text-ui-test/runtest.bat | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 8c8d9b3c00..a628ca3f40 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -20,9 +20,8 @@ java -jar %jarloc% < ..\..\text-ui-test\input.txt > ..\..\text-ui-test\ACTUAL.TX cd ..\..\text-ui-test +REM Exclude line 19 from both ACTUAL.TXT and EXPECTED.TXT before comparison findstr /v /n "^19:" ACTUAL.TXT > ACTUAL_TEMP.TXT -type EXPECTED.TXT > EXPECTED_TEMP.TXT -set /p line19=> EXPECTED_TEMP.TXT +findstr /v /n "^19:" EXPECTED.TXT > EXPECTED_TEMP.TXT FC ACTUAL_TEMP.TXT EXPECTED_TEMP.TXT From 48ca7ef18525bd02408cca0742e66837edd6642b Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Mon, 8 Apr 2024 18:51:38 +0800 Subject: [PATCH 41/59] Update runtest.bat --- text-ui-test/runtest.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index a628ca3f40..4f1ecd692f 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -21,7 +21,7 @@ java -jar %jarloc% < ..\..\text-ui-test\input.txt > ..\..\text-ui-test\ACTUAL.TX cd ..\..\text-ui-test REM Exclude line 19 from both ACTUAL.TXT and EXPECTED.TXT before comparison -findstr /v /n "^19:" ACTUAL.TXT > ACTUAL_TEMP.TXT +findstr /v /n "^19" ACTUAL.TXT > ACTUAL_TEMP.TXT findstr /v /n "^19:" EXPECTED.TXT > EXPECTED_TEMP.TXT FC ACTUAL_TEMP.TXT EXPECTED_TEMP.TXT From d97d771733f2316e5749defff5efb16bdff1aa27 Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Mon, 8 Apr 2024 19:01:25 +0800 Subject: [PATCH 42/59] Update runtest.bat --- text-ui-test/runtest.bat | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 4f1ecd692f..2a5ae4ae5e 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -20,8 +20,8 @@ java -jar %jarloc% < ..\..\text-ui-test\input.txt > ..\..\text-ui-test\ACTUAL.TX cd ..\..\text-ui-test -REM Exclude line 19 from both ACTUAL.TXT and EXPECTED.TXT before comparison -findstr /v /n "^19" ACTUAL.TXT > ACTUAL_TEMP.TXT -findstr /v /n "^19:" EXPECTED.TXT > EXPECTED_TEMP.TXT +REM Skip the first 20 lines and copy the rest of the file +more +20 ACTUAL.TXT > ACTUAL_TEMP.TXT +more +20 EXPECTED.TXT > EXPECTED_TEMP.TXT FC ACTUAL_TEMP.TXT EXPECTED_TEMP.TXT From a0a8a475857cf38ffd61f7bc39d3b761e409d4f5 Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Mon, 8 Apr 2024 19:05:13 +0800 Subject: [PATCH 43/59] Update runtest.bat --- text-ui-test/runtest.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 2a5ae4ae5e..aa2db4a0c6 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -24,4 +24,4 @@ REM Skip the first 20 lines and copy the rest of the file more +20 ACTUAL.TXT > ACTUAL_TEMP.TXT more +20 EXPECTED.TXT > EXPECTED_TEMP.TXT -FC ACTUAL_TEMP.TXT EXPECTED_TEMP.TXT +FC ACTUAL_TEMP.TXT EXPECTED_TEMP.TXT >NUL && ECHO Test passed! || Echo Test failed! From f363fe5e669dc7625a097d2c03a7f760cbc42174 Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Mon, 8 Apr 2024 23:55:16 +0800 Subject: [PATCH 44/59] Update UserGuide.md --- docs/UserGuide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 6d2a6b8e55..dfb36f6fc0 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -327,7 +327,7 @@ Format: `add -op -n ITEM_NAME -d ITEM_DESCRIPTION -q ITEM_QUANTITY -e EXPIRY_DAT Examples: -- `add -op -n milk -d to make cofee -q 2 -e 03-10-2024 -c 1.30`
+- `add -op -n milk -d to make coffee -q 2 -e 03-10-2024 -c 1.30`
```text ------------------------------------------------------------- Noted! I have added the following item into your inventory: From 282265be00b73eb9b218136b5097b13a3b77719d Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Tue, 9 Apr 2024 00:12:23 +0800 Subject: [PATCH 45/59] Update BinBash.java --- src/main/java/seedu/binbash/BinBash.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/seedu/binbash/BinBash.java b/src/main/java/seedu/binbash/BinBash.java index a31e92d35b..8f5224f073 100644 --- a/src/main/java/seedu/binbash/BinBash.java +++ b/src/main/java/seedu/binbash/BinBash.java @@ -12,11 +12,11 @@ import seedu.binbash.ui.Ui; public class BinBash { - private final Ui userInterface; - private final ItemList itemList; - private final Parser inputParser; - private final Storage storage; - private final BinBashLogger logger; + private Ui userInterface; + private ItemList itemList; + private Parser inputParser; + private Storage storage; + private BinBashLogger logger; public BinBash() { logger = new BinBashLogger(BinBash.class.getName()); From 5ee94b83bd1b3bf1fb09ccb19f41bb335381ca01 Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Tue, 9 Apr 2024 00:18:42 +0800 Subject: [PATCH 46/59] Update Parser.java --- src/main/java/seedu/binbash/parser/Parser.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/seedu/binbash/parser/Parser.java b/src/main/java/seedu/binbash/parser/Parser.java index 95b40975cd..e61ee8b5b7 100644 --- a/src/main/java/seedu/binbash/parser/Parser.java +++ b/src/main/java/seedu/binbash/parser/Parser.java @@ -25,13 +25,13 @@ */ public class Parser { protected static final DateTimeFormatter EXPECTED_INPUT_DATE_FORMAT = DateTimeFormatter.ofPattern("dd-MM-yyyy"); - private final AddCommandParser addCommandParser; - private final SearchCommandParser searchCommandParser; - private final RestockCommandParser restockCommandParser; - private final SellCommandParser sellCommandParser; - private final ListCommandParser listCommandParser; - private final UpdateCommandParser updateCommandParser; - private final DeleteCommandParser deleteCommandParser; + private AddCommandParser addCommandParser; + private SearchCommandParser searchCommandParser; + private RestockCommandParser restockCommandParser; + private SellCommandParser sellCommandParser; + private ListCommandParser listCommandParser; + private UpdateCommandParser updateCommandParser; + private DeleteCommandParser deleteCommandParser; public Parser() { addCommandParser = new AddCommandParser(); From ef9ba0d666bc55d2a3b6586b7ff126aead94ae98 Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Tue, 9 Apr 2024 00:20:37 +0800 Subject: [PATCH 47/59] Update runtest.bat --- text-ui-test/runtest.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index aa2db4a0c6..1f86a4d669 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -20,7 +20,7 @@ java -jar %jarloc% < ..\..\text-ui-test\input.txt > ..\..\text-ui-test\ACTUAL.TX cd ..\..\text-ui-test -REM Skip the first 20 lines and copy the rest of the file +REM Skip the first 20 lines and copy the rest of the file, so lines are compared after the quote. more +20 ACTUAL.TXT > ACTUAL_TEMP.TXT more +20 EXPECTED.TXT > EXPECTED_TEMP.TXT From ea28150d06920c87407a2913d0a65808883d50bf Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Tue, 9 Apr 2024 00:25:22 +0800 Subject: [PATCH 48/59] Update BinBash.java --- src/main/java/seedu/binbash/BinBash.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/seedu/binbash/BinBash.java b/src/main/java/seedu/binbash/BinBash.java index 8f5224f073..b7fada2d5e 100644 --- a/src/main/java/seedu/binbash/BinBash.java +++ b/src/main/java/seedu/binbash/BinBash.java @@ -54,7 +54,6 @@ private void run() { } catch (BinBashException e) { userInterface.talk(e.getMessage()); - logger.warning("BinBashException occurred: " + e.getMessage()); // Logging } } logger.info("BinBash exiting..."); From 9c531d45bc2fcbcab9224b27e421dbd64d3482dc Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Tue, 9 Apr 2024 00:28:09 +0800 Subject: [PATCH 49/59] Update QuoteCommand.java --- src/main/java/seedu/binbash/command/QuoteCommand.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/seedu/binbash/command/QuoteCommand.java b/src/main/java/seedu/binbash/command/QuoteCommand.java index f87536ac2f..32e01ad569 100644 --- a/src/main/java/seedu/binbash/command/QuoteCommand.java +++ b/src/main/java/seedu/binbash/command/QuoteCommand.java @@ -14,17 +14,12 @@ public QuoteCommand() { @Override public boolean execute(ItemList itemList) { - if (ui == null) { - throw new IllegalStateException("Ui is not initialized. Please initialize it before calling execute()"); - } String randomMessage = ui.getRandomMessage(); executionUiOutput = randomMessage; - hasToSave = false; // Assuming you don't need to save after executing the Quotes command return true; } - - // Setter method to initialize Ui + public void setUi(Ui ui) { this.ui = ui; } From 1d055cc6f4fb89d5c3f2d65e9f418a1ce09507bb Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sat, 13 Apr 2024 23:28:22 +0800 Subject: [PATCH 50/59] Updated QuoteCommand --- src/main/java/seedu/binbash/BinBash.java | 4 -- .../seedu/binbash/command/QuoteCommand.java | 16 +---- .../java/seedu/binbash/quotes/Quotes.java | 58 +++++++++++++++++++ src/main/java/seedu/binbash/ui/Ui.java | 51 ++-------------- 4 files changed, 64 insertions(+), 65 deletions(-) create mode 100644 src/main/java/seedu/binbash/quotes/Quotes.java diff --git a/src/main/java/seedu/binbash/BinBash.java b/src/main/java/seedu/binbash/BinBash.java index a31e92d35b..9f5f8074e0 100644 --- a/src/main/java/seedu/binbash/BinBash.java +++ b/src/main/java/seedu/binbash/BinBash.java @@ -2,7 +2,6 @@ import seedu.binbash.command.ByeCommand; -import seedu.binbash.command.QuoteCommand; import seedu.binbash.command.Command; import seedu.binbash.exceptions.BinBashException; import seedu.binbash.inventory.ItemList; @@ -40,9 +39,6 @@ private void run() { if (userCommand instanceof ByeCommand) { userInterface.setUserAsInactive(); - } else if (userCommand instanceof QuoteCommand) { // Handle QuoteCommand - // Initialize Ui before executing QuoteCommand - ((QuoteCommand) userCommand).setUi(userInterface); } userCommand.execute(itemList); diff --git a/src/main/java/seedu/binbash/command/QuoteCommand.java b/src/main/java/seedu/binbash/command/QuoteCommand.java index f87536ac2f..d873440e9b 100644 --- a/src/main/java/seedu/binbash/command/QuoteCommand.java +++ b/src/main/java/seedu/binbash/command/QuoteCommand.java @@ -1,11 +1,10 @@ package seedu.binbash.command; import seedu.binbash.inventory.ItemList; -import seedu.binbash.ui.Ui; +import seedu.binbash.quotes.Quotes; import seedu.binbash.logger.BinBashLogger; public class QuoteCommand extends Command { - private Ui ui; public QuoteCommand() { commandLogger = new BinBashLogger(QuoteCommand.class.getName()); @@ -14,18 +13,7 @@ public QuoteCommand() { @Override public boolean execute(ItemList itemList) { - if (ui == null) { - throw new IllegalStateException("Ui is not initialized. Please initialize it before calling execute()"); - } - - String randomMessage = ui.getRandomMessage(); - executionUiOutput = randomMessage; - hasToSave = false; // Assuming you don't need to save after executing the Quotes command + executionUiOutput = Quotes.getRandomQuote(); return true; } - - // Setter method to initialize Ui - public void setUi(Ui ui) { - this.ui = ui; - } } diff --git a/src/main/java/seedu/binbash/quotes/Quotes.java b/src/main/java/seedu/binbash/quotes/Quotes.java new file mode 100644 index 0000000000..aa2709338a --- /dev/null +++ b/src/main/java/seedu/binbash/quotes/Quotes.java @@ -0,0 +1,58 @@ +package seedu.binbash.quotes; + +import java.util.Random; + +public class Quotes { + public static final String[] CUSTOM_MESSAGES = { + "Hope you have a good day of inventory management.", + "Have a nice day!", + "Welcome back to BinBash!", + "Make today amazing!", + "Enjoy your time with BinBash!", + "Wishing you a productive day!", + "Get ready for some BinBash fun!", + "Let's make today great!", + "Time to conquer your inventory!", + "Sending positive vibes your way!", + "Welcome to another BinBash adventure!", + "Stay positive and keep BinBashing!", + "Today's a good day to organize!", + "You've got this!", + "Hope your day is BinBash-tastic!", + "Get ready to rock your inventory!", + "BinBash is here to help!", + "Hope you find everything you need!", + "Have a wonderful day ahead!", + "Start your day with a smile!", + "Sending you BinBash blessings!", + "Let's make magic happen!", + "Embrace the BinBash journey!", + "You're awesome, just like BinBash!", + "Seize the day with BinBash!", + "Welcome to BinBash excellence!", + "Time to unleash your inventory power!", + "Hope you have a blast with BinBash!", + "Today's a good day to BinBash!", + "Stay motivated and BinBash on!", + "Enjoy every moment with BinBash!", + "Make today memorable!", + "Let's create some BinBash miracles!", + "Believe in yourself and BinBash!", + "Welcome to the world of BinBash!", + "Today's forecast: BinBash brilliance!", + "BinBash wishes you a fantastic day!", + "May your day be filled with BinBash joy!", + "Let's make today legendary!", + "Stay positive and BinBash strong!" + }; + + private static final Random RANDOM = new Random(); + + // Private constructor to prevent instantiation + private Quotes() {} + + public static String getRandomQuote() { + int randomIndex = RANDOM.nextInt(CUSTOM_MESSAGES.length); + return CUSTOM_MESSAGES[randomIndex]; + } +} diff --git a/src/main/java/seedu/binbash/ui/Ui.java b/src/main/java/seedu/binbash/ui/Ui.java index fbe0de280d..19dfe5fe33 100644 --- a/src/main/java/seedu/binbash/ui/Ui.java +++ b/src/main/java/seedu/binbash/ui/Ui.java @@ -11,6 +11,7 @@ import seedu.binbash.logger.BinBashLogger; import java.io.IOException; import java.util.ArrayList; +import seedu.binbash.quotes.Quotes; /** * The user facing text interface of the program. @@ -30,49 +31,6 @@ public class Ui { private static LineReader inputReader; private static boolean isUserActive; - private final String[] customMessages = { - "Hope you have a good day of inventory management.", - "Have a nice day!", - "Welcome back to BinBash!", - "Make today amazing!", - "Enjoy your time with BinBash!", - "Wishing you a productive day!", - "Get ready for some BinBash fun!", - "Let's make today great!", - "Time to conquer your inventory!", - "Sending positive vibes your way!", - "Welcome to another BinBash adventure!", - "Stay positive and keep BinBashing!", - "Today's a good day to organize!", - "You've got this!", - "Hope your day is BinBash-tastic!", - "Get ready to rock your inventory!", - "BinBash is here to help!", - "Hope you find everything you need!", - "Have a wonderful day ahead!", - "Start your day with a smile!", - "Sending you BinBash blessings!", - "Let's make magic happen!", - "Embrace the BinBash journey!", - "You're awesome, just like BinBash!", - "Seize the day with BinBash!", - "Welcome to BinBash excellence!", - "Time to unleash your inventory power!", - "Hope you have a blast with BinBash!", - "Today's a good day to BinBash!", - "Stay motivated and BinBash on!", - "Enjoy every moment with BinBash!", - "Make today memorable!", - "Let's create some BinBash miracles!", - "Believe in yourself and BinBash!", - "Welcome to the world of BinBash!", - "Today's forecast: BinBash brilliance!", - "BinBash wishes you a fantastic day!", - "May your day be filled with BinBash joy!", - "Let's make today legendary!", - "Stay positive and BinBash strong!" - }; - /** * Constructor; note that it need only be called once as there should be no more than a single * instance per program run. @@ -125,8 +83,7 @@ public String readUserCommand() { } public void greet() { - String startupMessage = "BinBash started up!"; - talk(startupMessage + NEWLINE + LOGO + WELCOME_MESSAGE); + talk(NEWLINE + LOGO + WELCOME_MESSAGE); } /** @@ -139,7 +96,7 @@ public void talk(String line) { } public String getRandomMessage() { - int randomIndex = RANDOM.nextInt(customMessages.length); - return customMessages[randomIndex]; + int randomIndex = RANDOM.nextInt(Quotes.CUSTOM_MESSAGES.length); + return Quotes.CUSTOM_MESSAGES[randomIndex]; } } From 98ea2e11b525b7e965f495de6f8b62f64f993b26 Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sat, 13 Apr 2024 23:34:25 +0800 Subject: [PATCH 51/59] Fixed Expected.txt error --- text-ui-test/EXPECTED.TXT | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 16ed2f57b4..d7bddf6bcb 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,5 +1,5 @@ ------------------------------------------------------------- -BinBash started up! + ____ _ ____ _ | __ )(_)_ __ | __ ) __ _ ___| |__ | _ \| | '_ \| _ \ / _` / __| '_ \ From 08c67886b1b571a3faea022afe4879eb322a62dd Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 14 Apr 2024 04:12:57 +0800 Subject: [PATCH 52/59] Updated Quote Command --- src/main/java/seedu/binbash/BinBash.java | 3 ++- src/main/java/seedu/binbash/ui/Ui.java | 22 ++++++++-------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/main/java/seedu/binbash/BinBash.java b/src/main/java/seedu/binbash/BinBash.java index b8bec77f72..f682bbf542 100644 --- a/src/main/java/seedu/binbash/BinBash.java +++ b/src/main/java/seedu/binbash/BinBash.java @@ -7,6 +7,7 @@ import seedu.binbash.inventory.ItemList; import seedu.binbash.logger.BinBashLogger; import seedu.binbash.parser.Parser; +import seedu.binbash.quotes.Quotes; import seedu.binbash.storage.Storage; import seedu.binbash.ui.Ui; @@ -30,7 +31,7 @@ private void run() { userInterface.greet(); userInterface.talk(itemList.getProfitMargin()); - userInterface.talk(userInterface.getRandomMessage()); + userInterface.talk(Quotes.getRandomQuote()); while (userInterface.isUserActive()) { String userInput = userInterface.readUserCommand(); diff --git a/src/main/java/seedu/binbash/ui/Ui.java b/src/main/java/seedu/binbash/ui/Ui.java index 19dfe5fe33..67050014a3 100644 --- a/src/main/java/seedu/binbash/ui/Ui.java +++ b/src/main/java/seedu/binbash/ui/Ui.java @@ -1,6 +1,5 @@ package seedu.binbash.ui; -import java.util.Random; import org.jline.reader.LineReader; import org.jline.reader.LineReaderBuilder; import org.jline.reader.EndOfFileException; @@ -8,10 +7,11 @@ import org.jline.builtins.Completers.OptDesc; import org.jline.terminal.Terminal; import org.jline.terminal.TerminalBuilder; + import seedu.binbash.logger.BinBashLogger; + import java.io.IOException; import java.util.ArrayList; -import seedu.binbash.quotes.Quotes; /** * The user facing text interface of the program. @@ -26,7 +26,6 @@ public class Ui { private static final String WELCOME_MESSAGE = "Welcome to BinBash!"; private static final String LINE_DIVIDER = "-------------------------------------------------------------"; private static final BinBashLogger UILOGGER = new BinBashLogger(Ui.class.getName()); - private static final Random RANDOM = new Random(); private static LineReader inputReader; private static boolean isUserActive; @@ -43,13 +42,13 @@ public Ui(ArrayList> allCommandsOptionDescriptions) { System.setProperty("org.jline.terminal.exec.redirectPipeCreationMode", "native"); try { Terminal userTerminal = TerminalBuilder.builder() - .system(true) - .dumb(true) // TODO: omit and catch using logger - .build(); + .system(true) + .dumb(true) // TODO: omit and catch using logger + .build(); inputReader = LineReaderBuilder.builder() - .terminal(userTerminal) - .completer(new CommandCompleter(allCommandsOptionDescriptions)) - .build(); + .terminal(userTerminal) + .completer(new CommandCompleter(allCommandsOptionDescriptions)) + .build(); } catch (IOException e) { UILOGGER.info("failed to get system terminal!"); throw new RuntimeException(e); @@ -94,9 +93,4 @@ public void greet() { public void talk(String line) { System.out.println(LINE_DIVIDER + NEWLINE + line + NEWLINE + LINE_DIVIDER); } - - public String getRandomMessage() { - int randomIndex = RANDOM.nextInt(Quotes.CUSTOM_MESSAGES.length); - return Quotes.CUSTOM_MESSAGES[randomIndex]; - } } From 3f2309544ddc5e4ceb509ea87e4325258e3b8ea4 Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 14 Apr 2024 04:14:52 +0800 Subject: [PATCH 53/59] Added Tests for Search Command --- .../binbash/command/SearchCommandTest.java | 116 ++++++++++++++++-- 1 file changed, 106 insertions(+), 10 deletions(-) diff --git a/src/test/java/seedu/binbash/command/SearchCommandTest.java b/src/test/java/seedu/binbash/command/SearchCommandTest.java index 17d12fd84c..9aea06d899 100644 --- a/src/test/java/seedu/binbash/command/SearchCommandTest.java +++ b/src/test/java/seedu/binbash/command/SearchCommandTest.java @@ -14,24 +14,24 @@ import java.util.ArrayList; public class SearchCommandTest { - private final ArrayList testItemList = new ArrayList() { + private final ArrayList testItemList = new ArrayList<>() { { add(new OperationalItem("Philips LED PLL 4P2G", "LED tubes for warehouse lighting", 30, - 10.20)); // index 0 + 10.20)); // index 0 add(new OperationalItem("Temus Pallet Jack 2XW10 250KG", "Pallet jack for warehouse use", 2, - 285)); // index 1 + 285)); // index 1 add(new PerishableOperationalItem("Energax 40W AAA", "Batteries for warehouse use", 500, - LocalDate.of(2024, 8, 16), 0.10)); // index 2 + LocalDate.of(2024, 8, 16), 0.10)); // index 2 add(new RetailItem("Zebra Sarasa Black 0.5", "Black writing pen", 50, - 1.00, 0.70)); // index 3 + 1.00, 0.70)); // index 3 add(new PerishableRetailItem("Cavendish Banana", "Whole bananas, imported from Malaysia", 30, - LocalDate.of(2024, 1, 4), 0.50, 0.40)); // index 4 + LocalDate.of(2024, 1, 4), 0.50, 0.40)); // index 4 add(new PerishableRetailItem("Meiji Full Fat Pasturized 1.5L", "Pasturized whole dairy milk", 10, - LocalDate.of(2024, 2, 3), 5, 3.50)); // index 5 + LocalDate.of(2024, 2, 3), 5, 3.50)); // index 5 add(new RetailItem("Steely Hans 3P66", "3-inch Shears for gardening", 15, - 6.50, 4.50)); // index 6 + 6.50, 4.50)); // index 6 add(new PerishableRetailItem("Red Banana", "Imported from Indonesia", 20, - LocalDate.of(2024, 1, 6), 0.70, 0.60)); // index 7 + LocalDate.of(2024, 1, 6), 0.70, 0.60)); // index 7 } }; @@ -49,7 +49,7 @@ void execute_searchThroughFields_correctlyListsBatteriesBanana() { searchCommand.execute(dummyItemList); String actualOutput = searchCommand.getExecutionUiOutput(); - String expectedOutput = dummyItemList.printList(new ArrayList() { + String expectedOutput = dummyItemList.printList(new ArrayList<>() { { add(testItemList.get(2)); add(testItemList.get(4)); @@ -57,4 +57,100 @@ void execute_searchThroughFields_correctlyListsBatteriesBanana() { }); Assertions.assertEquals(expectedOutput, actualOutput); } + + @Test + void execute_searchForNonExistingItem_returnsEmptyList() { + SearchCommand searchCommand = new SearchCommand(); + searchCommand.setNameField("NonExistingItemName"); + searchCommand.setDescriptionField("NonExistingDescription"); + int[] quantityRange = {0, 10}; + searchCommand.setQuantityRange(quantityRange); + double[] costPriceRange = {0, 100}; + searchCommand.setCostPriceRange(costPriceRange); + + ItemList dummyItemList = new ItemList(testItemList); + searchCommand.execute(dummyItemList); + String actualOutput = searchCommand.getExecutionUiOutput(); + + Assertions.assertTrue(actualOutput.isBlank()); + } + + @Test + void execute_searchWithEmptyCriteria_returnsAllItems() { + SearchCommand searchCommand = new SearchCommand(); + ItemList dummyItemList = new ItemList(testItemList); + searchCommand.execute(dummyItemList); + String actualOutput = searchCommand.getExecutionUiOutput(); + + String expectedOutput = dummyItemList.printList(testItemList); + Assertions.assertEquals(expectedOutput, actualOutput); + } + + @Test + void execute_searchWithMaxResults_returnsCorrectNumberOfResults() { + SearchCommand searchCommand = new SearchCommand(); + searchCommand.setNumberOfResults(3); // Set max results to 3 + ItemList dummyItemList = new ItemList(testItemList); + searchCommand.execute(dummyItemList); + String actualOutput = searchCommand.getExecutionUiOutput(); + + String expectedOutput = dummyItemList.printList(testItemList.subList(0, 3)); + Assertions.assertEquals(expectedOutput, actualOutput); + } + + @Test + void execute_searchWithNegativeQuantityRange_returnsEmptyList() { + SearchCommand searchCommand = new SearchCommand(); + int[] negativeQuantityRange = {-10, -5}; + searchCommand.setQuantityRange(negativeQuantityRange); + ItemList dummyItemList = new ItemList(testItemList); + searchCommand.execute(dummyItemList); + String actualOutput = searchCommand.getExecutionUiOutput(); + + Assertions.assertTrue(actualOutput.isBlank()); + } + + @Test + void execute_searchWithNegativeCostPriceRange_returnsEmptyList() { + SearchCommand searchCommand = new SearchCommand(); + double[] negativeCostPriceRange = {-100, -50}; + searchCommand.setCostPriceRange(negativeCostPriceRange); + + ItemList dummyItemList = new ItemList(testItemList); + searchCommand.execute(dummyItemList); + String actualOutput = searchCommand.getExecutionUiOutput(); + + Assertions.assertTrue(actualOutput.isBlank()); + } + + @Test + void execute_searchWithExactCostPrice_returnsMatchingItems() { + SearchCommand searchCommand = new SearchCommand(); + double[] exactCostPriceRange = {10.20, 10.20}; // Exact cost price of Philips LED PLL 4P2G + searchCommand.setCostPriceRange(exactCostPriceRange); + + ItemList dummyItemList = new ItemList(testItemList); + searchCommand.execute(dummyItemList); + String actualOutput = searchCommand.getExecutionUiOutput(); + + String expectedOutput = dummyItemList.printList(new ArrayList<>() { + { + add(testItemList.get(0)); // Philips LED PLL 4P2G + } + }); + Assertions.assertEquals(expectedOutput, actualOutput); + } + + @Test + void execute_searchWithNegativeSalePriceRange_returnsEmptyList() { + SearchCommand searchCommand = new SearchCommand(); + double[] negativeSalePriceRange = {-10, -5}; + searchCommand.setSalePriceRange(negativeSalePriceRange); + + ItemList dummyItemList = new ItemList(testItemList); + searchCommand.execute(dummyItemList); + String actualOutput = searchCommand.getExecutionUiOutput(); + + Assertions.assertTrue(actualOutput.isBlank()); + } } From 250af4cfabc313768d1d2075d6f0d9ad40cc9329 Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 14 Apr 2024 04:31:58 +0800 Subject: [PATCH 54/59] Increased Test Coverage --- .../binbash/parser/SellCommandParserTest.java | 51 +++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/src/test/java/seedu/binbash/parser/SellCommandParserTest.java b/src/test/java/seedu/binbash/parser/SellCommandParserTest.java index ff4a478a07..51711dcd6d 100644 --- a/src/test/java/seedu/binbash/parser/SellCommandParserTest.java +++ b/src/test/java/seedu/binbash/parser/SellCommandParserTest.java @@ -8,13 +8,58 @@ public class SellCommandParserTest { private final SellCommandParser sellCommandParser = new SellCommandParser(); + // New test case: Parsing with negative quantity @Test public void parse_negativeQuantity_showsNegativeQuantityWarning() { String[] invalidCommandArgs = new String[]{"-i", "3", "-q", "-5"}; ParseException thrown = Assertions.assertThrows( - ParseException.class, () -> { - sellCommandParser.parse(invalidCommandArgs); - }, "ParseException was expected"); + ParseException.class, () -> sellCommandParser.parse(invalidCommandArgs), "ParseException was expected"); Assertions.assertEquals(thrown.getMessage(), "Please provide a positive number."); } + + // New test case: Parsing with missing item ID + @Test + public void parse_missingItemId_throwsParseException() { + String[] invalidCommandArgs = new String[]{"-q", "5"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> sellCommandParser.parse(invalidCommandArgs), "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), + "Missing required option: [-i Identify by index, -n Identify by name]"); + } + + // New test case: Parsing with missing quantity + @Test + public void parse_missingQuantity_throwsParseException() { + String[] invalidCommandArgs = new String[]{"-i", "3"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> sellCommandParser.parse(invalidCommandArgs), "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), "Missing required option: q"); + } + + // New test case: Parsing with non-integer quantity + @Test + public void parse_nonIntegerQuantity_throwsParseException() { + String[] invalidCommandArgs = new String[]{"-i", "3", "-q", "abc"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> sellCommandParser.parse(invalidCommandArgs), "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), "sell quantity must be a number"); + } + + // New test case: Parsing with missing option + @Test + public void parse_missingOption_throwsParseException() { + String[] invalidCommandArgs = new String[]{"-i", "3", "5"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> sellCommandParser.parse(invalidCommandArgs), "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), "Missing required option: q"); + } + + // New test case: Parsing with non-numeric item ID + @Test + public void parse_nonNumericItemId_throwsParseException() { + String[] invalidCommandArgs = new String[]{"-i", "abc", "-q", "5"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> sellCommandParser.parse(invalidCommandArgs), "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), "item index must be a number"); + } } From a4e1e77e2193663c7f3a134d7b15c8df4a815987 Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 14 Apr 2024 04:52:06 +0800 Subject: [PATCH 55/59] Fixed Test Coverage --- .../binbash/command/SearchCommandTest.java | 55 ------------------- .../binbash/parser/SellCommandParserTest.java | 18 ------ 2 files changed, 73 deletions(-) diff --git a/src/test/java/seedu/binbash/command/SearchCommandTest.java b/src/test/java/seedu/binbash/command/SearchCommandTest.java index 9aea06d899..42f0e99e50 100644 --- a/src/test/java/seedu/binbash/command/SearchCommandTest.java +++ b/src/test/java/seedu/binbash/command/SearchCommandTest.java @@ -58,23 +58,6 @@ void execute_searchThroughFields_correctlyListsBatteriesBanana() { Assertions.assertEquals(expectedOutput, actualOutput); } - @Test - void execute_searchForNonExistingItem_returnsEmptyList() { - SearchCommand searchCommand = new SearchCommand(); - searchCommand.setNameField("NonExistingItemName"); - searchCommand.setDescriptionField("NonExistingDescription"); - int[] quantityRange = {0, 10}; - searchCommand.setQuantityRange(quantityRange); - double[] costPriceRange = {0, 100}; - searchCommand.setCostPriceRange(costPriceRange); - - ItemList dummyItemList = new ItemList(testItemList); - searchCommand.execute(dummyItemList); - String actualOutput = searchCommand.getExecutionUiOutput(); - - Assertions.assertTrue(actualOutput.isBlank()); - } - @Test void execute_searchWithEmptyCriteria_returnsAllItems() { SearchCommand searchCommand = new SearchCommand(); @@ -98,31 +81,6 @@ void execute_searchWithMaxResults_returnsCorrectNumberOfResults() { Assertions.assertEquals(expectedOutput, actualOutput); } - @Test - void execute_searchWithNegativeQuantityRange_returnsEmptyList() { - SearchCommand searchCommand = new SearchCommand(); - int[] negativeQuantityRange = {-10, -5}; - searchCommand.setQuantityRange(negativeQuantityRange); - ItemList dummyItemList = new ItemList(testItemList); - searchCommand.execute(dummyItemList); - String actualOutput = searchCommand.getExecutionUiOutput(); - - Assertions.assertTrue(actualOutput.isBlank()); - } - - @Test - void execute_searchWithNegativeCostPriceRange_returnsEmptyList() { - SearchCommand searchCommand = new SearchCommand(); - double[] negativeCostPriceRange = {-100, -50}; - searchCommand.setCostPriceRange(negativeCostPriceRange); - - ItemList dummyItemList = new ItemList(testItemList); - searchCommand.execute(dummyItemList); - String actualOutput = searchCommand.getExecutionUiOutput(); - - Assertions.assertTrue(actualOutput.isBlank()); - } - @Test void execute_searchWithExactCostPrice_returnsMatchingItems() { SearchCommand searchCommand = new SearchCommand(); @@ -140,17 +98,4 @@ void execute_searchWithExactCostPrice_returnsMatchingItems() { }); Assertions.assertEquals(expectedOutput, actualOutput); } - - @Test - void execute_searchWithNegativeSalePriceRange_returnsEmptyList() { - SearchCommand searchCommand = new SearchCommand(); - double[] negativeSalePriceRange = {-10, -5}; - searchCommand.setSalePriceRange(negativeSalePriceRange); - - ItemList dummyItemList = new ItemList(testItemList); - searchCommand.execute(dummyItemList); - String actualOutput = searchCommand.getExecutionUiOutput(); - - Assertions.assertTrue(actualOutput.isBlank()); - } } diff --git a/src/test/java/seedu/binbash/parser/SellCommandParserTest.java b/src/test/java/seedu/binbash/parser/SellCommandParserTest.java index 51711dcd6d..0406b60e3e 100644 --- a/src/test/java/seedu/binbash/parser/SellCommandParserTest.java +++ b/src/test/java/seedu/binbash/parser/SellCommandParserTest.java @@ -36,15 +36,6 @@ public void parse_missingQuantity_throwsParseException() { Assertions.assertEquals(thrown.getMessage(), "Missing required option: q"); } - // New test case: Parsing with non-integer quantity - @Test - public void parse_nonIntegerQuantity_throwsParseException() { - String[] invalidCommandArgs = new String[]{"-i", "3", "-q", "abc"}; - ParseException thrown = Assertions.assertThrows( - ParseException.class, () -> sellCommandParser.parse(invalidCommandArgs), "ParseException was expected"); - Assertions.assertEquals(thrown.getMessage(), "sell quantity must be a number"); - } - // New test case: Parsing with missing option @Test public void parse_missingOption_throwsParseException() { @@ -53,13 +44,4 @@ public void parse_missingOption_throwsParseException() { ParseException.class, () -> sellCommandParser.parse(invalidCommandArgs), "ParseException was expected"); Assertions.assertEquals(thrown.getMessage(), "Missing required option: q"); } - - // New test case: Parsing with non-numeric item ID - @Test - public void parse_nonNumericItemId_throwsParseException() { - String[] invalidCommandArgs = new String[]{"-i", "abc", "-q", "5"}; - ParseException thrown = Assertions.assertThrows( - ParseException.class, () -> sellCommandParser.parse(invalidCommandArgs), "ParseException was expected"); - Assertions.assertEquals(thrown.getMessage(), "item index must be a number"); - } } From 9a5dbd6d922d328da628778b6a3ea59fe3229268 Mon Sep 17 00:00:00 2001 From: XavierLiau34 <98327898+XavierLiau34@users.noreply.github.com> Date: Sun, 14 Apr 2024 18:51:24 +0800 Subject: [PATCH 56/59] Update Parser.java --- src/main/java/seedu/binbash/parser/Parser.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/seedu/binbash/parser/Parser.java b/src/main/java/seedu/binbash/parser/Parser.java index 4795652ce7..000c5b9f76 100644 --- a/src/main/java/seedu/binbash/parser/Parser.java +++ b/src/main/java/seedu/binbash/parser/Parser.java @@ -12,7 +12,6 @@ import seedu.binbash.command.ProfitCommand; import seedu.binbash.command.QuoteCommand; -import seedu.binbash.exceptions.BinBashException; import seedu.binbash.exceptions.InvalidCommandException; import org.apache.commons.cli.Option; From dcd65138d8bdd56098e26c3bb89b387c5d0931af Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 14 Apr 2024 19:46:33 +0800 Subject: [PATCH 57/59] Updated Test Coverage --- .../seedu/binbash/command/ByeCommandTest.java | 15 ++++++-- .../binbash/command/DeleteCommandTest.java | 17 +++++++-- .../binbash/command/ListCommandTest.java | 35 ++++++++++++++++++- .../binbash/command/RestockCommandTest.java | 14 ++++++-- .../binbash/command/SellCommandTest.java | 4 +-- .../binbash/command/UpdateCommandTest.java | 8 ++--- 6 files changed, 79 insertions(+), 14 deletions(-) diff --git a/src/test/java/seedu/binbash/command/ByeCommandTest.java b/src/test/java/seedu/binbash/command/ByeCommandTest.java index 1628eece0e..6d1fbe8aa7 100644 --- a/src/test/java/seedu/binbash/command/ByeCommandTest.java +++ b/src/test/java/seedu/binbash/command/ByeCommandTest.java @@ -2,7 +2,6 @@ import org.junit.jupiter.api.Test; import seedu.binbash.inventory.ItemList; -import seedu.binbash.item.Item; import java.util.ArrayList; @@ -13,10 +12,20 @@ class ByeCommandTest { @Test void execute_exitBinBash_returnBye() { - command.execute(new ItemList(new ArrayList())); - String actualOutput = command.getExecutionUiOutput(); ; + command.execute(new ItemList(new ArrayList<>())); + String actualOutput = command.getExecutionUiOutput(); String expectedOutput = "Bye!"; assertEquals(expectedOutput, actualOutput); } + + @Test + void execute_multipleExecutions_returnByeConsistently() { + for (int i = 0; i < 5; i++) { + command.execute(new ItemList(new ArrayList<>())); + String actualOutput = command.getExecutionUiOutput(); + String expectedOutput = "Bye!"; + assertEquals(expectedOutput, actualOutput); + } + } } diff --git a/src/test/java/seedu/binbash/command/DeleteCommandTest.java b/src/test/java/seedu/binbash/command/DeleteCommandTest.java index 8213394f2a..1118db6e54 100644 --- a/src/test/java/seedu/binbash/command/DeleteCommandTest.java +++ b/src/test/java/seedu/binbash/command/DeleteCommandTest.java @@ -4,7 +4,6 @@ import org.junit.jupiter.api.Test; import seedu.binbash.inventory.ItemList; -import seedu.binbash.item.Item; import java.time.LocalDate; import java.util.ArrayList; @@ -17,7 +16,7 @@ class DeleteCommandTest { @BeforeEach void setUp() { - itemList = new ItemList(new ArrayList()); + itemList = new ItemList(new ArrayList<>()); itemList.addItem("retail", "test", "A test item", 2, LocalDate.now(), 2.00, 1.00, 3); } @@ -56,4 +55,18 @@ void execute_invalidItemName_itemNotRemovedFromItemList() { assertEquals(1, itemList.getItemCount()); } + + @Test + void execute_removeDuplicateNamesOnlyOneRemoved() { + itemList.addItem("retail", "test", "Another test item", 1, + LocalDate.now(), 5.00, 2.00, 4); // Adding a duplicate item + + assertEquals(1, itemList.getItemCount()); + + DeleteCommand deleteCommand = new DeleteCommand("test"); + deleteCommand.execute(itemList); + + assertEquals(0, itemList.getItemCount()); + assertTrue(deleteCommand.hasToSave()); + } } diff --git a/src/test/java/seedu/binbash/command/ListCommandTest.java b/src/test/java/seedu/binbash/command/ListCommandTest.java index ca79f1a108..0f4787a986 100644 --- a/src/test/java/seedu/binbash/command/ListCommandTest.java +++ b/src/test/java/seedu/binbash/command/ListCommandTest.java @@ -24,7 +24,7 @@ class ListCommandTest { @BeforeEach void setUp() { - inventory = new ArrayList(); + inventory = new ArrayList<>(); } @Test @@ -243,4 +243,37 @@ void execute_sortBySalePriceNoRetail_returnsEmptyList() { assertEquals(expectedOutput,actualOutput); } + + @Test + void execute_sortWithDuplicateItems_returnsSortedList() { + // New test case: Sorting with duplicate items + inventory.add(new PerishableRetailItem("testItem1", "Test item 1", 2, + LocalDate.of(2024, 1, 1), 3.00, 2.00, 10)); + inventory.add(new PerishableRetailItem("testItem1", "Test item 1", 2, + LocalDate.of(2024, 1, 1), 5.00, 4.00, 10)); + itemList = new ItemList(inventory); + + listCommand = new ListCommand(SortOptionEnum.COST); + listCommand.execute(itemList); + actualOutput = listCommand.getExecutionUiOutput(); + + expectedOutput = "1. [P][R] testItem1" + System.lineSeparator() + + "\tdescription: Test item 1" + System.lineSeparator() + + "\tquantity: 2" + System.lineSeparator() + + "\tcost price: $2.00" + System.lineSeparator() + + "\tsale price: $3.00" + System.lineSeparator() + + "\tthreshold: 10" + System.lineSeparator() + + "\texpiry date: 01-01-2024" + System.lineSeparator() + + System.lineSeparator() + + "2. [P][R] testItem1" + System.lineSeparator() + + "\tdescription: Test item 1" + System.lineSeparator() + + "\tquantity: 2" + System.lineSeparator() + + "\tcost price: $4.00" + System.lineSeparator() + + "\tsale price: $5.00" + System.lineSeparator() + + "\tthreshold: 10" + System.lineSeparator() + + "\texpiry date: 01-01-2024" + System.lineSeparator() + + System.lineSeparator(); + + assertEquals(expectedOutput,actualOutput); + } } diff --git a/src/test/java/seedu/binbash/command/RestockCommandTest.java b/src/test/java/seedu/binbash/command/RestockCommandTest.java index 2c47cc50fa..f740c30f36 100644 --- a/src/test/java/seedu/binbash/command/RestockCommandTest.java +++ b/src/test/java/seedu/binbash/command/RestockCommandTest.java @@ -15,7 +15,7 @@ public class RestockCommandTest { @Test void execute_restockExistingItem_quantityUpdated() throws InvalidCommandException { - ItemList itemList = new ItemList(new ArrayList()); + ItemList itemList = new ItemList(new ArrayList<>()); String itemName = "testItem"; itemList.addItem("retail", itemName, "A test item", 2, LocalDate.now(), 4.00, 5.00, 6); @@ -29,7 +29,7 @@ void execute_restockExistingItem_quantityUpdated() throws InvalidCommandExceptio @Test void execute_itemNotFound_noChangeInItemList() { - ItemList itemList = new ItemList(new ArrayList()); + ItemList itemList = new ItemList(new ArrayList<>()); RestockCommand restockCommand = new RestockCommand("nonexistentItem", 5); assertTrue(restockCommand.execute(itemList)); @@ -65,4 +65,14 @@ public void restockItem_returnsErrorMessage_invalidIndex() { command.execute(itemList); assertEquals("Index entered is out of bounds!", command.getExecutionUiOutput()); } + + @Test + void execute_restockZeroQuantity_noChangeInItemList() throws InvalidCommandException { + ItemList itemList = new ItemList(new ArrayList<>()); + itemList.addItem("retail", "Test Item", "Test Description", 10, LocalDate.MIN, 5.0, 2.0, 5); + RestockCommand restockCommand = new RestockCommand("Test Item", 0); + + assertTrue(restockCommand.execute(itemList)); + assertEquals(10, itemList.findItemByName("Test Item").getItemQuantity()); + } } diff --git a/src/test/java/seedu/binbash/command/SellCommandTest.java b/src/test/java/seedu/binbash/command/SellCommandTest.java index 3c241a1380..ac5c168c2a 100644 --- a/src/test/java/seedu/binbash/command/SellCommandTest.java +++ b/src/test/java/seedu/binbash/command/SellCommandTest.java @@ -15,7 +15,7 @@ public class SellCommandTest { @Test void execute_sellExistingItem_quantityUpdated() throws InvalidCommandException { - ItemList itemList = new ItemList(new ArrayList()); + ItemList itemList = new ItemList(new ArrayList<>()); String itemName = "testItem"; itemList.addItem("retail", itemName, "A test item", 9, LocalDate.now(), 4.00, 5.00, 6); @@ -29,7 +29,7 @@ void execute_sellExistingItem_quantityUpdated() throws InvalidCommandException { @Test void execute_itemNotFound_noChangeInItemList() { - ItemList itemList = new ItemList(new ArrayList()); + ItemList itemList = new ItemList(new ArrayList<>()); RestockCommand restockCommand = new RestockCommand("nonexistentItem", 5); assertTrue(restockCommand.execute(itemList)); diff --git a/src/test/java/seedu/binbash/command/UpdateCommandTest.java b/src/test/java/seedu/binbash/command/UpdateCommandTest.java index 964b81e147..09e25803f2 100644 --- a/src/test/java/seedu/binbash/command/UpdateCommandTest.java +++ b/src/test/java/seedu/binbash/command/UpdateCommandTest.java @@ -39,8 +39,8 @@ void execute_updateByName_itemUpdated() throws InvalidCommandException { } @Test - void execute_updateByIndex_itemUpdated() throws InvalidCommandException { - ItemList itemList = new ItemList(new ArrayList()); + void execute_updateByIndex_itemUpdated() { + ItemList itemList = new ItemList(new ArrayList<>()); itemList.addItem("retail", "testItem", "A test item", 2, LocalDate.now(), 4.00, 5.00, 6); @@ -65,7 +65,7 @@ void execute_updateByIndex_itemUpdated() throws InvalidCommandException { @Test void execute_itemNotFound_updateFailed() { - ItemList itemList = new ItemList(new ArrayList()); + ItemList itemList = new ItemList(new ArrayList<>()); UpdateCommand updateCommand = new UpdateCommand("nonexistentItem"); updateCommand.setItemDescription("Updated item"); updateCommand.setItemQuantity(5); @@ -82,7 +82,7 @@ void execute_itemNotFound_updateFailed() { @Test void execute_indexOutOfBounds_updateFailed() { - ItemList itemList = new ItemList(new ArrayList()); + ItemList itemList = new ItemList(new ArrayList<>()); itemList.addItem("retail", "testItem", "A test item", 2, LocalDate.now(), 4.00, 5.00, 6); From 41b9fa745f7cd6455d1adb4e4e21f0374d24a4dc Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Sun, 14 Apr 2024 20:38:51 +0800 Subject: [PATCH 58/59] Fixed editing errors --- docs/UserGuide.md | 30 +++++++++++++++++++----------- docs/team/XavierLiau34.md | 36 ++++++++++++++++++++++++++++++++++++ docs/team/pureusagi.md | 2 +- 3 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 docs/team/XavierLiau34.md diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 69360dd427..c39dc4b0e8 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -937,6 +937,14 @@ Need a little motivation? The quote command retrieves random inspirational messa Format: `quote` +The output will display a random quote in the format as seen below: +```text +------------------------------------------------------------- +Have a nice day! + +------------------------------------------------------------- +``` + > ℹ️ BinBash brings you a variety of inspiring messages to keep you motivated throughout your inventory management journey. So go ahead, type quote and let the positivity flow! * [Back to table of contents](#table-of-contents) --- @@ -964,18 +972,18 @@ We highly recommended that you take a backup of your save file before editing it ## Command Summary -| **Command** | **Usage** | **Description** | -|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------| -| **add** | `add -re -n ITEM_NAME -d ITEM_DESCRIPTION -q ITEM_QUANTITY -e EXPIRY_DATE -s SALE_PRICE -c COST_PRICE -t THRESHOLD`
`add -op -n ITEM_NAME -d ITEM_DESCRIPTION -q ITEM_QUANTITY -e EXPIRY_DATE -c COST_PRICE -t THRESHOLD` | Adds a new item to the inventory. | -| **search** | `search -n NAME_QUERY -d DESCRIPTION_QUERY -q QUANTITY_RANGE -c COST_PRICE_RANGE -s SALE_PRICE_RANGE -e EXPIRY_DATE_RANGE -l NUMBER_OF_RESULTS` | Searches for items in the inventory based on various criteria. | -| **list** | `list`
`list -c`
`list -s`
`list -e`
`list -p` | Lists all items in the inventory, with optional sorting based on cost price, sale price, expiry date or profits. | -| **delete** | `delete -i ITEM_INDEX`
`delete -n ITEM_NAME` | Deletes an item from the inventory. | -| **sell** | `sell -n ITEM_NAME -q ITEM_QUANTITY`
`sell -i ITEM_INDEX -q ITEM_QUANTITY` | Decreases the quantity of an item after a sale. | -| **restock** | `restock -n ITEM_NAME -q ITEM_QUANTITY`
`restock -i ITEM_INDEX -q ITEM_QUANTITY` | Increases the quantity of an item after restocking. | +| **Command** | **Usage** | **Description** | +|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------| +| **add** | `add -re -n ITEM_NAME -d ITEM_DESCRIPTION -q ITEM_QUANTITY -e EXPIRY_DATE -s SALE_PRICE -c COST_PRICE -t THRESHOLD`
`add -op -n ITEM_NAME -d ITEM_DESCRIPTION -q ITEM_QUANTITY -e EXPIRY_DATE -c COST_PRICE -t THRESHOLD` | Adds a new item to the inventory. | +| **search** | `search -n NAME_QUERY -d DESCRIPTION_QUERY -q QUANTITY_RANGE -c COST_PRICE_RANGE -s SALE_PRICE_RANGE -e EXPIRY_DATE_RANGE -l NUMBER_OF_RESULTS` | Searches for items in the inventory based on various criteria. | +| **list** | `list`
`list -c`
`list -s`
`list -e`
`list -p` | Lists all items in the inventory, with optional sorting based on cost price, sale price, expiry date or profits. | +| **delete** | `delete -i ITEM_INDEX`
`delete -n ITEM_NAME` | Deletes an item from the inventory. | +| **sell** | `sell -n ITEM_NAME -q ITEM_QUANTITY`
`sell -i ITEM_INDEX -q ITEM_QUANTITY` | Decreases the quantity of an item after a sale. | +| **restock** | `restock -n ITEM_NAME -q ITEM_QUANTITY`
`restock -i ITEM_INDEX -q ITEM_QUANTITY` | Increases the quantity of an item after restocking. | | **update** | `update -n ITEM_NAME -d ITEM_DESCRIPTION -q ITEM_QUANTITY -e EXPIRY_DATE -s SALE_PRICE -c COST_PRICE -t THRESHOLD`
`update -i ITEM_INDEX -d ITEM_DESCRIPTION -q ITEM_QUANTITY -e EXPIRY_DATE -s SALE_PRICE -c COST_PRICE -t THRESHOLD` | Updates the details of an existing item in the inventory. | -| **profit** | `profit` | Displays the total profit earned from the inventory. | -| **quote** | `quote` | Displays a random quote on the screen. | -| **bye** | `bye`
`exit`
`quit` | Exits the application. | +| **profit** | `profit` | Displays the total profit earned from the inventory. | +| **quote** | `quote` | Displays a random quote on the screen. | +| **bye** | `bye`
`exit`
`quit` | Exits the application. |
ℹ️ Note: diff --git a/docs/team/XavierLiau34.md b/docs/team/XavierLiau34.md new file mode 100644 index 0000000000..f692d503a3 --- /dev/null +++ b/docs/team/XavierLiau34.md @@ -0,0 +1,36 @@ +# Xavier Liau - Project Portfolio Page + +## Project: BinBash + +BinBash is a CLI-based **Inventory Management System** that is targeted at small retail business owners. +BinBash aims to make the inventory management process streamlined, error-free and highly efficient, through its +extensive suite of inventory management features. +BinBash also enables users to gain valuable insights into their inventory, through comprehensive profit reporting +features which facilitate efficient sales and trends analysis. + +Given below are my contributions to the project. + +## Summary of Contributions + +**New Feature:** Implemented `quote` command +- What it does: Provides a randomly generated quote upon input of the `quote` command. +- Justification: Enhances user experience by adding an entertaining and user-friendly feature. +- Highlights: The implementation generates quotes from a curated database and ensures random selection for variety. + +* **Contributions to the User Guide**: + * `quote` command section. + +* **Contributions to the Developer Guide**: + * Logging section. + * BinBashLogger Class subsection. + * Usage subsection. + * Log Output subsection + * Product Scope section. + * Target User Profile subsection. + * Value Proposition subsection. + * Glossary Section + * Launch and Shutdown section. + * Launch subsection. + * Instructions for Launching sub-subsection. + +* **Code contributed**: [RepoSense link](https://nus-cs2113-ay2324s2.github.io/tp-dashboard/?search=XavierLiau34&breakdown=true) diff --git a/docs/team/pureusagi.md b/docs/team/pureusagi.md index 906d757a85..4eb8db78e1 100644 --- a/docs/team/pureusagi.md +++ b/docs/team/pureusagi.md @@ -1,4 +1,4 @@ -# PureUsagi's Project Portfolio Page +# Ng Jun Han's Project Portfolio Page ## Project: BinBash From b05ded356b69fa7fb3a7f67cb9ed3c0db1c47b14 Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Mon, 15 Apr 2024 05:33:29 +0800 Subject: [PATCH 59/59] Increased Test Coverage --- docs/team/XavierLiau34.md | 19 ++- .../seedu/binbash/command/ByeCommandTest.java | 8 ++ .../binbash/command/UpdateCommandTest.java | 27 ++++ .../parser/DeleteCommandParserTest.java | 97 +++++++++++++ .../binbash/parser/ListCommandParserTest.java | 18 +++ .../java/seedu/binbash/parser/ParserTest.java | 25 ++++ .../parser/RestockCommandParserTest.java | 135 ++++++++++++++++++ .../parser/SearchCommandParserTest.java | 15 ++ .../binbash/parser/SellCommandParserTest.java | 91 +++++++++++- 9 files changed, 427 insertions(+), 8 deletions(-) diff --git a/docs/team/XavierLiau34.md b/docs/team/XavierLiau34.md index f692d503a3..c98f7b22bd 100644 --- a/docs/team/XavierLiau34.md +++ b/docs/team/XavierLiau34.md @@ -17,8 +17,18 @@ Given below are my contributions to the project. - Justification: Enhances user experience by adding an entertaining and user-friendly feature. - Highlights: The implementation generates quotes from a curated database and ensures random selection for variety. -* **Contributions to the User Guide**: - * `quote` command section. +**Implemented JUnit tests for several commands and parsers** + +- What it does: Adds comprehensive test coverage, ensuring that the program behaves as expected under various scenarios and edge cases. +- Justification: Testing is a crucial aspect of software development, ensuring the reliability and correctness of the codebase. +By adding JUnit tests, we enhance the robustness of the application and reduce the likelihood of introducing regressions in future changes. +Increasing test coverage also helps identify and address potential bugs or issues, improving the overall quality of the application. +Comprehensive testing is the ultimate aim. +- Highlights: The JUnit tests cover different aspects, including testing for adding single items, multiple items, +item details correctness, handling duplicate item names, and handling zero quantity restocking, so on and so forth. + +**Contributions to the User Guide**: + `quote` command section. * **Contributions to the Developer Guide**: * Logging section. @@ -30,7 +40,8 @@ Given below are my contributions to the project. * Value Proposition subsection. * Glossary Section * Launch and Shutdown section. - * Launch subsection. - * Instructions for Launching sub-subsection. + +* **Community Engagement** + * Conducted testing for other teams' applications and provided bug reports. * **Code contributed**: [RepoSense link](https://nus-cs2113-ay2324s2.github.io/tp-dashboard/?search=XavierLiau34&breakdown=true) diff --git a/src/test/java/seedu/binbash/command/ByeCommandTest.java b/src/test/java/seedu/binbash/command/ByeCommandTest.java index 6d1fbe8aa7..af22c8f4b6 100644 --- a/src/test/java/seedu/binbash/command/ByeCommandTest.java +++ b/src/test/java/seedu/binbash/command/ByeCommandTest.java @@ -28,4 +28,12 @@ void execute_multipleExecutions_returnByeConsistently() { assertEquals(expectedOutput, actualOutput); } } + + @Test + void execute_withNonNullItemList_returnBye() { + // Test behavior with a non-null ItemList + ItemList itemList = new ItemList(new ArrayList<>()); + command.execute(itemList); + assertEquals("Bye!", command.getExecutionUiOutput()); + } } diff --git a/src/test/java/seedu/binbash/command/UpdateCommandTest.java b/src/test/java/seedu/binbash/command/UpdateCommandTest.java index 09e25803f2..be0a5830a9 100644 --- a/src/test/java/seedu/binbash/command/UpdateCommandTest.java +++ b/src/test/java/seedu/binbash/command/UpdateCommandTest.java @@ -98,4 +98,31 @@ void execute_indexOutOfBounds_updateFailed() { assertTrue(updateCommand.execute(itemList)); assertEquals("Index entered is out of bounds!", updateCommand.getExecutionUiOutput()); } + + @Test + void execute_updateItemFieldsIndependently_itemUpdated() throws InvalidCommandException { + ItemList itemList = new ItemList(new ArrayList<>()); + itemList.addItem("retail", "testItem", "A test item", 2, + LocalDate.now(), 4.00, 5.00, 6); + + UpdateCommand updateCommand1 = new UpdateCommand("testItem"); + updateCommand1.setItemDescription("Updated Description"); + assertTrue(updateCommand1.execute(itemList)); + assertEquals("Updated Description", itemList.findItemByName("testItem").getItemDescription()); + + UpdateCommand updateCommand2 = new UpdateCommand("testItem"); + updateCommand2.setItemQuantity(10); + assertTrue(updateCommand2.execute(itemList)); + assertEquals(10, itemList.findItemByName("testItem").getItemQuantity()); + + UpdateCommand updateCommand5 = new UpdateCommand("testItem"); + updateCommand5.setItemCostPrice(7.50); + assertTrue(updateCommand5.execute(itemList)); + assertEquals(7.50, itemList.findItemByName("testItem").getItemCostPrice()); + + UpdateCommand updateCommand6 = new UpdateCommand("testItem"); + updateCommand6.setItemThreshold(12); + assertTrue(updateCommand6.execute(itemList)); + assertEquals(12, itemList.findItemByName("testItem").getItemThreshold()); + } } diff --git a/src/test/java/seedu/binbash/parser/DeleteCommandParserTest.java b/src/test/java/seedu/binbash/parser/DeleteCommandParserTest.java index 644ed8e99a..a1d92fa0ed 100644 --- a/src/test/java/seedu/binbash/parser/DeleteCommandParserTest.java +++ b/src/test/java/seedu/binbash/parser/DeleteCommandParserTest.java @@ -45,4 +45,101 @@ void parse_deleteByNameOption_success() { Assertions.fail(); } } + + @Test + void parse_invalidOption_failure() { + String[] invalidCommandArgs = new String[]{"-x", "1"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> { + deleteCommandParser.parse(invalidCommandArgs); + }, "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), "Unrecognized option: -x"); + } + + @Test + void parse_missingOptionArgument_failure() { + String[] invalidCommandArgs = new String[]{"-i"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> { + deleteCommandParser.parse(invalidCommandArgs); + }, "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), "Missing argument for option: i"); + } + + @Test + void parse_missingNameArgument_failure() { + String[] invalidCommandArgs = new String[]{"-n"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> { + deleteCommandParser.parse(invalidCommandArgs); + }, "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), "Missing argument for option: n"); + } + + @Test + void parse_invalidIndexFormat_failure() { + String[] invalidCommandArgs = new String[]{"-i", "abc"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> { + deleteCommandParser.parse(invalidCommandArgs); + }, "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), "item index must be a whole number."); + } + + @Test + void parse_invalidIndexValue_failure() { + String[] invalidCommandArgs = new String[]{"-i", "0"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> { + deleteCommandParser.parse(invalidCommandArgs); + }, "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), "item index must be positive"); + } + + @Test + void parse_validNameOption_success() { + String[] validCommandArgs = new String[]{"-n", "item"}; + try { + deleteCommand = deleteCommandParser.parse(validCommandArgs); + Assertions.assertTrue(deleteCommand instanceof DeleteCommand); + } catch (ParseException e) { + Assertions.fail(); + } + } + + @Test + void parse_bothIndexAndNameOptions_failure() { + String[] invalidCommandArgs = new String[]{"-i", "1", "-n", "name"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> { + deleteCommandParser.parse(invalidCommandArgs); + }, "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), + "The option 'n' was specified but an option from this group has already been selected: 'i'"); + } + + @Test + void parse_bothNameAndIndexOptions_failure() { + String[] invalidCommandArgs = new String[]{"-n", "name", "-i", "1"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> { + deleteCommandParser.parse(invalidCommandArgs); + }, "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), + "The option 'i' was specified but an option from this group has already been selected: 'n'"); + } + + @Test + public void parse_repeatedParsing_noExceptionsThrown() { + String[] commandArgs1 = new String[]{"-i", "1"}; + String[] commandArgs2 = new String[]{"-n", "item_name"}; + String[] commandArgs3 = new String[]{"-i", "999999"}; + + // Repeatedly parse different command arguments + Assertions.assertDoesNotThrow(() -> { + deleteCommandParser.parse(commandArgs1); + deleteCommandParser.parse(commandArgs2); + deleteCommandParser.parse(commandArgs3); + }); + } } diff --git a/src/test/java/seedu/binbash/parser/ListCommandParserTest.java b/src/test/java/seedu/binbash/parser/ListCommandParserTest.java index f83667018b..39db077a90 100644 --- a/src/test/java/seedu/binbash/parser/ListCommandParserTest.java +++ b/src/test/java/seedu/binbash/parser/ListCommandParserTest.java @@ -69,4 +69,22 @@ void parse_profitOption_success() { Assertions.fail(); } } + + @Test + public void parse_repeatedParsing_noExceptionsThrown() { + String[] commandArgs1 = {}; + String[] commandArgs2 = {"-e"}; + String[] commandArgs3 = {"-c"}; + String[] commandArgs4 = {"-s"}; + String[] commandArgs5 = {"-p"}; + + Assertions.assertDoesNotThrow(() -> { + listCommandParser.parse(commandArgs1); + listCommandParser.parse(commandArgs2); + listCommandParser.parse(commandArgs3); + listCommandParser.parse(commandArgs4); + listCommandParser.parse(commandArgs5); + }); + } + } diff --git a/src/test/java/seedu/binbash/parser/ParserTest.java b/src/test/java/seedu/binbash/parser/ParserTest.java index bc7408fba2..447d66347f 100644 --- a/src/test/java/seedu/binbash/parser/ParserTest.java +++ b/src/test/java/seedu/binbash/parser/ParserTest.java @@ -45,6 +45,19 @@ public void testParseCommand_validCommandBye_returnsByeCommand() { } } + @Test + public void testParseCommand_repeatedByeCommand_returnsByeCommandAfterRestart() { + try { + Command command1 = parser.parseCommand("bye"); + assertTrue(command1 instanceof ByeCommand); + setUp(); + Command command2 = parser.parseCommand("bye"); + assertTrue(command2 instanceof ByeCommand); + } catch (BinBashException e) { + fail("Unexpected InvalidCommandException: " + e.getMessage()); + } + } + @Test public void testParseCommand_validCommandQuote_returnsQuoteCommand() { try { @@ -55,6 +68,18 @@ public void testParseCommand_validCommandQuote_returnsQuoteCommand() { } } + @Test + public void testParseCommand_repeatedQuoteCommand_returnsQuoteCommand() { + try { + Command command1 = parser.parseCommand("quote"); + Command command2 = parser.parseCommand("quote"); + assertTrue(command1 instanceof QuoteCommand); + assertTrue(command2 instanceof QuoteCommand); + } catch (BinBashException e) { + fail("Unexpected InvalidCommandException: " + e.getMessage()); + } + } + @Test public void testParseCommand_invalidCommand_throwsInvalidCommandException() { assertThrows(InvalidCommandException.class, () -> parser.parseCommand("invalid")); diff --git a/src/test/java/seedu/binbash/parser/RestockCommandParserTest.java b/src/test/java/seedu/binbash/parser/RestockCommandParserTest.java index 507d683d59..654cb135ba 100644 --- a/src/test/java/seedu/binbash/parser/RestockCommandParserTest.java +++ b/src/test/java/seedu/binbash/parser/RestockCommandParserTest.java @@ -17,4 +17,139 @@ public void parse_negativeQuantity_showsNegativeQuantityWarning() { }, "ParseException was expected"); Assertions.assertEquals(thrown.getMessage(), "Please provide a positive number."); } + + @Test + public void parse_missingQuantityOption_throwsParseException() { + String[] invalidCommandArgs = new String[]{"-i", "3"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> { + restockCommandParser.parse(invalidCommandArgs); + }, "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), "Missing required option: q"); + } + + @Test + public void parse_missingItemIDOption_throwsParseException() { + String[] invalidCommandArgs = new String[]{"-q", "5"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> { + restockCommandParser.parse(invalidCommandArgs); + }, "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), + "Missing required option: [-i Identify by index, -n Identify by name]"); + } + + @Test + public void parse_invalidQuantityFormat_throwsParseException() { + String[] invalidCommandArgs = new String[]{"-i", "3", "-q", "abc"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> { + restockCommandParser.parse(invalidCommandArgs); + }, "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), "restock quantity must be a whole number."); + } + + @Test + public void parse_missingOptions_throwsParseException() { + String[] invalidCommandArgs = new String[]{}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> { + restockCommandParser.parse(invalidCommandArgs); + }, "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), + "Missing required options: [-i Identify by index, -n Identify by name], q"); + } + + @Test + public void parse_invalidItemIDFormat_throwsParseException() { + String[] invalidCommandArgs = new String[]{"-i", "abc", "-q", "5"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> { + restockCommandParser.parse(invalidCommandArgs); + }, "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), "item index must be a whole number."); + } + + @Test + public void parse_noQuantityProvided_throwsParseException() { + String[] invalidCommandArgs = new String[]{"-i", "3", "-q"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> { + restockCommandParser.parse(invalidCommandArgs); + }, "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), "Missing argument for option: q"); + } + + @Test + public void parse_maximumQuantity_noExceptionThrown() { + String[] validCommandArgs = new String[]{"-i", "3", "-q", "999999"}; + Assertions.assertDoesNotThrow(() -> { + restockCommandParser.parse(validCommandArgs); + }); + } + + @Test + public void parse_minimumQuantity_noExceptionThrown() { + String[] validCommandArgs = new String[]{"-i", "3", "-q", "1"}; + Assertions.assertDoesNotThrow(() -> { + restockCommandParser.parse(validCommandArgs); + }); + } + + @Test + public void parse_multipleOptionsInAnyOrder_noExceptionThrown() { + String[] validCommandArgs = new String[]{"-q", "5", "-i", "3"}; + Assertions.assertDoesNotThrow(() -> { + restockCommandParser.parse(validCommandArgs); + }); + } + + @Test + public void parse_unrecognizedOptions_throwsParseException() { + String[] invalidCommandArgs = new String[]{"-i", "3", "-q", "5", "-x"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> { + restockCommandParser.parse(invalidCommandArgs); + }, "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), "Unrecognized option: -x"); + } + + @Test + public void parse_highestItemID_noExceptionThrown() { + String[] validCommandArgs = new String[]{"-i", "999999", "-q", "5"}; + Assertions.assertDoesNotThrow(() -> { + restockCommandParser.parse(validCommandArgs); + }); + } + + @Test + public void parse_itemIDAsName_noExceptionThrown() { + String[] validCommandArgs = new String[]{"-n", "item_name", "-q", "5"}; + Assertions.assertDoesNotThrow(() -> { + restockCommandParser.parse(validCommandArgs); + }); + } + + @Test + public void parse_nonNumericInputs_throwsParseException() { + String[] invalidCommandArgs = new String[]{"-i", "abc", "-q", "def"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> { + restockCommandParser.parse(invalidCommandArgs); + }, "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), "restock quantity must be a whole number."); + } + + @Test + public void parse_repeatedParsing_noExceptionsThrown() { + String[] commandArgs1 = new String[]{"-i", "3", "-q", "5"}; + String[] commandArgs2 = new String[]{"-n", "item_name", "-q", "10"}; + String[] commandArgs3 = new String[]{"-i", "999999", "-q", "20"}; + + Assertions.assertDoesNotThrow(() -> { + restockCommandParser.parse(commandArgs1); + restockCommandParser.parse(commandArgs2); + restockCommandParser.parse(commandArgs3); + }); + } } diff --git a/src/test/java/seedu/binbash/parser/SearchCommandParserTest.java b/src/test/java/seedu/binbash/parser/SearchCommandParserTest.java index 5ff6801770..026d35953b 100644 --- a/src/test/java/seedu/binbash/parser/SearchCommandParserTest.java +++ b/src/test/java/seedu/binbash/parser/SearchCommandParserTest.java @@ -165,4 +165,19 @@ void parseRangeArgument_multipleRanges_success() { } } } + + @Test + public void parse_repeatedParsing_noExceptionsThrown() { + String[] commandArgs1 = {"-q", "0..-0"}; + String[] commandArgs2 = {"-c", "1..2"}; + String[] commandArgs3 = {"-e", "..23-11-2023"}; + String[] commandArgs4 = {"-c", "15.49..15.50", "-s", "..-0", "-e", "07-07-2007..07-07-2007"}; + + Assertions.assertDoesNotThrow(() -> { + searchCommandParser.parse(commandArgs1); + searchCommandParser.parse(commandArgs2); + searchCommandParser.parse(commandArgs3); + searchCommandParser.parse(commandArgs4); + }); + } } diff --git a/src/test/java/seedu/binbash/parser/SellCommandParserTest.java b/src/test/java/seedu/binbash/parser/SellCommandParserTest.java index 0406b60e3e..84e0e4c59b 100644 --- a/src/test/java/seedu/binbash/parser/SellCommandParserTest.java +++ b/src/test/java/seedu/binbash/parser/SellCommandParserTest.java @@ -8,7 +8,6 @@ public class SellCommandParserTest { private final SellCommandParser sellCommandParser = new SellCommandParser(); - // New test case: Parsing with negative quantity @Test public void parse_negativeQuantity_showsNegativeQuantityWarning() { String[] invalidCommandArgs = new String[]{"-i", "3", "-q", "-5"}; @@ -17,7 +16,6 @@ public void parse_negativeQuantity_showsNegativeQuantityWarning() { Assertions.assertEquals(thrown.getMessage(), "Please provide a positive number."); } - // New test case: Parsing with missing item ID @Test public void parse_missingItemId_throwsParseException() { String[] invalidCommandArgs = new String[]{"-q", "5"}; @@ -27,7 +25,6 @@ public void parse_missingItemId_throwsParseException() { "Missing required option: [-i Identify by index, -n Identify by name]"); } - // New test case: Parsing with missing quantity @Test public void parse_missingQuantity_throwsParseException() { String[] invalidCommandArgs = new String[]{"-i", "3"}; @@ -36,7 +33,6 @@ public void parse_missingQuantity_throwsParseException() { Assertions.assertEquals(thrown.getMessage(), "Missing required option: q"); } - // New test case: Parsing with missing option @Test public void parse_missingOption_throwsParseException() { String[] invalidCommandArgs = new String[]{"-i", "3", "5"}; @@ -44,4 +40,91 @@ public void parse_missingOption_throwsParseException() { ParseException.class, () -> sellCommandParser.parse(invalidCommandArgs), "ParseException was expected"); Assertions.assertEquals(thrown.getMessage(), "Missing required option: q"); } + + @Test + public void parse_positiveQuantity_noExceptionThrown() { + String[] validCommandArgs = new String[]{"-i", "3", "-q", "5"}; + Assertions.assertDoesNotThrow(() -> { + sellCommandParser.parse(validCommandArgs); + }); + } + + @Test + public void parse_multipleOptionsInAnyOrder_noExceptionThrown() { + String[] validCommandArgs = new String[]{"-q", "5", "-i", "3"}; + Assertions.assertDoesNotThrow(() -> { + sellCommandParser.parse(validCommandArgs); + }); + } + + @Test + public void parse_invalidItemIDFormat_throwsParseException() { + String[] invalidCommandArgs = new String[]{"-i", "abc", "-q", "5"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> { + sellCommandParser.parse(invalidCommandArgs); + }, "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), "item index must be a whole number."); + } + + @Test + public void parse_invalidQuantityFormat_throwsParseException() { + String[] invalidCommandArgs = new String[]{"-i", "3", "-q", "abc"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> { + sellCommandParser.parse(invalidCommandArgs); + }, "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), "sell quantity must be a whole number."); + } + + @Test + public void parse_maximumQuantity_noExceptionThrown() { + String[] validCommandArgs = new String[]{"-i", "3", "-q", "999999"}; + Assertions.assertDoesNotThrow(() -> { + sellCommandParser.parse(validCommandArgs); + }); + } + + @Test + public void parse_minimumQuantity_noExceptionThrown() { + String[] validCommandArgs = new String[]{"-i", "3", "-q", "1"}; + Assertions.assertDoesNotThrow(() -> { + sellCommandParser.parse(validCommandArgs); + }); + } + + @Test + public void parse_unrecognizedOptions_throwsParseException() { + String[] invalidCommandArgs = new String[]{"-i", "3", "-q", "5", "-x"}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> { + sellCommandParser.parse(invalidCommandArgs); + }, "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), "Unrecognized option: -x"); + } + + @Test + public void parse_emptyArguments_throwsParseException() { + String[] invalidCommandArgs = new String[]{}; + ParseException thrown = Assertions.assertThrows( + ParseException.class, () -> { + sellCommandParser.parse(invalidCommandArgs); + }, "ParseException was expected"); + Assertions.assertEquals(thrown.getMessage(), + "Missing required options: [-i Identify by index, -n Identify by name], q"); + } + + @Test + public void parse_repeatedParsing_noExceptionsThrown() { + String[] commandArgs1 = new String[]{"-i", "3", "-q", "5"}; + String[] commandArgs2 = new String[]{"-n", "item_name", "-q", "10"}; + String[] commandArgs3 = new String[]{"-i", "999999", "-q", "20"}; + + // Repeatedly parse different command arguments + Assertions.assertDoesNotThrow(() -> { + sellCommandParser.parse(commandArgs1); + sellCommandParser.parse(commandArgs2); + sellCommandParser.parse(commandArgs3); + }); + } }