Skip to content

Commit

Permalink
tesztek megírása
Browse files Browse the repository at this point in the history
Közös munka IntelliJ-ben Code With Me funkcióval.

Résztvevők:
Karsai Artúr
Sinkler Szilveszter
  • Loading branch information
szilva07 committed May 14, 2024
1 parent 3deb342 commit 70375ea
Show file tree
Hide file tree
Showing 9 changed files with 280 additions and 11 deletions.
Empty file.
57 changes: 57 additions & 0 deletions src/test/java/cucumberTest/FixerActionsOnTank.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
30 changes: 22 additions & 8 deletions src/test/java/cucumberTest/FixerFixes.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,41 @@
import drukmakoriSzerelok.Fixer;
import drukmakoriSzerelok.Game;
import drukmakoriSzerelok.Pipe;
import drukmakoriSzerelok.Pump;

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 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")
Expand All @@ -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));
}

}
72 changes: 72 additions & 0 deletions src/test/java/cucumberTest/PlayerMoves.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
75 changes: 75 additions & 0 deletions src/test/java/cucumberTest/SaboteurActionsOnPipe.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
14 changes: 14 additions & 0 deletions src/test/resources/cucumberTest/FixerActionsOnTank.feature
Original file line number Diff line number Diff line change
@@ -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
11 changes: 8 additions & 3 deletions src/test/resources/cucumberTest/FixerFixes.feature
Original file line number Diff line number Diff line change
@@ -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"
14 changes: 14 additions & 0 deletions src/test/resources/cucumberTest/PlayerMoves.feature
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions src/test/resources/cucumberTest/SaboteurActionsOnPipe.feature
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 70375ea

Please sign in to comment.