Increase test coverage

This commit is contained in:
Arne Keller 2020-03-11 11:37:32 +01:00
parent f39fdee4c9
commit ed5170ebfc
9 changed files with 346 additions and 8 deletions

View File

@ -78,5 +78,5 @@ survived
tiger tiger
survived survived
thunderstorm thunderstorm
lose lost
Error, can not get resources: game not started Error, can not get resources: game not started

View File

@ -0,0 +1,82 @@
start wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,spider,spider,spider,spider,spider,snake,snake,snake,snake,snake,tiger,tiger,tiger,tiger,tiger,thunderstorm,wood,wood,wood
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
rollD4 1
draw
rollD4 1
draw
rollD4 2
draw
rollD4 3
draw
rollD4 4
draw
rollD6 2
draw
rollD6 3
draw
rollD6 4
draw
rollD6 5
draw
rollD6 6
draw
rollD8 4
draw
rollD8 5
draw
rollD8 6
draw
rollD8 7
draw
rollD8 8
draw
draw
draw
draw
build club
list-resources

View File

@ -0,0 +1,82 @@
OK
wood
wood
wood
wood
wood
wood
wood
wood
wood
wood
wood
wood
wood
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
spider
lose
spider
lose
spider
lose
spider
survived
spider
survived
snake
lose
snake
lose
snake
survived
snake
survived
snake
survived
tiger
lose
tiger
survived
tiger
survived
tiger
survived
tiger
survived
thunderstorm
wood
wood
wood
lost
Error, can not get resources: game not started

View File

@ -34,6 +34,11 @@ class MainTest {
cmpInOut("game_over_no_actions_input.txt", "game_over_no_actions_output.txt"); cmpInOut("game_over_no_actions_input.txt", "game_over_no_actions_output.txt");
} }
@Test
void gameOverNoMaterials() throws IOException {
cmpInOut("game_over_no_materials_input.txt", "game_over_no_materials_output.txt");
}
@Test @Test
void genericTest() throws IOException { void genericTest() throws IOException {
cmpInOut("generic_test_input.txt", "generic_test_output.txt"); cmpInOut("generic_test_input.txt", "generic_test_output.txt");
@ -44,6 +49,11 @@ class MainTest {
cmpInOut("generic_waf2_test_input.txt", "generic_waf2_test_output.txt"); cmpInOut("generic_waf2_test_input.txt", "generic_waf2_test_output.txt");
} }
@Test
void testCoverage() throws IOException {
cmpInOut("testcoverage_input.txt", "testcoverage_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

@ -14,7 +14,7 @@ public enum Card {
} }
public boolean needsDiceRoll() { public boolean needsDiceRoll() {
return this.equals(SPIDER) || this.equals(SNAKE) || this.equals(TIGER); return this.diceSizeNeeded() > 0;
} }
public int diceSizeNeeded() { public int diceSizeNeeded() {

View File

@ -33,9 +33,6 @@ public class CardGame {
* @return whether the game could be successfully started * @return whether the game could be successfully started
*/ */
public boolean start(Deque<Card> cardStack) throws LogicException { public boolean start(Deque<Card> cardStack) throws LogicException {
if (cardStack == null) {
throw new LogicException("can not initialize game with null cards");
}
if (gameStarted()) { if (gameStarted()) {
return false; return false;
} }
@ -66,7 +63,7 @@ public class CardGame {
items.remove(FIREPLACE); items.remove(FIREPLACE);
} }
if (currentCardStack.isEmpty() && getBuildableItems().isEmpty()) { if (currentCardStack.isEmpty() && getBuildableItems().isEmpty()) {
endGame(); // TODO: somehow print "lose" ??? (after the card!) [awaiting ILIAS..] endGame(); // TODO: somehow print "lost" ??? (after the card!) [awaiting ILIAS..]
} }
return card; return card;
} }
@ -135,7 +132,7 @@ public class CardGame {
minimumDiceRoll = 4; minimumDiceRoll = 4;
} else if (currentCardStack != null && currentCardStack.isEmpty() && getBuildableItems().isEmpty()) { } else if (currentCardStack != null && currentCardStack.isEmpty() && getBuildableItems().isEmpty()) {
endGame(); endGame();
return "lose"; return "lost";
} }
return "OK"; return "OK";
} else { } else {

View File

@ -95,7 +95,7 @@ public enum Item {
case BALLON: case BALLON:
return "ballon"; return "ballon";
default: default:
return null; return super.toString();
} }
} }
} }

84
testcoverage_input.txt Normal file
View File

@ -0,0 +1,84 @@
quit game
build?!
start spider,spider,spider,spider,spider,snake,snake,snake,snake,snake,tiger,tiger,tiger,tiger,thunderstorm,tiger,metal,metal,metal,wood,wood,wood,wood,metal,metal,plastic,plastic,wood,wood,wood,wood,wood,wood,wood,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,wood,wood,metal,metal,wood,wood,wood,metal,metal,metal,metal,metal,metal,metal,metal,metal
draw
rollD4 1
draw
rollD4 2
draw
rollD4 3
draw
rollD4 4
draw
rollD4 4
draw
rollD6 1
draw
rollD6 3
draw
rollD6 4
draw
rollD6 5
draw
rollD6 6
draw
rollD8 4
draw
rollD8 5
draw
rollD8 6
draw
rollD8 7
draw
draw
rollD8 1
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
quit

83
testcoverage_output.txt Normal file
View File

@ -0,0 +1,83 @@
Error, input after quit command
Error, invalid build? argument: none expected
OK
spider
lose
spider
lose
spider
survived
spider
survived
spider
survived
snake
lose
snake
lose
snake
survived
snake
survived
snake
survived
tiger
lose
tiger
survived
tiger
survived
tiger
survived
thunderstorm
tiger
lose
metal
metal
metal
wood
wood
wood
wood
metal
metal
plastic
plastic
wood
wood
wood
wood
wood
wood
wood
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
wood
wood
metal
metal
wood
wood
wood
metal
metal
metal
metal
metal
metal
metal
metal
metal
Error, no card to draw exists