Add shack building test and fix behaviour on codetester

This commit is contained in:
Arne Keller 2020-02-29 08:47:20 +01:00
parent 3bd70a5350
commit 74cac150fa
4 changed files with 46 additions and 2 deletions

17
shack_test_input.txt Normal file
View File

@ -0,0 +1,17 @@
start wood,metal,plastic,wood,metal,plastic,spider,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,spider,spider,spider,spider,snake,snake,snake,snake,snake,tiger,tiger,tiger,tiger,tiger,thunderstorm
draw
draw
draw
draw
draw
draw
list-resources
list-buildings
build?
build shack
list-buildings
draw
start wood
rollD4 1
list-resources
quit

21
shack_test_output.txt Normal file
View File

@ -0,0 +1,21 @@
OK
wood
metal
plastic
wood
metal
plastic
plastic
metal
wood
plastic
metal
wood
EMPTY
shack
OK
shack
spider
Error, invalid start arguments
lose
metal

View File

@ -23,6 +23,11 @@ class MainTest {
cmpInOut("commands1_input.txt", "commands1_output.txt"); cmpInOut("commands1_input.txt", "commands1_output.txt");
} }
@Test
void shackTest() throws IOException {
cmpInOut("shack_test_input.txt", "shack_test_output.txt");
}
private void cmpInOut(String in, String out) throws IOException { private void cmpInOut(String in, String out) throws IOException {
System.setIn(new ByteArrayInputStream(readFile(in))); System.setIn(new ByteArrayInputStream(readFile(in)));
ByteArrayOutputStream output = new ByteArrayOutputStream(); ByteArrayOutputStream output = new ByteArrayOutputStream();

View File

@ -1,5 +1,6 @@
package edu.kit.informatik.model; package edu.kit.informatik.model;
import edu.kit.informatik.Terminal;
import edu.kit.informatik.ui.InvalidInputException; import edu.kit.informatik.ui.InvalidInputException;
import java.util.ArrayDeque; import java.util.ArrayDeque;
@ -34,7 +35,7 @@ public class CardGame {
* @return * @return
*/ */
public boolean start(Deque<Card> cardStack) { public boolean start(Deque<Card> cardStack) {
if (this.cardStack == null || this.cardStack.isEmpty()) { if (this.cardStack == null) {
this.cardStack = cardStack; this.cardStack = cardStack;
return true; return true;
} else { } else {
@ -107,7 +108,7 @@ public class CardGame {
} else if (canBuild(item)) { } else if (canBuild(item)) {
// remove used resources // remove used resources
for (Card resource : item.resourcesNeeded()) { for (Card resource : item.resourcesNeeded()) {
assert resources.removeLastOccurrence(resource); // TODO: remove assert resources.removeLastOccurrence(resource);
} }
items.add(item); items.add(item);
if (item.equals(STEAMBOAT) || item.equals(BALLOON)) { if (item.equals(STEAMBOAT) || item.equals(BALLOON)) {