From 70375ea84d6622e5e149c7c43306c110db8005c0 Mon Sep 17 00:00:00 2001 From: szilva07 Date: Tue, 14 May 2024 16:29:49 +0200 Subject: [PATCH] =?UTF-8?q?tesztek=20meg=C3=ADr=C3=A1sa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Közös munka IntelliJ-ben Code With Me funkcióval. Résztvevők: Karsai Artúr Sinkler Szilveszter --- ...03\251sz\303\255t\303\251se - Cucumber.md" | 0 .../java/cucumberTest/FixerActionsOnTank.java | 57 ++++++++++++++ src/test/java/cucumberTest/FixerFixes.java | 30 ++++++-- src/test/java/cucumberTest/PlayerMoves.java | 72 ++++++++++++++++++ .../cucumberTest/SaboteurActionsOnPipe.java | 75 +++++++++++++++++++ .../cucumberTest/FixerActionsOnTank.feature | 14 ++++ .../resources/cucumberTest/FixerFixes.feature | 11 ++- .../cucumberTest/PlayerMoves.feature | 14 ++++ .../SaboteurActionsOnPipe.feature | 18 +++++ 9 files changed, 280 insertions(+), 11 deletions(-) create mode 100644 "doc/BDD tesztek k\303\251sz\303\255t\303\251se - Cucumber.md" create mode 100644 src/test/java/cucumberTest/FixerActionsOnTank.java create mode 100644 src/test/java/cucumberTest/PlayerMoves.java create mode 100644 src/test/java/cucumberTest/SaboteurActionsOnPipe.java create mode 100644 src/test/resources/cucumberTest/FixerActionsOnTank.feature create mode 100644 src/test/resources/cucumberTest/PlayerMoves.feature create mode 100644 src/test/resources/cucumberTest/SaboteurActionsOnPipe.feature diff --git "a/doc/BDD tesztek k\303\251sz\303\255t\303\251se - Cucumber.md" "b/doc/BDD tesztek k\303\251sz\303\255t\303\251se - Cucumber.md" new file mode 100644 index 0000000..e69de29 diff --git a/src/test/java/cucumberTest/FixerActionsOnTank.java b/src/test/java/cucumberTest/FixerActionsOnTank.java new file mode 100644 index 0000000..99d0eee --- /dev/null +++ b/src/test/java/cucumberTest/FixerActionsOnTank.java @@ -0,0 +1,57 @@ +package cucumberTest; + +import drukmakoriSzerelok.Game; +import drukmakoriSzerelok.Tank; +import drukmakoriSzerelok.Fixer; + +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +import static org.junit.Assert.assertEquals; + +public class FixerActionsOnTank { + private Tank tank = new Tank(); + private Fixer fixer = new Fixer("fixer1",""); + + public FixerActionsOnTank(){ + Game.Get().SetActivePlayer(fixer); + } + + @Given("a tank") + public void a_tank() { + Game game = Game.Get(); + } + + @Given("the fixer currently standing on that tank") + public void the_fixer_currently_standing_on_that_tank() { + fixer.SetField(tank); + tank.AddPlayer(fixer); + } + + @When("the saboteur tries to carry a pipe") + public void the_saboteur_tries_to_carry_a_pipe() { + fixer.CarryPipe(tank); + } + + @When("the saboteur tries to carry a pump") + public void the_saboteur_tries_to_carry_a_pump() { + fixer.CarryPump(tank); + } + + @Then("the tank should have {string} pipes") + public void the_tank_should_have_pipes(String answer){ + assertEquals(answer, String.valueOf(tank.getNumberOfPipes())); + } + + @Then("the tank should have {string} pumps") + public void the_tank_should_have_pumps(String answer){ + assertEquals(answer, String.valueOf(tank.getNumberOfPumps())); + } + + @Then("the fixer should {string}have an active field") + public void the_fixer_should_have_an_active_field(String answer){ + var result = fixer.GetHasActive() ? "" : "not "; + assertEquals(answer, result); + } +} diff --git a/src/test/java/cucumberTest/FixerFixes.java b/src/test/java/cucumberTest/FixerFixes.java index dd25f72..6e60011 100644 --- a/src/test/java/cucumberTest/FixerFixes.java +++ b/src/test/java/cucumberTest/FixerFixes.java @@ -3,6 +3,7 @@ import drukmakoriSzerelok.Fixer; import drukmakoriSzerelok.Game; import drukmakoriSzerelok.Pipe; +import drukmakoriSzerelok.Pump; import io.cucumber.java.en.Given; import io.cucumber.java.en.Then; @@ -10,24 +11,33 @@ import static org.junit.Assert.assertEquals; - -class IsItWorks{ - static String isItWorks(boolean status) { - return status ? "fixed" : "not fixed"; +class IsItBroken{ + static String isItBroken(boolean status) { + return status ? "fixed" : "broken"; } } public class FixerFixes { private Pipe pipe = new Pipe(); + private Pump pump = new Pump(); private Fixer fixer = new Fixer("fixer1",""); private boolean result; + public FixerFixes(){ + Game.Get().SetActivePlayer(fixer); + } + @Given("a broken pipe") public void a_broken_pipe() { pipe.SetIsBroken(true); Game game = Game.Get(); + } + @Given("a broken pump") + public void a_broken_pump() { + pump.SetIsBroken(true); + Game game = Game.Get(); } @Given("the fixer currently standing on that pipe") @@ -36,16 +46,20 @@ public void the_fixer_currently_standing_on_that_pipe() { pipe.AddPlayer(fixer); } + @Given("the fixer currently standing on that pump") + public void the_fixer_currently_standing_on_that_pump() { + fixer.SetField(pump); + pump.AddPlayer(fixer); + } - @When("the fixer try to repair that") - public void the_fixer_try_to_repair_that(){ + @When("the fixer tries to repair that") + public void the_fixer_tries_to_repair_that(){ fixer.Fix(pipe); result = ! pipe.GetIsBroken(); } @Then("it should be {string}") public void it_should_be(String answer){ - assertEquals(answer, IsItWorks.isItWorks(result)); + assertEquals(answer, IsItBroken.isItBroken(result)); } - } diff --git a/src/test/java/cucumberTest/PlayerMoves.java b/src/test/java/cucumberTest/PlayerMoves.java new file mode 100644 index 0000000..f897c59 --- /dev/null +++ b/src/test/java/cucumberTest/PlayerMoves.java @@ -0,0 +1,72 @@ +package cucumberTest; + +import drukmakoriSzerelok.*; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +import static org.junit.Assert.assertEquals; + +public class PlayerMoves{ + Field tank; + Player player; + Field neighbour; + + @Given("a default map") + public void a_default_map() { + Game.Get(); + } + @Given("a fixer currently standing on a tank") + public void a_fixer_currently_standing_on_a_tank() { + player = Game.Get().GetPlayers().get(0); + Game.Get().SetActivePlayer(player); + tank = player.GetField(); + } + @Given("a neighbour pipe") + public void a_neighbour_pipe() { + neighbour = Game.Get().GetMap().GetNeighbourFromDirection(tank, "right"); + } + @When("the fixer tries to move to the neighbour pipe") + public void the_fixer_tries_to_move_to_the_neighbour_pipe() { + player.Move(neighbour); + } + @Then("the fixer should be placed on the {string} pipe") + public void the_fixer_should_be_placed_on_the_neighbour_pipe(String answer) { + var result = player.GetField() == neighbour ? "neighbour" : "tank"; + assertEquals(answer, result); + } + + + Field field1; + Field field2; + Player player1; + Player player2; + Field pump; + + @Given("two players currently standing on two separate fields") + public void two_players_currently_standing_on_two_separate_fields() { + player1 = Game.Get().GetPlayers().get(0); + player2 = Game.Get().GetPlayers().get(1); + field1 = player1.GetField(); + field2 = Game.Get().GetMap().GetNeighbourFromDirection(Game.Get().GetMap().GetNeighbourFromDirection(field1, "right"), "right"); + field2.AddPlayer(player2); + player2.SetField(field2); + } + @Given("a neighbour pump") + public void a_neighbour_pump() { + pump = Game.Get().GetMap().GetNeighbourFromDirection(field1, "left"); + pump = new Pump(); + } + @When("both players try to move to the neighbour pump") + public void both_players_try_to_move_to_the_neighbour_pump() { + Game.Get().SetActivePlayer(player1); + player1.Move(pump); + Game.Get().SetActivePlayer(player2); + player2.Move(pump); + } + @Then("{string} players should be placed on the pump") + public void both_players_should_be_placed_on_the_pump(String answer) { + String result = String.valueOf(pump.GetPlayer().size()); + assertEquals(answer, result); + } +} \ No newline at end of file diff --git a/src/test/java/cucumberTest/SaboteurActionsOnPipe.java b/src/test/java/cucumberTest/SaboteurActionsOnPipe.java new file mode 100644 index 0000000..79eba0c --- /dev/null +++ b/src/test/java/cucumberTest/SaboteurActionsOnPipe.java @@ -0,0 +1,75 @@ +package cucumberTest; + +import drukmakoriSzerelok.Saboteur; +import drukmakoriSzerelok.Game; +import drukmakoriSzerelok.Pipe; + +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +import static org.junit.Assert.assertEquals; + +class IsPipeStatusCorrect { + static String isItSlippery(boolean status) { + return status ? "" : "not "; + } + + static String isItSticky(boolean status) { return status ? "" : "not "; } +} + +public class SaboteurActionsOnPipe { + private Pipe pipe = new Pipe(); + private Saboteur saboteur = new Saboteur("saboteur1",""); + + private boolean result; + + public SaboteurActionsOnPipe(){ + Game.Get().SetActivePlayer(saboteur); + } + + @Given("a not broken pipe") + public void a_not_broken_pipe() { + pipe.SetIsBroken(false); + Game game = Game.Get(); + } + + @Given("the saboteur currently standing on that pipe") + public void the_saboteur_currently_standing_on_that_pipe() { + saboteur.SetField(pipe); + pipe.AddPlayer(saboteur); + } + + @When("the saboteur tries to break that") + public void the_saboteur_tries_to_break_that() { + saboteur.PipeSabotage(pipe); + result = ! pipe.GetIsBroken(); + } + + @Given("a pipe") + public void a_pipe() { + Game game = Game.Get(); + } + + @When("the saboteur tries to make that slippery") + public void the_saboteur_tries_to_make_that_slippery() { + saboteur.MakeSlippery(pipe); + result = pipe.GetSlippery() > 0; + } + + @When("the saboteur tries to make that sticky") + public void the_saboteur_tries_to_make_that_sticky() { + saboteur.MakeSticky(pipe); + result = pipe.GetSticky() > 0; + } + + @Then("the pipe should be {string}slippery") + public void the_pipe_should_be_slippery(String answer){ + assertEquals(answer, IsPipeStatusCorrect.isItSlippery(result)); + } + + @Then("the pipe should be {string}sticky") + public void the_pipe_should_be_sticky(String answer){ + assertEquals(answer, IsPipeStatusCorrect.isItSticky(result)); + } +} diff --git a/src/test/resources/cucumberTest/FixerActionsOnTank.feature b/src/test/resources/cucumberTest/FixerActionsOnTank.feature new file mode 100644 index 0000000..7328704 --- /dev/null +++ b/src/test/resources/cucumberTest/FixerActionsOnTank.feature @@ -0,0 +1,14 @@ +Feature: + Scenario: test carrying pipe + Given a tank + Given the fixer currently standing on that tank + When the saboteur tries to carry a pipe + Then the tank should have "4" pipes + Then the fixer should ""have an active field + + Scenario: test carrying pump + Given a tank + Given the fixer currently standing on that tank + When the saboteur tries to carry a pump + Then the tank should have "0" pumps + Then the fixer should ""have an active field \ No newline at end of file diff --git a/src/test/resources/cucumberTest/FixerFixes.feature b/src/test/resources/cucumberTest/FixerFixes.feature index 846b3b1..b7ced98 100644 --- a/src/test/resources/cucumberTest/FixerFixes.feature +++ b/src/test/resources/cucumberTest/FixerFixes.feature @@ -1,7 +1,12 @@ -Feature: test fixing the pipe and pump - Scenario: +Feature: + Scenario: test fixing a pipe Given a broken pipe Given the fixer currently standing on that pipe - When the fixer try to repair that + When the fixer tries to repair that Then it should be "fixed" + Scenario: test fixing a pump + Given a broken pump + Given the fixer currently standing on that pump + When the fixer tries to repair that + Then it should be "fixed" \ No newline at end of file diff --git a/src/test/resources/cucumberTest/PlayerMoves.feature b/src/test/resources/cucumberTest/PlayerMoves.feature new file mode 100644 index 0000000..955eae8 --- /dev/null +++ b/src/test/resources/cucumberTest/PlayerMoves.feature @@ -0,0 +1,14 @@ +Feature: + Scenario: a player moves to another pipe + Given a default map + And a fixer currently standing on a tank + And a neighbour pipe + When the fixer tries to move to the neighbour pipe + Then the fixer should be placed on the "neighbour" pipe + + Scenario: two players move to the same pump + Given a default map + And two players currently standing on two separate fields + And a neighbour pump + When both players try to move to the neighbour pump + Then "2" players should be placed on the pump diff --git a/src/test/resources/cucumberTest/SaboteurActionsOnPipe.feature b/src/test/resources/cucumberTest/SaboteurActionsOnPipe.feature new file mode 100644 index 0000000..2204457 --- /dev/null +++ b/src/test/resources/cucumberTest/SaboteurActionsOnPipe.feature @@ -0,0 +1,18 @@ +Feature: + Scenario: test breaking a pipe + Given a not broken pipe + Given the saboteur currently standing on that pipe + When the saboteur tries to break that + Then it should be "broken" + + Scenario: test making a pipe slippery + Given a pipe + Given the saboteur currently standing on that pipe + When the saboteur tries to make that slippery + Then the pipe should be ""slippery + + Scenario: test making a pipe sticky + Given a pipe + Given the saboteur currently standing on that pipe + When the saboteur tries to make that sticky + Then the pipe should be ""sticky \ No newline at end of file