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");
}
@Test
void shackTest() throws IOException {
cmpInOut("shack_test_input.txt", "shack_test_output.txt");
}
private void cmpInOut(String in, String out) throws IOException {
System.setIn(new ByteArrayInputStream(readFile(in)));
ByteArrayOutputStream output = new ByteArrayOutputStream();

View File

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