summaryrefslogtreecommitdiffstats
path: root/core/test/ch/asynk/rustanddust
diff options
context:
space:
mode:
Diffstat (limited to 'core/test/ch/asynk/rustanddust')
-rw-r--r--core/test/ch/asynk/rustanddust/Helpers.java8
-rw-r--r--core/test/ch/asynk/rustanddust/LineOfSightTest.java106
2 files changed, 109 insertions, 5 deletions
diff --git a/core/test/ch/asynk/rustanddust/Helpers.java b/core/test/ch/asynk/rustanddust/Helpers.java
index 673be1f..f75e75e 100644
--- a/core/test/ch/asynk/rustanddust/Helpers.java
+++ b/core/test/ch/asynk/rustanddust/Helpers.java
@@ -52,11 +52,13 @@ public class Helpers
public static class FakeTile extends Tile
{
public boolean offMap;
+ public boolean blockLineOfSight;
public FakeTile(int col, int row)
{
super(col, row);
offMap = false;
+ blockLineOfSight = false;
}
public FakeTile(int col, int row, boolean offMap)
@@ -76,7 +78,9 @@ public class Helpers
@Override public boolean isA(TileTerrain terrain) { return true; }
@Override public boolean road(Orientation side) { return false; }
@Override public boolean atLeastOneMove(Pawn pawn) { return true; }
- @Override public boolean blockLineOfSightFrom(Tile from) { return false; }
+ @Override public boolean blockLineOfSightFrom(Tile from) { return blockLineOfSight; }
+
+ public void setBlockLineOfSight(boolean block) { blockLineOfSight = block; }
}
public static class FakeSearchBoard extends SearchBoard
@@ -90,6 +94,8 @@ public class Helpers
{
return distance(getNode(col0, row0), getNode(col1, row1));
}
+
+ public Node get(int col, int row) { return getNode(col, row); }
}
public static class FakeBoard extends Board
diff --git a/core/test/ch/asynk/rustanddust/LineOfSightTest.java b/core/test/ch/asynk/rustanddust/LineOfSightTest.java
index 60b95ab..45363ae 100644
--- a/core/test/ch/asynk/rustanddust/LineOfSightTest.java
+++ b/core/test/ch/asynk/rustanddust/LineOfSightTest.java
@@ -5,22 +5,27 @@ import java.util.List;
import org.junit.Test;
import org.junit.Before;
-import ch.asynk.rustanddust.engine.SearchBoard;
import ch.asynk.rustanddust.engine.SearchBoard.Node;
import static org.junit.Assert.assertTrue;
public class LineOfSightTest
{
- private SearchBoard sb;
+ private Helpers.FakeBoard fakeBoard;
+ private Helpers.FakeSearchBoard sb;
@Before
public void initialize()
{
int cols = 10;
int rows = 9;
- Helpers.FakeBoard fakeBoard = new Helpers.FakeBoard(cols, rows, 0);
- sb = new SearchBoard(fakeBoard, cols, rows);
+ fakeBoard = new Helpers.FakeBoard(cols, rows, 0);
+ sb = new Helpers.FakeSearchBoard(fakeBoard, cols, rows);
+ }
+
+ private void block(int i, int j, boolean block)
+ {
+ ((Helpers.FakeTile) fakeBoard.getTile(i, j)).setBlockLineOfSight(block);
}
private void checkNode(List<Node> l, int i, int col, int row)
@@ -1418,4 +1423,97 @@ public class LineOfSightTest
checkNode(s, 12, 4, 7);
checkNode(s, 13, 4, 8);
}
+
+ private void testBlocking(Node from, Node to, Node blockA, Node blockB)
+ {
+ List<Node> s = null;
+
+ // clear
+ s = lineOfSight(from.col, from.row, to.col, to.row);
+ assertTrue(s.size() == 4);
+ checkNode(s, 0, from.col, from.row);
+ checkNode(s, 3, to.col, to.row);
+
+ // block A
+ block(blockA.col, blockA.row, true);
+ s = lineOfSight(from.col, from.row, to.col, to.row);
+ assertTrue(s.size() == 4);
+ checkNode(s, 0, from.col, from.row);
+ checkNode(s, 3, to.col, to.row);
+ block(blockA.col, blockA.row, false);
+
+ // block B
+ block(blockB.col, blockB.row, true);
+ s = lineOfSight(from.col, from.row, to.col, to.row);
+ assertTrue(s.size() == 4);
+ checkNode(s, 0, from.col, from.row);
+ checkNode(s, 3, to.col, to.row);
+ block(blockB.col, blockB.row, false);
+
+ // block A and B
+ block(blockA.col, blockA.row, true);
+ block(blockB.col, blockB.row, true);
+ s = lineOfSight(from.col, from.row, to.col, to.row);
+ assertTrue(s.size() == 3);
+ checkNode(s, 0, from.col, from.row);
+ block(blockA.col, blockA.row, false);
+ block(blockB.col, blockB.row, false);
+
+ // reverse
+ // clear
+ s = lineOfSight(to.col, to.row, from.col, from.row);
+ assertTrue(s.size() == 4);
+ checkNode(s, 0, to.col, to.row);
+ checkNode(s, 3, from.col, from.row);
+
+ // block A
+ block(blockA.col, blockA.row, true);
+ s = lineOfSight(to.col, to.row, from.col, from.row);
+ assertTrue(s.size() == 4);
+ checkNode(s, 0, to.col, to.row);
+ checkNode(s, 3, from.col, from.row);
+ block(blockA.col, blockA.row, false);
+
+ // block B
+ block(blockB.col, blockB.row, true);
+ s = lineOfSight(to.col, to.row, from.col, from.row);
+ assertTrue(s.size() == 4);
+ checkNode(s, 0, to.col, to.row);
+ checkNode(s, 3, from.col, from.row);
+ block(blockB.col, blockB.row, false);
+
+ // block A and B
+ block(blockA.col, blockA.row, true);
+ block(blockB.col, blockB.row, true);
+ s = lineOfSight(to.col, to.row, from.col, from.row);
+ assertTrue(s.size() == 3);
+ checkNode(s, 0, to.col, to.row);
+ block(blockA.col, blockA.row, false);
+ block(blockB.col, blockB.row, false);
+
+ }
+
+ @Test public void test_97() {
+ testBlocking(sb.get(6, 4), sb.get(7, 6), sb.get(6, 5), sb.get(7, 5));
+ }
+
+ @Test public void test_98() {
+ testBlocking(sb.get(6, 4), sb.get(8, 5), sb.get(7, 5), sb.get(7, 4));
+ }
+
+ @Test public void test_99() {
+ testBlocking(sb.get(6, 4), sb.get(7, 3), sb.get(7, 4), sb.get(6, 3));
+ }
+
+ @Test public void test_100() {
+ testBlocking(sb.get(6, 4), sb.get(5, 2), sb.get(5, 3), sb.get(6, 3));
+ }
+
+ @Test public void test_101() {
+ testBlocking(sb.get(6, 4), sb.get(4, 3), sb.get(5, 4), sb.get(5, 3));
+ }
+
+ @Test public void test_102() {
+ testBlocking(sb.get(6, 4), sb.get(5, 5), sb.get(5, 4), sb.get(6, 5));
+ }
}