Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Shu committed Apr 15, 2024
2 parents 2d72115 + ae37ea6 commit 9d4caee
Show file tree
Hide file tree
Showing 16 changed files with 279 additions and 20 deletions.
Empty file added StockMasterData.txt
Empty file.
Binary file modified docs/Diagrams/Images/Itemlist/AddCommand_SequenceDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/Diagrams/Images/Storage/Storage.png
Binary file not shown.
Binary file modified docs/Diagrams/Images/Storage/Storage_ClassDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file modified docs/Diagrams/Images/Storage/Storage_sequenceDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,31 @@
!include ../Style.puml

actor User
participant "Parser" as Parser
participant "AddCommand" as AddCommand
participant "Itemlist" as Itemlist
participant "EditCommand" as EditCommand
participant ":Parser" as Parser
participant ":AddCommand" as AddCommand
participant ":Itemlist" as Itemlist
participant ":EditCommand" as EditCommand

User -> Parser: add command
activate Parser

Parser -> AddCommand: prepareAdd(userInput)
activate AddCommand
AddCommand -> Itemlist: itemIsExist(itemName)
activate Itemlist
alt Item exists
Itemlist -> AddCommand: true
AddCommand -> EditCommand: edit Item
activate EditCommand
EditCommand -> Itemlist: editQuantity(index, newQuantity)
deactivate EditCommand
Itemlist --> AddCommand
AddCommand -> User: Output success message
else Item does not exist
Itemlist -> AddCommand: false
AddCommand -> Itemlist: addItem(item)
deactivate Itemlist
Itemlist --> AddCommand

AddCommand -> User: Output success message
deactivate AddCommand
deactivate Parser
end
deactivate Itemlist
deactivate Parser
@enduml
2 changes: 1 addition & 1 deletion docs/Diagrams/PUML files/Storage/Storage_ClassDiagram.puml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@startuml
hide circle
!include ../Style.puml

class Storage {
+readFromFile(fileName: String)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@startuml
hide footbox
!include ../Style.puml
participant Client
participant Storage
participant Itemlist
Expand Down
8 changes: 6 additions & 2 deletions docs/team/Fureimi.md → docs/team/fureimi.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ manage and operate their business.
to keep track of their inventory. It also provides a convenient way for users to check a item of a certain category as
they may have many items in the whole item list, making it hard to search for specific items. In addition, users might
only want to see their marked items. The mark feature is explained below.

- **New Feature**: Added the ability to mark and unmark specific items in the item list.
- **What it does**: Allows users to mark specific item in the item list. The user can also unmark a marked item.
- **Justification**: Users might want to mark items for many reasons, such as to keep track of their sales as they
may be a high in demand item. These items might also be from different categories, so user cannot list them by
category. This feature hence provides a convenient way for users to access items they want to keep an eye on.

- **New Feature**: Added the ability to edit current item parameters.
- **What it does**: Allows users to edit specific parameters of existing items, such as quantity, category, name, etc.
- **Justification**: This feature is crucial to our application as it allows users to rectify user errors when
Expand All @@ -30,11 +32,13 @@ only want to see their marked items. The mark feature is explained below.
- **Highlights**: The implementation was challenging as it required integration with `Itemlist` as well as `item` to
ensure that the parameters are edited accurately. In addition, this enhancement allows users to edit multiple
parameters at once, which increases convenience for the user.
- **Code Contributed** : [RepoSense Link](https://nus-cs2113-ay2324s2.github.io/tp-dashboard/?search=&sort=groupTitle&sortWithin=title&timeframe=commit&mergegroup=&groupSelect=groupByRepos&breakdown=true&checkedFileTypes=docs~functional-code~test-code~other&since=2024-02-23&tabOpen=true&tabType=authorship&tabAuthor=Fureimi&tabRepo=AY2324S2-CS2113-T15-4%2Ftp%5Bmaster%5D&authorshipIsMergeGroup=false&authorshipFileTypes=docs~functional-code~test-code&authorshipIsBinaryFileTypeChecked=false&authorshipIsIgnoredFilesChecked=false)

- **Code Contributed** : [RepoSense Link](https://nus-cs2113-ay2324s2.github.io/tp-dashboard/?search=fureimi&breakdown=true)

- **Documentation**:
- User Guide:
- Added documentation for the features `list_items`, `mark`, `unmark` and `edit`
- Update the command summary
- Developer Guide:
- Added class diagram of the `EditCommand` class.
- Added implementation details and sequence diagram of both the `list_items` and `edit` features.
- Added implementation details and sequence diagram of both the `list_items` and `edit` features.
20 changes: 19 additions & 1 deletion docs/team/joellimjr.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ manage and operate their business.
and warn the user about the items that are running low in stock.


- **New Feature:** Detailed help command
- What it does: An extension of the help command, it gives users more detailed information about
a specific command along with examples.
- Justification: Some of the commands have many input variables, some of which are optional.
This feature aims to help users understand the specific requirements of the commands


- **Code Contributed:** [RepoSense link](https://nus-cs2113-ay2324s2.github.io/tp-dashboard/?search=&sort=groupTitle&sortWithin=title&timeframe=commit&mergegroup=&groupSelect=groupByRepos&breakdown=true&checkedFileTypes=docs~functional-code~test-code~other&since=2024-02-23&tabOpen=true&tabType=authorship&tabAuthor=Joellimjr&tabRepo=AY2324S2-CS2113-T15-4%2Ftp%5Bmaster%5D&authorshipIsMergeGroup=false&authorshipFileTypes=docs~functional-code~test-code&authorshipIsBinaryFileTypeChecked=false&authorshipIsIgnoredFilesChecked=false)


Expand All @@ -48,4 +55,15 @@ manage and operate their business.
- Update the command summary
- Developer Guide:
- Added implementation details and class diagram of the `Parser` class.
- Added implementation details and sequence diagram of the `add` feature.
- Added implementation details and sequence diagram of the `add` feature.


- **J-Unit Testing**
- Added J-Unit testing:
- ParserTest
- AddCommandTest
- EditCommandTest
- HelpCommandTest
- SellCommandTest
- LowStockCommandTest

2 changes: 1 addition & 1 deletion src/main/java/command/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public float getNewSellPrice() {
}

/**
* Edits the relevant params of the item in the item list
* Edits the relevant params of the item in the item list and prints out to the user.
*/
@Override
public void execute() {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/storage/PromotionStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public static void readFromFile(String fileName) {
} catch (InvalidDateException | CommandFormatException e) {
LOGGER.log(Level.WARNING, "Other exception occurred.", e);
System.out.println(e);;
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(fileName + " is not written in a correct format.");
LOGGER.warning("Incorrect documentation format.");
}
scanner.close();
}
Expand Down
146 changes: 146 additions & 0 deletions src/test/java/command/EditCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package command;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import itemlist.Itemlist;
import promotion.Promotionlist;
import storage.PromotionStorage;
import storage.Storage;
import storage.TransactionLogs;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class EditCommandTest {

private final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();

@BeforeEach
public void setUp() {
System.setOut(new PrintStream(outputStreamCaptor));
}

@AfterEach
void tearDown() {
// This will be run after each test, cleaning up
Itemlist.getItems().clear(); // clear the list for next test
Promotionlist.getAllPromotion().clear();
Storage.updateFile("", false);
PromotionStorage.updateFile("", false);
TransactionLogs.updateFile("", false);
}

@Test
public void testExecuteEditItemNotFound() {
new EditCommand("NonExistentItem", "NewTestItem", -1, "NA", "NA", -1, -1).execute();
String expectedOutput = "item not found!" + System.lineSeparator() +
"End of Edits" + System.lineSeparator() + System.lineSeparator();
assertEquals(expectedOutput, outputStreamCaptor.toString());
}

@Test
public void testExecuteEditItemName() {
new AddCommand("TestItem", 10, "pcs", "TestCategory", 5.0f, 10.0f).execute();
new EditCommand("TestItem", "NewTestItem", -1, "NA", "NA", -1, -1).execute();
String expectedOutput = "added: testitem (Qty: 10 pcs, Buy: $5.00, Sell: $10.00) to TestCategory" +
System.lineSeparator() + "\n" +
"Edited: " + System.lineSeparator() +
"Name of TestItem from TestItem to NewTestItem" + System.lineSeparator() +
"End of Edits" + System.lineSeparator() + System.lineSeparator();
assertEquals(expectedOutput, outputStreamCaptor.toString());
}

@Test
public void testExecuteEditQuantity() {
new AddCommand("TestItem", 10, "pcs", "TestCategory", 5.0f, 10.0f).execute();
new EditCommand("TestItem", "NA", 50, "NA", "NA", -1, -1).execute();
String expectedOutput = "added: testitem (Qty: 10 pcs, Buy: $5.00, Sell: $10.00) to TestCategory" +
System.lineSeparator() + "\n" +
"Edited: " + System.lineSeparator() +
"Quantity of TestItem from 10 to 50" + System.lineSeparator() +
"End of Edits" + System.lineSeparator() + System.lineSeparator();
assertEquals(expectedOutput, outputStreamCaptor.toString());
}

@Test
public void testExecuteEditInvalidQuantity() {
new AddCommand("TestItem", 10, "pcs", "TestCategory", 5.0f, 10.0f).execute();
new EditCommand("TestItem", "NA", -100, "NA", "NA", -1, -1).execute();
String expectedOutput = "added: testitem (Qty: 10 pcs, Buy: $5.00, Sell: $10.00) to TestCategory" +
System.lineSeparator() + "\n" +
"Edited: " + System.lineSeparator() +
"Quantity of TestItem from 10 to -100" + System.lineSeparator() +
"End of Edits" + System.lineSeparator() + System.lineSeparator();
assertEquals(expectedOutput, outputStreamCaptor.toString());
}

@Test
public void testExecuteEditUnitOfMeasurement() {
new AddCommand("TestItem", 10, "pcs", "TestCategory", 5.0f, 10.0f).execute();
new EditCommand("TestItem", "NA", -1, "kg", "NA", -1, -1).execute();
String expectedOutput = "added: testitem (Qty: 10 pcs, Buy: $5.00, Sell: $10.00) to TestCategory" +
System.lineSeparator() + "\n" +
"Edited: " + System.lineSeparator() +
"Unit of Measurement of TestItem from pcs to kg" + System.lineSeparator() +
"End of Edits" + System.lineSeparator() + System.lineSeparator();
assertEquals(expectedOutput, outputStreamCaptor.toString());
}

@Test
public void testExecuteEditCategory() {
new AddCommand("TestItem", 10, "pcs", "TestCategory", 5.0f, 10.0f).execute();
new EditCommand("TestItem", "NA", -1, "NA", "NewTestCategory", -1, -1).execute();
String expectedOutput = "added: testitem (Qty: 10 pcs, Buy: $5.00, Sell: $10.00) to TestCategory" +
System.lineSeparator() + "\n" +
"Edited: " + System.lineSeparator() +
"Category of TestItem from TestCategory to NewTestCategory" + System.lineSeparator() +
"End of Edits" + System.lineSeparator() + System.lineSeparator();
assertEquals(expectedOutput, outputStreamCaptor.toString());
}

@Test
public void testExecuteEditBuyPrice() {
new AddCommand("TestItem", 10, "pcs", "TestCategory", 5.0f, 10.0f).execute();
new EditCommand("TestItem", "NA", -1, "NA", "NA", 6.0f, -1).execute();
String expectedOutput = "added: testitem (Qty: 10 pcs, Buy: $5.00, Sell: $10.00) to TestCategory" +
System.lineSeparator() + "\n" +
"Edited: " + System.lineSeparator() +
"Buy Price of TestItem from 5.0 to 6.00" + System.lineSeparator() +
"End of Edits" + System.lineSeparator() + System.lineSeparator();
assertEquals(expectedOutput, outputStreamCaptor.toString());
}

@Test
public void testExecuteEditSellPrice() {
new AddCommand("TestItem", 10, "pcs", "TestCategory", 5.0f, 10.0f).execute();
new EditCommand("TestItem", "NA", -1, "NA", "NA", -1, 12.0f).execute();
String expectedOutput = "added: testitem (Qty: 10 pcs, Buy: $5.00, Sell: $10.00) to TestCategory" +
System.lineSeparator() + "\n" +
"Edited: " + System.lineSeparator() +
"Sell Price of TestItem from 10.0 to 12.00" + System.lineSeparator() +
"End of Edits" + System.lineSeparator() + System.lineSeparator();
assertEquals(expectedOutput, outputStreamCaptor.toString());
}

@Test
public void testExecuteEditMultipleAttributes() {
new AddCommand("TestItem", 10, "pcs", "TestCategory", 5.0f, 10.0f).execute();
new EditCommand("TestItem", "NewTestItem", 50, "kg", "NewTestCategory", 6.0f, 12.0f).execute();
String expectedOutput = "added: testitem (Qty: 10 pcs, Buy: $5.00, Sell: $10.00) to TestCategory" +
System.lineSeparator() + "\n" +
"Edited: " + System.lineSeparator() +
"Name of TestItem from TestItem to NewTestItem" + System.lineSeparator() +
"Quantity of TestItem from 10 to 50" + System.lineSeparator() +
"Unit of Measurement of TestItem from pcs to kg" + System.lineSeparator() +
"Category of TestItem from TestCategory to NewTestCategory" + System.lineSeparator() +
"Buy Price of TestItem from 5.0 to 6.00" + System.lineSeparator() +
"Sell Price of TestItem from 10.0 to 12.00" + System.lineSeparator() +
"End of Edits" + System.lineSeparator() + System.lineSeparator();
assertEquals(expectedOutput, outputStreamCaptor.toString());
}

}
84 changes: 84 additions & 0 deletions src/test/java/item/ItemTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package item;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ItemTest {

private Item item;

@BeforeEach
void setUp() {
// Initialize Item object before each test
item = new Item("Apple", 10, "Kg", "Fruit", 0.50f, 1.00f);
}

@Test
void testItemCreation() {
assertNotNull(item, "Item should not be null after creation");
assertEquals("Apple", item.getItemName(), "Check item name");
assertEquals(10, item.getQuantity(), "Check quantity");
assertEquals("Kg", item.getUnitOfMeasurement(), "Check unit of measurement");
assertEquals("Fruit", item.getCategory(), "Check category");
assertEquals(0.50f, item.getBuyPrice(), "Check buy price");
assertEquals(1.00f, item.getSellPrice(), "Check sell price");
assertFalse(item.getIsOOS(), "Item should not be out of stock");
}

@Test
void testSetItemName() {
item.setItemName("Banana");
assertEquals("Banana", item.getItemName(), "Item name should be updated to Banana");
}

@Test
void testSetQuantity() {
item.setQuantity(20);
assertEquals(20, item.getQuantity(), "Quantity should be updated to 20");
assertFalse(item.getIsOOS(), "Item should not be marked out of stock with quantity 20");

// Testing out of stock scenario
item.setQuantity(0);
assertEquals(0, item.getQuantity(), "Quantity should be updated to 0");
assertTrue(item.getIsOOS(), "Item should be marked out of stock");
}

@Test
void testSetUnitOfMeasurement() {
item.setUnitOfMeasurement("Boxes");
assertEquals("Boxes", item.getUnitOfMeasurement(), "Unit of measurement should be updated to Boxes");
}

@Test
void testSetCategory() {
item.setCategory("Snacks");
assertEquals("Snacks", item.getCategory(), "Category should be updated to Snacks");
}

@Test
void testSetBuyPrice() {
item.setBuyPrice(0.75f);
assertEquals(0.75f, item.getBuyPrice(), "Buy price should be updated to 0.75");
}

@Test
void testSetSellPrice() {
item.setSellPrice(1.50f);
assertEquals(1.50f, item.getSellPrice(), "Sell price should be updated to 1.50");
}

@Test
void testMarkUnmarkItem() {
item.mark();
assertTrue(item.getMarkStatus(), "Item should be marked");

item.unmark();
assertFalse(item.getMarkStatus(), "Item should be unmarked");
}
}

15 changes: 10 additions & 5 deletions src/test/java/seedu/duke/StockMasterTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package seedu.duke;

import static org.junit.jupiter.api.Assertions.assertTrue;

import exceptions.CommandFormatException;
import exceptions.EmptyListException;
import exceptions.InvalidDateException;
import org.junit.jupiter.api.Test;

class StockMasterTest {

import java.io.IOException;

public class StockMasterTest {

@Test
public void sampleTest() {
assertTrue(true);
public void testStockMaster() throws CommandFormatException, InvalidDateException, IOException, EmptyListException {
StockMaster stockMaster = new StockMaster();
}
}

0 comments on commit 9d4caee

Please sign in to comment.