forked from nus-cs2113-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/AY2324S2-CS2113-T15-4/tp
- Loading branch information
Showing
16 changed files
with
279 additions
and
20 deletions.
There are no files selected for viewing
Empty file.
Binary file modified
BIN
-3.18 KB
(87%)
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 not shown.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |