From ed5170ebfc61af1062f9b2f068f7995fcaa82603 Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Wed, 11 Mar 2020 11:37:32 +0100 Subject: [PATCH] Increase test coverage --- game_over_no_actions_output.txt | 2 +- game_over_no_materials_input.txt | 82 ++++++++++++++++++ game_over_no_materials_output.txt | 82 ++++++++++++++++++ src/edu/kit/informatik/cardgame/MainTest.java | 10 +++ .../kit/informatik/cardgame/model/Card.java | 2 +- .../informatik/cardgame/model/CardGame.java | 7 +- .../kit/informatik/cardgame/model/Item.java | 2 +- testcoverage_input.txt | 84 +++++++++++++++++++ testcoverage_output.txt | 83 ++++++++++++++++++ 9 files changed, 346 insertions(+), 8 deletions(-) create mode 100644 game_over_no_materials_input.txt create mode 100644 game_over_no_materials_output.txt create mode 100644 testcoverage_input.txt create mode 100644 testcoverage_output.txt diff --git a/game_over_no_actions_output.txt b/game_over_no_actions_output.txt index ac1d711..0d484a4 100644 --- a/game_over_no_actions_output.txt +++ b/game_over_no_actions_output.txt @@ -78,5 +78,5 @@ survived tiger survived thunderstorm -lose +lost Error, can not get resources: game not started diff --git a/game_over_no_materials_input.txt b/game_over_no_materials_input.txt new file mode 100644 index 0000000..0283efc --- /dev/null +++ b/game_over_no_materials_input.txt @@ -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 diff --git a/game_over_no_materials_output.txt b/game_over_no_materials_output.txt new file mode 100644 index 0000000..50736e4 --- /dev/null +++ b/game_over_no_materials_output.txt @@ -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 diff --git a/src/edu/kit/informatik/cardgame/MainTest.java b/src/edu/kit/informatik/cardgame/MainTest.java index 4ea4aed..d442e33 100644 --- a/src/edu/kit/informatik/cardgame/MainTest.java +++ b/src/edu/kit/informatik/cardgame/MainTest.java @@ -34,6 +34,11 @@ class MainTest { 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 void genericTest() throws IOException { 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"); } + @Test + void testCoverage() throws IOException { + cmpInOut("testcoverage_input.txt", "testcoverage_output.txt"); + } + private void cmpInOut(String in, String out) throws IOException { System.setIn(new ByteArrayInputStream(readFile(in))); ByteArrayOutputStream output = new ByteArrayOutputStream(); diff --git a/src/edu/kit/informatik/cardgame/model/Card.java b/src/edu/kit/informatik/cardgame/model/Card.java index 4963f89..c36dbe0 100644 --- a/src/edu/kit/informatik/cardgame/model/Card.java +++ b/src/edu/kit/informatik/cardgame/model/Card.java @@ -14,7 +14,7 @@ public enum Card { } public boolean needsDiceRoll() { - return this.equals(SPIDER) || this.equals(SNAKE) || this.equals(TIGER); + return this.diceSizeNeeded() > 0; } public int diceSizeNeeded() { diff --git a/src/edu/kit/informatik/cardgame/model/CardGame.java b/src/edu/kit/informatik/cardgame/model/CardGame.java index 26d0929..813d732 100644 --- a/src/edu/kit/informatik/cardgame/model/CardGame.java +++ b/src/edu/kit/informatik/cardgame/model/CardGame.java @@ -33,9 +33,6 @@ public class CardGame { * @return whether the game could be successfully started */ public boolean start(Deque cardStack) throws LogicException { - if (cardStack == null) { - throw new LogicException("can not initialize game with null cards"); - } if (gameStarted()) { return false; } @@ -66,7 +63,7 @@ public class CardGame { items.remove(FIREPLACE); } 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; } @@ -135,7 +132,7 @@ public class CardGame { minimumDiceRoll = 4; } else if (currentCardStack != null && currentCardStack.isEmpty() && getBuildableItems().isEmpty()) { endGame(); - return "lose"; + return "lost"; } return "OK"; } else { diff --git a/src/edu/kit/informatik/cardgame/model/Item.java b/src/edu/kit/informatik/cardgame/model/Item.java index 3f3af3d..30722d4 100644 --- a/src/edu/kit/informatik/cardgame/model/Item.java +++ b/src/edu/kit/informatik/cardgame/model/Item.java @@ -95,7 +95,7 @@ public enum Item { case BALLON: return "ballon"; default: - return null; + return super.toString(); } } } diff --git a/testcoverage_input.txt b/testcoverage_input.txt new file mode 100644 index 0000000..874bd6b --- /dev/null +++ b/testcoverage_input.txt @@ -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 diff --git a/testcoverage_output.txt b/testcoverage_output.txt new file mode 100644 index 0000000..0445dd3 --- /dev/null +++ b/testcoverage_output.txt @@ -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