diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-01 10:45:06 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-01 10:45:06 +0200 |
commit | 048f714663da82a70dc7423881daf7b9195a32d9 (patch) | |
tree | 803977db34d773c7b492a291624bee647dc755fa | |
parent | 46b0fbb938636ed24ac93ffc4a07db2d515541ce (diff) | |
download | RustAndDust-048f714663da82a70dc7423881daf7b9195a32d9.zip RustAndDust-048f714663da82a70dc7423881daf7b9195a32d9.tar.gz |
FakeBoard and FakeTile go into test/../Helpers
-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); } |