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 pull request #98 from Joellimjr/v2.0
add addcommand sequence diagram
- Loading branch information
Showing
12 changed files
with
203 additions
and
17 deletions.
There are no files selected for viewing
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,4 +1,2 @@ | ||
1. | apple iphone | Qty: 10 pieces | Cat: electronics | BuyPrice: $100.0 | SellPrice: $500.0 | ||
2. | apple | Qty: 180 pieces | Cat: fruits | BuyPrice: $4.0 | SellPrice: $5.0 | ||
3. | orange | Qty: 0 pieces | Cat: fruits | BuyPrice: $2.0 | SellPrice: $4.0 | ||
4. | samsung phone | Qty: 3 pieces | Cat: electronics | BuyPrice: $80.0 | SellPrice: $300.0 | ||
1. | testItem | Qty: 1 EA | Cat: null | BuyPrice: $1.0 | SellPrice: $10.0 | ||
2. | testItem | Qty: 1 EA | Cat: null | BuyPrice: $1.0 | SellPrice: $10.0 |
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
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
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,22 @@ | ||
package command; | ||
|
||
import exceptions.CommandFormatException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
public class SellCommandTest { | ||
|
||
@Test | ||
public void sellItemTest() throws CommandFormatException { | ||
try { | ||
Command sellCommandTest1 = new SellCommand("testItem", 1, 3); | ||
Command sellCommandTest2 = new SellCommand("testItem", 7, 14); | ||
sellCommandTest1.execute(); | ||
sellCommandTest2.execute(); | ||
} catch (CommandFormatException e) { | ||
fail("Unable to sell item."); | ||
} | ||
} | ||
|
||
} |
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,22 +1,109 @@ | ||
package parser; | ||
|
||
import command.Command; | ||
import command.AddCommand; | ||
import command.EditCommand; | ||
import command.FindCommand; | ||
import command.HelpCommand; | ||
import command.ListCommand; | ||
import command.MarkCommand; | ||
import command.SellCommand; | ||
import command.UnmarkCommand; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class ParserTest { | ||
|
||
private Parser parser; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
parser = new Parser(); | ||
} | ||
|
||
/* | ||
* Note how the names of the test methods does not follow the normal naming convention. | ||
* That is because our coding standard allows a different naming convention for test methods. | ||
*/ | ||
@Test | ||
public void testParseAddCommand() { | ||
String userInput = "add ItemName qty/10 /unitOfMeasurement cat/Category buy/10.5 sell/15.0"; | ||
Command command = parser.parseInput(userInput); | ||
assertInstanceOf(AddCommand.class, command); | ||
AddCommand addCommand = (AddCommand) command; | ||
assertEquals("ItemName", addCommand.getItemName()); | ||
assertEquals(10, addCommand.getQuantity()); | ||
assertEquals("unitOfMeasurement", addCommand.getUnitOfMeasurement()); | ||
assertEquals("Category", addCommand.getCategory()); | ||
assertEquals(10.5f, addCommand.getBuyPrice(), 0.01); | ||
assertEquals(15.0f, addCommand.getSellPrice(), 0.01); | ||
} | ||
|
||
@Test | ||
public void testParseEditCommand() { | ||
String userInput = "edit ItemName name/NewName qty/20 uom/NewUOM cat/NewCategory buy/15.0 sell/20.0"; | ||
Command command = parser.parseInput(userInput); | ||
assertInstanceOf(EditCommand.class, command); | ||
EditCommand editCommand = (EditCommand) command; | ||
assertEquals("ItemName", editCommand.getItemName()); | ||
assertEquals("NewName", editCommand.getNewItemName()); | ||
assertEquals(20, editCommand.getNewQuantity()); | ||
assertEquals("NewUOM", editCommand.getNewUnitOfMeasurement()); | ||
assertEquals("NewCategory", editCommand.getNewCategory()); | ||
assertEquals(15.0f, editCommand.getNewBuyPrice(), 0.01); | ||
assertEquals(20.0f, editCommand.getNewSellPrice(), 0.01); | ||
} | ||
|
||
@Test | ||
public void testParseSellCommand() { | ||
String userInput = "sell ItemName qty/5 price/20.0"; | ||
Command command = parser.parseInput(userInput); | ||
assertInstanceOf(SellCommand.class, command); | ||
SellCommand sellCommand = (SellCommand) command; | ||
assertEquals("ItemName", sellCommand.getItemName()); | ||
assertEquals(5, sellCommand.getSellQuantity()); | ||
assertEquals(20.0f, sellCommand.getSellPrice(), 0.01); | ||
} | ||
|
||
@Test | ||
public void testParseFindCommand() { | ||
String userInput = "find /info Keyword"; | ||
Command command = parser.parseInput(userInput); | ||
assertInstanceOf(FindCommand.class, command); | ||
FindCommand findCommand = (FindCommand) command; | ||
assertEquals("/info", findCommand.getItemInfo()); | ||
assertEquals("Keyword", findCommand.getKeyword()); | ||
} | ||
|
||
@Test | ||
public void testParseListCommand() { | ||
String userInput = "list cat/Category"; | ||
Command command = parser.parseInput(userInput); | ||
assertInstanceOf(ListCommand.class, command); | ||
ListCommand listCommand = (ListCommand) command; | ||
assertEquals("Category", listCommand.getCategory()); | ||
} | ||
|
||
@Test | ||
public void testParseMarkCommand() { | ||
String userInput = "mark ItemName"; | ||
Command command = parser.parseInput(userInput); | ||
assertInstanceOf(MarkCommand.class, command); | ||
MarkCommand markCommand = (MarkCommand) command; | ||
assertEquals("ItemName", markCommand.getItemName()); | ||
} | ||
|
||
@Test | ||
public void testParseUnmarkCommand() { | ||
String userInput = "unmark ItemName"; | ||
Command command = parser.parseInput(userInput); | ||
assertInstanceOf(UnmarkCommand.class, command); | ||
UnmarkCommand unmarkCommand = (UnmarkCommand) command; | ||
assertEquals("ItemName", unmarkCommand.getItemName()); | ||
} | ||
|
||
@Test | ||
public void parse_emptyInput_returnsIncorrect() { | ||
public void testParseHelpCommand() { | ||
String userInput = "help"; | ||
Command command = parser.parseInput(userInput); | ||
assertInstanceOf(HelpCommand.class, command); | ||
} | ||
} | ||
} |