Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increased Test Coverage #290

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/seedu/binbash/quotes/Quotes.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class Quotes {
private static final Random RANDOM = new Random();

// Private constructor to prevent instantiation
private Quotes() {}
XavierLiau34 marked this conversation as resolved.
Show resolved Hide resolved
public Quotes() {}

public static String getRandomQuote() {
int randomIndex = RANDOM.nextInt(CUSTOM_MESSAGES.length);
Expand Down
39 changes: 39 additions & 0 deletions src/test/java/seedu/binbash/command/ProfitCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package seedu.binbash.command;

import org.junit.jupiter.api.Test;

import seedu.binbash.item.Item;
import seedu.binbash.inventory.ItemList;

import java.time.LocalDate;
import java.util.ArrayList;

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

public class ProfitCommandTest {

@Test
void execute_calculateTotalProfit() {
ArrayList<Item> emptyItemList = new ArrayList<>();
ItemList itemList = new ItemList(emptyItemList);

AddCommand addCommand1 = new AddCommand("retail", "Item 1", "Description 1", 1,
LocalDate.now(), 5, 3, 1);
addCommand1.execute(itemList);

AddCommand addCommand2 = new AddCommand("retail", "Item 2", "Description 2", 1,
LocalDate.now(), 10, 7, 1);
addCommand2.execute(itemList);

SellCommand sellCommand1 = new SellCommand("Item 1", 1);
sellCommand1.execute(itemList);

SellCommand sellCommand2 = new SellCommand("Item 2", 1);
sellCommand2.execute(itemList);

ProfitCommand profitCommand = new ProfitCommand();
assertTrue(profitCommand.execute(itemList));
assertEquals("Total profit: $5.00", profitCommand.getExecutionUiOutput().trim());
}
}
17 changes: 17 additions & 0 deletions src/test/java/seedu/binbash/parser/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.apache.commons.cli.ParseException;

import org.junit.jupiter.api.Assertions;
import seedu.binbash.quotes.Quotes;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
Expand Down Expand Up @@ -80,6 +82,21 @@ public void testParseCommand_repeatedQuoteCommand_returnsQuoteCommand() {
}
}


@Test
void getRandomQuote_returnsValidQuote() {
String quote = Quotes.getRandomQuote();

boolean quoteFound = false;
for (String predefinedQuote : Quotes.CUSTOM_MESSAGES) {
if (predefinedQuote.equals(quote)) {
quoteFound = true;
break;
}
}
assertTrue(quoteFound, "Returned quote is not one of the predefined quotes.");
}

@Test
public void testParseCommand_invalidCommand_throwsInvalidCommandException() {
assertThrows(InvalidCommandException.class, () -> parser.parseCommand("invalid"));
Expand Down
Loading