aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/eu/equalparts/cardbase/cli/CardbaseCLI.java47
-rw-r--r--test/eu/equalparts/cardbase/cli/CardbaseCLITest.java143
-rw-r--r--test/eu/equalparts/cardbase/cli/specificCardPerusal7
-rw-r--r--todo10
4 files changed, 173 insertions, 34 deletions
diff --git a/src/eu/equalparts/cardbase/cli/CardbaseCLI.java b/src/eu/equalparts/cardbase/cli/CardbaseCLI.java
index 8c0c97a..03351da 100644
--- a/src/eu/equalparts/cardbase/cli/CardbaseCLI.java
+++ b/src/eu/equalparts/cardbase/cli/CardbaseCLI.java
@@ -351,23 +351,6 @@ public final class CardbaseCLI {
}
/**
- * Undo previous action.
- */
- void undo() {
- if (lastAction != null) {
- if (lastAction == Action.ADD) {
- removeCard(lastAction.card);
- } else if (lastAction == Action.REMOVE) {
- addCard(lastAction.card);
- }
- // can only undo once
- lastAction = null;
- } else {
- System.out.println("Nothing to undo.");
- }
- }
-
- /**
* Remove one or more of a card.
*
* @param args the set number of the card to remove and optionally the count to be removed.
@@ -375,7 +358,8 @@ public final class CardbaseCLI {
void remove(String... args) {
if (selectedSet != null) {
if (args != null && args.length > 0) {
- Card cardToRemove = selectedSet.getCardByNumber(args[0]);
+// Card cardToRemove = selectedSet.getCardByNumber(args[0]);
+ Card cardToRemove = cardbase.getCard(selectedSet.code, args[0]);
if (cardToRemove != null) {
Integer count = 1;
if (args.length > 1 && args[1].matches("[0-9]+")) {
@@ -388,7 +372,7 @@ public final class CardbaseCLI {
cardToRemove.count = count;
removeCard(cardToRemove);
} else {
- System.out.println(args[0] + " does not correspond to a card in " + selectedSet.name + ".");
+ System.out.println(args[0] + " is not in the cardbase.");
}
} else {
System.out.println("Please specify a card number to remove.");
@@ -433,13 +417,30 @@ public final class CardbaseCLI {
}
/**
+ * Undo previous action.
+ */
+ void undo() {
+ if (lastAction != null) {
+ if (lastAction == Action.ADD) {
+ removeCard(lastAction.card);
+ } else if (lastAction == Action.REMOVE) {
+ addCard(lastAction.card);
+ }
+ // can only undo once
+ lastAction = null;
+ } else {
+ System.out.println("Nothing to undo.");
+ }
+ }
+
+ /**
* Add the specified count of the specified card
* to the cardbase.
*
* @param card the card to add, set this object's
* count field to determine the count to add.
*/
- void addCard(Card card) {
+ private void addCard(Card card) {
System.out.println("Added " + card.count + "x " + card.name + ".");
cardbase.addCard(card);
savePrompt = true;
@@ -454,7 +455,7 @@ public final class CardbaseCLI {
* @param card the card to remove, set this object's count field
* to determine how many of the card to remove.
*/
- void removeCard(Card card) {
+ private void removeCard(Card card) {
Integer removed = cardbase.removeCard(card);
if (removed > 0) {
System.out.println("Removed " + removed + "x " + card.name + ".");
@@ -489,7 +490,7 @@ public final class CardbaseCLI {
*
* @param card the card to glance.
*/
- void printGlance(Card card) {
+ private void printGlance(Card card) {
System.out.println(String.format("%1$-4d %2$s (%3$s, %4$s)", card.count, card.name, card.setCode, card.number));
}
@@ -500,7 +501,7 @@ public final class CardbaseCLI {
*
* @param card the card to peruse.
*/
- void printPerusal(Card card) {
+ private void printPerusal(Card card) {
printGlance(card);
if (card.type != null) System.out.println("\t" + card.type);
if (card.manaCost != null) System.out.println("\tCost: " + card.manaCost);
diff --git a/test/eu/equalparts/cardbase/cli/CardbaseCLITest.java b/test/eu/equalparts/cardbase/cli/CardbaseCLITest.java
index 528362e..7332c3b 100644
--- a/test/eu/equalparts/cardbase/cli/CardbaseCLITest.java
+++ b/test/eu/equalparts/cardbase/cli/CardbaseCLITest.java
@@ -19,6 +19,7 @@ import org.junit.rules.TemporaryFolder;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.equalparts.cardbase.cards.Card;
+import eu.equalparts.cardbase.cards.FullCardSet;
import eu.equalparts.cardbase.utils.MTGUniverse;
public class CardbaseCLITest {
@@ -535,17 +536,153 @@ public class CardbaseCLITest {
}
}
- /***********************************************************************************
- * undo() tests, happy path
- ***********************************************************************************/
+ @Test
+ public void specificPerusalWithValidArgumentIsPrinted() throws Exception {
+ uut = new CardbaseCLI(getClass().getResource("/testbase.cb").getFile());
+ // dummy set just so the uut knows the set to peruse from
+ FullCardSet fcs = new FullCardSet();
+ fcs.code = "FRF";
+ uut.selectedSet = fcs;
+
+ try {
+ System.setOut(new PrintStream(testOutput));
+ uut.peruse("129");
+ } finally {
+ System.setOut(console);
+ }
+
+ try (Scanner scanner = new Scanner(getClass().getResourceAsStream("specificCardPerusal"))) {
+ assertEquals(scanner.useDelimiter("\\Z").next() + EOL, testOutput.toString());
+ }
+ }
+
+ /*
+ * Edge cases
+ */
+ @Test
+ public void specificPerusalWithInvalidArgument() throws Exception {
+ uut = new CardbaseCLI(getClass().getResource("/testbase.cb").getFile());
+ // dummy set just so the uut knows the set to peruse from
+ FullCardSet fcs = new FullCardSet();
+ fcs.code = "FRF";
+ uut.selectedSet = fcs;
+
+ try {
+ System.setOut(new PrintStream(testOutput));
+ uut.peruse("100");
+ } finally {
+ System.setOut(console);
+ }
+
+ assertEquals("Card not in cardbase." + EOL, testOutput.toString());
+ }
+
+ @Test
+ public void specificPerusalWithNoSelectedSet() throws Exception {
+ uut = new CardbaseCLI(getClass().getResource("/testbase.cb").getFile());
+ uut.selectedSet = null;
+
+ try {
+ System.setOut(new PrintStream(testOutput));
+ uut.peruse("100");
+ } finally {
+ System.setOut(console);
+ }
+
+ assertEquals("Please select a set before perusing a specific card." + EOL, testOutput.toString());
+ }
/***********************************************************************************
* remove() tests, happy path
***********************************************************************************/
+ @Test
+ public void removeValidAmountOfExistingCard() throws Exception {
+ uut = new CardbaseCLI(getClass().getResource("/testbase.cb").getFile());
+ // dummy set just so the uut knows the set to peruse from
+ FullCardSet fcs = new FullCardSet();
+ fcs.code = "FRF";
+ uut.selectedSet = fcs;
+
+ uut.remove("129", "3");
+
+ assertEquals("Wrong number of cards was removed.", uut.cardbase.getCard("FRF", "129").count, new Integer(6));
+ }
+
+ @Test
+ public void removeExceedingAmountOfExistingCard() throws Exception {
+ uut = new CardbaseCLI(getClass().getResource("/testbase.cb").getFile());
+ // dummy set just so the uut knows the set to peruse from
+ FullCardSet fcs = new FullCardSet();
+ fcs.code = "FRF";
+ uut.selectedSet = fcs;
+
+ uut.remove("128", "3");
+
+ assertNull("Card was not removed successfully.", uut.cardbase.getCard("FRF", "128"));
+ }
+
+ @Test
+ public void removeExactAmountOfExistingCard() throws Exception {
+ uut = new CardbaseCLI(getClass().getResource("/testbase.cb").getFile());
+ // dummy set just so the uut knows the set to peruse from
+ FullCardSet fcs = new FullCardSet();
+ fcs.code = "FRF";
+ uut.selectedSet = fcs;
+
+ uut.remove("128", "1");
+
+ assertNull("Card was not removed successfully.", uut.cardbase.getCard("FRF", "128"));
+ }
+
+ @Test
+ public void removeSingleExistingCardWithoutAmount() throws Exception {
+ uut = new CardbaseCLI(getClass().getResource("/testbase.cb").getFile());
+ // dummy set just so the uut knows the set to peruse from
+ FullCardSet fcs = new FullCardSet();
+ fcs.code = "FRF";
+ uut.selectedSet = fcs;
+
+ uut.remove("128");
+
+ assertNull("Card was not removed successfully.", uut.cardbase.getCard("FRF", "128"));
+ }
+
+ @Test
+ public void removeMultipleExistingCardWithoutAmount() throws Exception {
+ uut = new CardbaseCLI(getClass().getResource("/testbase.cb").getFile());
+ // dummy set just so the uut knows the set to peruse from
+ FullCardSet fcs = new FullCardSet();
+ fcs.code = "FRF";
+ uut.selectedSet = fcs;
+
+ uut.remove("129");
+
+ assertNull("Card was not removed successfully.", uut.cardbase.getCard("FRF", "129"));
+ }
+
+ /*
+ * Edge cases
+ */
+ // attempt to remove nonexistent card without amount
+
+ // attempt to remove nonexistent card with amount
+
+ // remove 0 of existing card
+
+ // remove negative number of existing card
+
+ // remove card without selected set
+
/***********************************************************************************
* add() tests, happy path
***********************************************************************************/
+
+
+ /***********************************************************************************
+ * undo() tests, happy path
+ ***********************************************************************************/
+
}
diff --git a/test/eu/equalparts/cardbase/cli/specificCardPerusal b/test/eu/equalparts/cardbase/cli/specificCardPerusal
new file mode 100644
index 0000000..a1f6548
--- /dev/null
+++ b/test/eu/equalparts/cardbase/cli/specificCardPerusal
@@ -0,0 +1,7 @@
+8 Formless Nurturing (FRF, 129)
+ Sorcery
+ Cost: {3}{G}
+ Manifest the top card of your library, then put a +1/+1 counter on it. (To manifest a card, put it onto the battlefield face down as a 2/2 creature. Turn it face up any time for its mana cost if it's a creature card.)
+ Common
+ MID: 391837
+ Illus. Cliff Childs \ No newline at end of file
diff --git a/todo b/todo
index 0e57ce0..9a0635b 100644
--- a/todo
+++ b/todo
@@ -4,12 +4,6 @@ Cardbase:
* decks
CardbaseCLI:
- * command methods
- *
-
+ * undo, add, remove
-ANT problems:
- * invalidSetIsProvided
- * correctSetIsSelected
- * correctSetListIsPrinted
- * \ No newline at end of file
+To pass: happy path remove \ No newline at end of file