summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-01 12:04:02 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-01 12:04:02 +0200
commit1ce860bd73131559930c0d2174781af5487d10e2 (patch)
treebde1cad341a8d7871cfe8a23f4c7046947a47af3 /core
parent8f1bc29230f1af76fe50fd9a3e533a06b7aec33e (diff)
downloadRustAndDust-1ce860bd73131559930c0d2174781af5487d10e2.zip
RustAndDust-1ce860bd73131559930c0d2174781af5487d10e2.tar.gz
add possiblePaths(...) tests
Diffstat (limited to 'core')
-rw-r--r--core/test/ch/asynk/tankontank/BoardUtils.java77
1 files changed, 76 insertions, 1 deletions
diff --git a/core/test/ch/asynk/tankontank/BoardUtils.java b/core/test/ch/asynk/tankontank/BoardUtils.java
index e944693..632d7a4 100644
--- a/core/test/ch/asynk/tankontank/BoardUtils.java
+++ b/core/test/ch/asynk/tankontank/BoardUtils.java
@@ -1,6 +1,7 @@
package ch.asynk.tankontank;
import java.util.List;
+import java.util.ArrayDeque;
import org.junit.Test;
import org.junit.Before;
@@ -16,7 +17,81 @@ public class BoardUtils
@Before
public void initialize()
{
- sb = new SearchBoard(null, 10, 9);
+ int cols = 10;
+ int rows = 9;
+ Helpers.FakeBoard fakeBoard = new Helpers.FakeBoard(cols, rows);
+ sb = new SearchBoard(fakeBoard, cols, rows);
+ }
+
+ @Test
+ public void testPaths()
+ {
+ Helpers.FakePawn p = new Helpers.FakePawn(3);
+ List<ArrayDeque<SearchBoard.Node>> paths = sb.possiblePaths(p, 2, 2, 4, 3);
+
+ assertTrue(paths.size() == 8);
+
+ for(ArrayDeque<SearchBoard.Node> path : paths) {
+
+ assertTrue((path.size() == 3) || (path.size() == 4));
+ SearchBoard.Node n = path.removeFirst();
+ assertTrue(n.col == 4);
+ assertTrue(n.row == 3);
+ n = path.removeLast();
+ assertTrue(n.col == 2);
+ assertTrue(n.row == 2);
+
+ if (path.size() == 1) {
+ n = path.pop();
+ assertTrue(n.col == 3);
+ assertTrue((n.row == 3) || (n.row == 2));
+ } else {
+ n = path.pop();
+ if (n.col == 2) {
+ if (n.col == 1) {
+ n = path.pop();
+ assert(n.col == 3);
+ assert(n.row == 2);
+ } else {
+ assert(n.col == 3);
+ n = path.pop();
+ assert(n.col == 2);
+ assert(n.row == 3);
+ }
+ } else if (n.col == 3) {
+ if (n.row == 2) {
+ n = path.pop();
+ if (n.col == 2)
+ assert(n.row == 1);
+ else {
+ assert(n.col == 3);
+ assert(n.row == 3);
+ }
+ } else {
+ assert(n.col == 3);
+ n = path.pop();
+ if (n.col == 2)
+ assert(n.row == 3);
+ else {
+ assert(n.col == 3);
+ assert(n.row == 2);
+ }
+ }
+ } else {
+ assertTrue(n.col == 4);
+ if (n.row == 4) {
+ n = path.pop();
+ assert(n.col == 3);
+ assert(n.row == 3);
+ } else {
+ assert(n.row == 2);
+ n = path.pop();
+ assert(n.col == 3);
+ assert(n.row == 2);
+ }
+ }
+ }
+ }
}
@Test