diff options
Diffstat (limited to 'core/test/ch/asynk')
-rw-r--r-- | core/test/ch/asynk/tankontank/Helpers.java | 67 | ||||
-rw-r--r-- | core/test/ch/asynk/tankontank/LineOfSightTest.java | 61 |
2 files changed, 68 insertions, 60 deletions
diff --git a/core/test/ch/asynk/tankontank/Helpers.java b/core/test/ch/asynk/tankontank/Helpers.java new file mode 100644 index 0000000..b3d98e6 --- /dev/null +++ b/core/test/ch/asynk/tankontank/Helpers.java @@ -0,0 +1,67 @@ +package ch.asynk.tankontank; + +import ch.asynk.tankontank.engine.Board; +import ch.asynk.tankontank.engine.Tile; +import ch.asynk.tankontank.engine.Pawn; + +public class Helpers +{ + public static class FakeTile extends Tile + { + public boolean offMap; + + public FakeTile() + { + super(); + offMap = false; + } + + public FakeTile(boolean offMap) + { + this.offMap = offMap; + } + + public boolean isOffMap() + { + return offMap; + } + public boolean blockLineOfSightFrom(Tile from) { return false; } + public boolean atLeastOneMove(Pawn pawn) { return true; } + public boolean road(Board.Orientation side) { return false; } + public int costFrom(Pawn pawn, Board.Orientation side, boolean road) { return 1; } + public boolean hasTargetsFor(Pawn pawn) { return false; } + } + + public static class FakeBoard extends Board + { + private int cols; + private int rows; + public FakeTile fakeTiles[]; + + public FakeBoard(int cols, int rows) + { + super(); + this.cols = cols; + this.rows = rows; + fakeTiles = new FakeTile[cols * rows]; + for (int i = 0; i < rows; i++) { + for ( int j = 0; j < cols; j ++) + fakeTiles[j + (i * cols)] = new FakeTile(); + } + fakeTiles[19].offMap = true; + fakeTiles[39].offMap = true; + fakeTiles[59].offMap = true; + fakeTiles[79].offMap = true; + } + + @Override + public Tile getTile(int col, int row) + { + int colOffset = ((row + 1) / 2); + if ((col < colOffset) || (row < 0) || (row >= rows) || ((col - colOffset) >= cols)) + return new FakeTile(true);; + int idx = ((col - colOffset)) + (row * cols); + return fakeTiles[idx]; + } + } +} diff --git a/core/test/ch/asynk/tankontank/LineOfSightTest.java b/core/test/ch/asynk/tankontank/LineOfSightTest.java index 8c15908..2f901af 100644 --- a/core/test/ch/asynk/tankontank/LineOfSightTest.java +++ b/core/test/ch/asynk/tankontank/LineOfSightTest.java @@ -13,65 +13,6 @@ import ch.asynk.tankontank.engine.SearchBoard.Node; import static org.junit.Assert.assertTrue; -class FakeTile extends Tile -{ - public boolean offMap; - - public FakeTile() - { - super(); - offMap = false; - } - - public FakeTile(boolean offMap) - { - this.offMap = offMap; - } - - public boolean isOffMap() - { - return offMap; - } - public boolean blockLineOfSightFrom(Tile from) { return false; } - public boolean atLeastOneMove(Pawn pawn) { return true; } - public boolean road(Board.Orientation side) { return false; } - public int costFrom(Pawn pawn, Board.Orientation side, boolean road) { return 1; } - public boolean hasTargetsFor(Pawn pawn) { return false; } -} - -class FakeBoard extends Board -{ - private int cols; - private int rows; - public FakeTile fakeTiles[]; - - public FakeBoard(int cols, int rows) - { - super(); - this.cols = cols; - this.rows = rows; - fakeTiles = new FakeTile[cols * rows]; - for (int i = 0; i < rows; i++) { - for ( int j = 0; j < cols; j ++) - fakeTiles[j + (i * cols)] = new FakeTile(); - } - fakeTiles[19].offMap = true; - fakeTiles[39].offMap = true; - fakeTiles[59].offMap = true; - fakeTiles[79].offMap = true; - } - - @Override - public Tile getTile(int col, int row) - { - int colOffset = ((row + 1) / 2); - if ((col < colOffset) || (row < 0) || (row >= rows) || ((col - colOffset) >= cols)) - return new FakeTile(true);; - int idx = ((col - colOffset)) + (row * cols); - return fakeTiles[idx]; - } -} - public class LineOfSightTest { private SearchBoard sb; @@ -81,7 +22,7 @@ public class LineOfSightTest { int cols = 10; int rows = 9; - FakeBoard fakeBoard = new FakeBoard(cols, rows); + Helpers.FakeBoard fakeBoard = new Helpers.FakeBoard(cols, rows); sb = new SearchBoard(fakeBoard, cols, rows); } |