Skip to content

Commit

Permalink
Fixed bug with ConnectPipe and done more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gergobuzas committed May 21, 2024
1 parent 4bfbfd8 commit 1af1964
Show file tree
Hide file tree
Showing 11 changed files with 343 additions and 37 deletions.
2 changes: 1 addition & 1 deletion HwProject/src/Pump.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public int repair()
@Override
public int connectPipe(Pipe pipe)
{
if (connectedPipes.size() < maxConnectedPipes - 1)
if (connectedPipes.size() < maxConnectedPipes)
{
return super.connectPipe(pipe);
}
Expand Down
5 changes: 1 addition & 4 deletions HwProject/tests/DrainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ public void testPickUpPipe() {

@AfterEach
public void cleanUp() {
TestPump.setInstanceNr(0);
TestPipe.setInstanceNr(0);
TestSource.setInstanceNr(0);
TestDrain.setInstanceNr(0);
TestCleanup.cleanup();
}
}
67 changes: 43 additions & 24 deletions HwProject/tests/HelperClasses/TestPipe.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
package HwProject.tests.HelperClasses;

import HwProject.src.Pipe;

/**
* Pipe subclass for testing, only added setters and getters for each private and protected field
*/
public class TestPipe extends Pipe {
public TestPipe() {
super();
}

public int getWaterLevel() {
return waterLevel;
}

public void setWaterLevel(int waterLevel) {
this.waterLevel = waterLevel;
}

public static void setInstanceNr(int i) {
instanceNr = i;
}
}
package tests.HelperClasses;

import src.*;

import java.util.ArrayList;
import java.util.Collection;

/**
* Pipe subclass for testing, only added setters and getters for each private and protected field
*/
public class TestPipe extends Pipe {
public TestPipe() {
super();
}

public int getWaterLevel() {
return waterLevel;
}

public void setWaterLevel(int waterLevel) {
this.waterLevel = waterLevel;
}

public boolean getSplippy() {
return this.isSlippy;
}

public StickyStates getSticky() {
return this.stickyState;
}

public static void setInstanceNr(int i) {
instanceNr = i;
}

public ArrayList<Player> getPlayers() {
return players;
}

public boolean getDamage() {
return isDamaged;
}
}
5 changes: 1 addition & 4 deletions HwProject/tests/PumpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ void testDisconnectPipe() {

@AfterEach
public void cleanUp() {
TestPump.setInstanceNr(0);
TestPipe.setInstanceNr(0);
TestSource.setInstanceNr(0);
TestDrain.setInstanceNr(0);
TestCleanup.cleanup();
}
}
5 changes: 1 addition & 4 deletions HwProject/tests/SourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ public void testStepCallsPushWater() {

@AfterEach
public void cleanUp() {
TestPump.setInstanceNr(0);
TestPipe.setInstanceNr(0);
TestSource.setInstanceNr(0);
TestDrain.setInstanceNr(0);
TestCleanup.cleanup();
}
}
Binary file added docs/Connect_pipe_fixed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Connect_pipe_wrong.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions src/SaboteurTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package src;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import tests.HelperClasses.TestCleanup;
import tests.HelperClasses.TestSaboteur;

import static org.junit.jupiter.api.Assertions.*;

class SaboteurTest {
private Game game;

private TestSaboteur saboteur;

@BeforeEach
public void setUp() {
game = new Game(System.out);
Pipe.SetGame(game);
Drain.SetGame(game);
saboteur = new TestSaboteur("Saboteur1", game.GetFieldByID("Drain1"));
}

@Test
void move() {
saboteur.Move(game.GetFieldByID("Pipe12"));
assertEquals(game.GetFieldByID("Pipe12"), saboteur.getPosition());

TestSaboteur saboteur2 = new TestSaboteur("Saboteur2", game.GetFieldByID("Drain1"));
saboteur2.Move(game.GetFieldByID("Pipe12"));
assertEquals(game.GetFieldByID("Drain1"), saboteur2.getPosition());
}

@Test
void setPumpDirection() {
saboteur.Move(game.GetFieldByID("Pipe12"));
saboteur.Move(game.GetFieldByID("Pump5"));
saboteur.SetPumpDirection((Pipe) game.GetFieldByID("Pipe3"), (Pipe) game.GetFieldByID("Pipe10"));
assertEquals(game.GetFieldByID("Pipe10"), ((Pump) game.GetFieldByID("Pump5")).output);
assertEquals(game.GetFieldByID("Pipe3"), ((Pump) game.GetFieldByID("Pump5")).input);
}

@Test
void damage() {
saboteur.Move(game.GetFieldByID("Pipe12"));
saboteur.Damage();
assertTrue(((Pipe) game.GetFieldByID("Pipe12")).isDamaged);
}

@Test
void makeSlippy() {
saboteur.Move(game.GetFieldByID("Pipe12"));
saboteur.MakeSlippy();
assertTrue(((Pipe) game.GetFieldByID("Pipe12")).isSlippy);
}

@Test
void makeSticky() {
}

@Test
void testSetPumpDirection() {
}

@Test
void testDamage() {
}

@Test
void testMakeSlippy() {
}

@Test
void testMakeSticky() {
}

@AfterEach
public void cleanUp() {
TestCleanup.cleanup();
}
}
11 changes: 11 additions & 0 deletions tests/HelperClasses/TestCleanup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package tests.HelperClasses;

public class TestCleanup {

public static void cleanup() {
TestPump.setInstanceNr(0);
TestPipe.setInstanceNr(0);
TestSource.setInstanceNr(0);
TestDrain.setInstanceNr(0);
}
}
12 changes: 12 additions & 0 deletions tests/HelperClasses/TestSaboteur.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package tests.HelperClasses;
import src.*;
public class TestSaboteur extends Saboteur {

public TestSaboteur(String ID, Field position) {
super(ID, position);
}

public Field getPosition() {
return position;
}
}
Loading

0 comments on commit 1af1964

Please sign in to comment.