summaryrefslogtreecommitdiffstats
path: root/core/test/ch
diff options
context:
space:
mode:
Diffstat (limited to 'core/test/ch')
-rw-r--r--core/test/ch/asynk/tankontank/BoardUtils.java38
-rw-r--r--core/test/ch/asynk/tankontank/Helpers.java31
-rw-r--r--core/test/ch/asynk/tankontank/LineOfSightTest.java2
3 files changed, 40 insertions, 31 deletions
diff --git a/core/test/ch/asynk/tankontank/BoardUtils.java b/core/test/ch/asynk/tankontank/BoardUtils.java
index 757e315..5324a93 100644
--- a/core/test/ch/asynk/tankontank/BoardUtils.java
+++ b/core/test/ch/asynk/tankontank/BoardUtils.java
@@ -23,15 +23,15 @@ public class BoardUtils
{
int cols = 10;
int rows = 9;
- b = new Helpers.FakeBoard(cols, rows);
+ int mvt = 3;
+ b = new Helpers.FakeBoard(cols, rows, 3);
sb = new SearchBoard(b, cols, rows);
}
@Test
public void testPaths()
{
- Helpers.FakePawn p = new Helpers.FakePawn(3);
- List<ArrayList<SearchBoard.Node>> paths = sb.possiblePaths(p, 2, 2, 4, 3);
+ List<ArrayList<SearchBoard.Node>> paths = b.buildPossiblePaths(2, 2, 4, 3);
assertTrue(paths.size() == 8);
@@ -94,45 +94,32 @@ public class BoardUtils
@Test
public void testPathSet()
{
- Helpers.FakePawn p = new Helpers.FakePawn(3);
HashSet<GridPoint2> points = new HashSet<GridPoint2>();
- GridPoint2 from = new GridPoint2(2, 2);
- GridPoint2 to = new GridPoint2(3, 3);
-
- int n = b.possiblePaths(p, from, to, points);
+ int n = b.buildPossiblePaths(2, 2, 3, 3, points);
assertTrue(n == 1);
assertTrue(points.size() == 0);
- to.set(4, 3);
-
- n = b.possiblePaths(p, from, to, points);
+ n = b.buildPossiblePaths(2, 2, 4, 3, points);
assertTrue(n == 8);
assertTrue(points.size() == 6);
- GridPoint2 p0 = new GridPoint2(3, 3);
- n = b.possiblePathsFilterToggle(p0, points);
-
+ n = b.togglePoint(3, 3);
assertTrue(n == 1);
- assertTrue(points.size() == 1);
- to.set(5, 3);
-
- n = b.possiblePaths(p, from, to, points);
+ n = b.buildPossiblePaths(2, 2, 5, 3, points);
assertTrue(n == 3);
- p0.set(3, 3);
- n = b.possiblePathsFilterToggle(p0, points);
+ n = b.togglePoint(3, 3);
assertTrue(n == 1);
- n = b.possiblePathsFilterToggle(p0, points);
+
+ n = b.togglePoint(3, 3);
assertTrue(n == 3);
- GridPoint2 p1 = new GridPoint2(3, 2);
- n = b.possiblePathsFilterToggle(p1, points);
+ n = b.togglePoint(3, 2);
assertTrue(n == 2);
- GridPoint2 p2 = new GridPoint2(4, 2);
- n = b.possiblePathsFilterToggle(p2, points);
+ n = b.togglePoint(4, 2);
assertTrue(n == 1);
}
@@ -140,7 +127,6 @@ public class BoardUtils
@Test
public void testDistance()
{
-
assertTrue(sb.distance(6, 4, 6, 4) == 0);
assertTrue(sb.distance(6, 4, 5, 4) == 1);
assertTrue(sb.distance(6, 4, 6, 5) == 1);
diff --git a/core/test/ch/asynk/tankontank/Helpers.java b/core/test/ch/asynk/tankontank/Helpers.java
index 51fdc2e..731aaa2 100644
--- a/core/test/ch/asynk/tankontank/Helpers.java
+++ b/core/test/ch/asynk/tankontank/Helpers.java
@@ -1,5 +1,11 @@
package ch.asynk.tankontank;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.HashSet;
+
+import com.badlogic.gdx.math.GridPoint2;
+
import ch.asynk.tankontank.engine.Pawn;
import ch.asynk.tankontank.engine.Tile;
import ch.asynk.tankontank.engine.Board;
@@ -49,7 +55,7 @@ public class Helpers
}
public boolean blockLineOfSightFrom(Tile from) { return false; }
public boolean atLeastOneMove(Pawn pawn) { return true; }
- public boolean road(Orientation side) { return false; }
+ public boolean road(Orientation side) { return false; }
public boolean hasTargetsFor(Pawn pawn) { return false; }
public int costFrom(Pawn pawn, Orientation side, boolean road) { return 1; }
}
@@ -59,10 +65,11 @@ public class Helpers
private int cols;
private int rows;
public FakeTile fakeTiles[];
+ public FakePawn pawn;
- public FakeBoard(int cols, int rows)
+ public FakeBoard(int cols, int rows, int mvt)
{
- super();
+ super(cols, rows);
this.cols = cols;
this.rows = rows;
fakeTiles = new FakeTile[cols * rows];
@@ -74,7 +81,7 @@ public class Helpers
fakeTiles[39].offMap = true;
fakeTiles[59].offMap = true;
fakeTiles[79].offMap = true;
- this.searchBoard = new SearchBoard(this, cols, rows);
+ pawn = new FakePawn(mvt);
}
@Override
@@ -86,5 +93,21 @@ public class Helpers
int idx = ((col - colOffset)) + (row * cols);
return fakeTiles[idx];
}
+
+ public List<ArrayList<SearchBoard.Node>> buildPossiblePaths(int x0, int y0, int x1, int y1)
+ {
+ buildPossiblePaths(pawn, new GridPoint2(x0, y0), new GridPoint2(x1, y1), new HashSet<GridPoint2>());
+ return paths;
+ }
+
+ public int buildPossiblePaths(int x0, int y0, int x1, int y1, HashSet<GridPoint2> points)
+ {
+ return buildPossiblePaths(pawn, new GridPoint2(x0, y0), new GridPoint2(x1, y1), points);
+ }
+
+ public int togglePoint(int x, int y)
+ {
+ return possiblePathsFilterToggle(new GridPoint2(x, y), new HashSet<GridPoint2>());
+ }
}
}
diff --git a/core/test/ch/asynk/tankontank/LineOfSightTest.java b/core/test/ch/asynk/tankontank/LineOfSightTest.java
index cf2d83b..b559e03 100644
--- a/core/test/ch/asynk/tankontank/LineOfSightTest.java
+++ b/core/test/ch/asynk/tankontank/LineOfSightTest.java
@@ -19,7 +19,7 @@ public class LineOfSightTest
{
int cols = 10;
int rows = 9;
- Helpers.FakeBoard fakeBoard = new Helpers.FakeBoard(cols, rows);
+ Helpers.FakeBoard fakeBoard = new Helpers.FakeBoard(cols, rows, 0);
sb = new SearchBoard(fakeBoard, cols, rows);
}