summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2016-12-24 13:02:22 +0100
committerjbion <joffrey.bion@amadeus.com>2016-12-24 13:55:19 +0100
commit4174a130e3dc0355269140c2339adb044f6c4360 (patch)
treec3300b991273b0af024a074ebfd009ab1ac69dbd /src/test/java
parentAdd test for RawPointsIncrease (diff)
downloadseven-wonders-4174a130e3dc0355269140c2339adb044f6c4360.tar.gz
seven-wonders-4174a130e3dc0355269140c2339adb044f6c4360.tar.bz2
seven-wonders-4174a130e3dc0355269140c2339adb044f6c4360.zip
Add test for relative board position accesses
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/api/TableTest.java49
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/boards/RelativeBoardPositionTest.java44
2 files changed, 93 insertions, 0 deletions
diff --git a/src/test/java/org/luxons/sevenwonders/game/api/TableTest.java b/src/test/java/org/luxons/sevenwonders/game/api/TableTest.java
new file mode 100644
index 00000000..9ed0af02
--- /dev/null
+++ b/src/test/java/org/luxons/sevenwonders/game/api/TableTest.java
@@ -0,0 +1,49 @@
+package org.luxons.sevenwonders.game.api;
+
+import org.junit.experimental.theories.DataPoints;
+import org.junit.experimental.theories.Theories;
+import org.junit.experimental.theories.Theory;
+import org.junit.runner.RunWith;
+import org.luxons.sevenwonders.game.boards.RelativeBoardPosition;
+import org.luxons.sevenwonders.game.test.TestUtils;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assume.assumeTrue;
+
+@RunWith(Theories.class)
+public class TableTest {
+
+ @DataPoints
+ public static int[] nbPlayers() {
+ return new int[] {2, 3, 4, 5, 6, 7, 8};
+ }
+
+ @Theory
+ public void getBoard_wrapLeft(int nbPlayers) {
+ assumeTrue(nbPlayers >= 2);
+ Table table = TestUtils.createTable(nbPlayers);
+ int last = nbPlayers - 1;
+ assertEquals(table.getBoard(last), table.getBoard(0, RelativeBoardPosition.LEFT));
+ assertEquals(table.getBoard(0), table.getBoard(0, RelativeBoardPosition.SELF));
+ assertEquals(table.getBoard(1), table.getBoard(0, RelativeBoardPosition.RIGHT));
+ }
+
+ @Theory
+ public void getBoard_wrapRight(int nbPlayers) {
+ assumeTrue(nbPlayers >= 2);
+ Table table = TestUtils.createTable(nbPlayers);
+ int last = nbPlayers - 1;
+ assertEquals(table.getBoard(last - 1), table.getBoard(last, RelativeBoardPosition.LEFT));
+ assertEquals(table.getBoard(last), table.getBoard(last, RelativeBoardPosition.SELF));
+ assertEquals(table.getBoard(0), table.getBoard(last, RelativeBoardPosition.RIGHT));
+ }
+
+ @Theory
+ public void getBoard_noWrap(int nbPlayers) {
+ assumeTrue(nbPlayers >= 3);
+ Table table = TestUtils.createTable(nbPlayers);
+ assertEquals(table.getBoard(0), table.getBoard(1, RelativeBoardPosition.LEFT));
+ assertEquals(table.getBoard(1), table.getBoard(1, RelativeBoardPosition.SELF));
+ assertEquals(table.getBoard(2), table.getBoard(1, RelativeBoardPosition.RIGHT));
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/luxons/sevenwonders/game/boards/RelativeBoardPositionTest.java b/src/test/java/org/luxons/sevenwonders/game/boards/RelativeBoardPositionTest.java
new file mode 100644
index 00000000..e95a1e37
--- /dev/null
+++ b/src/test/java/org/luxons/sevenwonders/game/boards/RelativeBoardPositionTest.java
@@ -0,0 +1,44 @@
+package org.luxons.sevenwonders.game.boards;
+
+import org.junit.experimental.theories.DataPoints;
+import org.junit.experimental.theories.Theories;
+import org.junit.experimental.theories.Theory;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.*;
+import static org.junit.Assume.*;
+
+@RunWith(Theories.class)
+public class RelativeBoardPositionTest {
+
+ @DataPoints
+ public static int[] nbPlayers() {
+ return new int[] {1, 2, 3, 5, 7, 9};
+ }
+
+ @Theory
+ public void getIndexFrom_wrapLeft(int nbPlayers) {
+ assumeTrue(nbPlayers >= 2);
+ int last = nbPlayers - 1;
+ assertEquals(last, RelativeBoardPosition.LEFT.getIndexFrom(0, nbPlayers));
+ assertEquals(0, RelativeBoardPosition.SELF.getIndexFrom(0, nbPlayers));
+ assertEquals(1, RelativeBoardPosition.RIGHT.getIndexFrom(0, nbPlayers));
+ }
+
+ @Theory
+ public void getIndexFrom_wrapRight(int nbPlayers) {
+ assumeTrue(nbPlayers >= 2);
+ int last = nbPlayers - 1;
+ assertEquals(last - 1, RelativeBoardPosition.LEFT.getIndexFrom(last, nbPlayers));
+ assertEquals(last, RelativeBoardPosition.SELF.getIndexFrom(last, nbPlayers));
+ assertEquals(0, RelativeBoardPosition.RIGHT.getIndexFrom(last, nbPlayers));
+ }
+
+ @Theory
+ public void getIndexFrom_noWrap(int nbPlayers) {
+ assumeTrue(nbPlayers >= 3);
+ assertEquals(0, RelativeBoardPosition.LEFT.getIndexFrom(1, nbPlayers));
+ assertEquals(1, RelativeBoardPosition.SELF.getIndexFrom(1, nbPlayers));
+ assertEquals(2, RelativeBoardPosition.RIGHT.getIndexFrom(1, nbPlayers));
+ }
+} \ No newline at end of file
bgstack15