summaryrefslogtreecommitdiffstats
path: root/test/src/ch/asynk/gdx/boardgame
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2020-07-03 11:05:48 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2020-07-03 11:05:48 +0200
commit64f863949a4100d632124e19f54b8cc93fdc79fe (patch)
treee0dd521141ddd9d5d485ec98a87f209a71072ab1 /test/src/ch/asynk/gdx/boardgame
parent79fb05c4674b8c8ad688a049c4fbbb38e58b4c4f (diff)
downloadgdx-boardgame-64f863949a4100d632124e19f54b8cc93fdc79fe.zip
gdx-boardgame-64f863949a4100d632124e19f54b8cc93fdc79fe.tar.gz
add quick and dirty tests
Diffstat (limited to 'test/src/ch/asynk/gdx/boardgame')
-rw-r--r--test/src/ch/asynk/gdx/boardgame/test/DesktopLauncher.java12
-rw-r--r--test/src/ch/asynk/gdx/boardgame/test/Tests.java82
2 files changed, 90 insertions, 4 deletions
diff --git a/test/src/ch/asynk/gdx/boardgame/test/DesktopLauncher.java b/test/src/ch/asynk/gdx/boardgame/test/DesktopLauncher.java
index 2c9066f..a1dc054 100644
--- a/test/src/ch/asynk/gdx/boardgame/test/DesktopLauncher.java
+++ b/test/src/ch/asynk/gdx/boardgame/test/DesktopLauncher.java
@@ -4,11 +4,15 @@ import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
public class DesktopLauncher {
- public static void main (String[] arg) {
- LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
- new LwjglApplication(new GdxBoardTest(), config);
+ public static void main (String[] arg) {
+
+ Tests tests = new Tests();
+ tests.run();
+
+ LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
+ new LwjglApplication(new GdxBoardTest(), config);
config.title = "gdx-boardgame Demo";
config.width=800;
config.height=600;
- }
+ }
}
diff --git a/test/src/ch/asynk/gdx/boardgame/test/Tests.java b/test/src/ch/asynk/gdx/boardgame/test/Tests.java
new file mode 100644
index 0000000..f6e2198
--- /dev/null
+++ b/test/src/ch/asynk/gdx/boardgame/test/Tests.java
@@ -0,0 +1,82 @@
+package ch.asynk.gdx.boardgame.test;
+
+import com.badlogic.gdx.math.Vector2;
+
+import ch.asynk.gdx.boardgame.Tile;
+import ch.asynk.gdx.boardgame.tilestorages.TileStorage;
+import ch.asynk.gdx.boardgame.tilestorages.ArrayTileStorage;
+import ch.asynk.gdx.boardgame.boards.Board;
+import ch.asynk.gdx.boardgame.boards.BoardFactory;
+
+public class Tests
+{
+ private Board board;
+ private TileStorage tileStorage;
+ private Vector2 v;
+
+ public Tests()
+ {
+ v = new Vector2();
+ }
+
+ public void run ()
+ {
+ System.err.println("Run tests ...");
+ runHexVertical();
+ runHexHorizontal();
+ System.err.println("done.");
+ }
+
+ private void runHexVertical()
+ {
+ board = BoardFactory.getBoard(10, 9, BoardFactory.BoardType.HEX, 110, 50, 103, BoardFactory.BoardOrientation.VERTICAL, this::getTile);
+ tileStorage = new ArrayTileStorage(board.size());
+ testTouch(899, 602, 5, 3, 812, 653, 32);
+ testTouch(906, 593, 5, 2, 907, 488, 23);
+ testTouch(916, 601, 6, 3, 1002, 653, 33);
+ }
+
+ private void runHexHorizontal()
+ {
+ board = BoardFactory.getBoard(9, 10, BoardFactory.BoardType.HEX, 110, 103, 50, BoardFactory.BoardOrientation.HORIZONTAL, this::getTile);
+ tileStorage = new ArrayTileStorage(board.size());
+ testTouch(705, 1103, 3, 7, 653, 1193, 34);
+ testTouch(707, 1092, 3, 6, 653, 1002, 33);
+ testTouch(715, 1096, 4, 7, 818, 1097, 43);
+ }
+
+ private void testTouch(int tx, int ty, int x, int y, int cx, int cy, int g)
+ {
+ String title = String.format("[%d;%d] -> [%d;%d] (%d;%d) %d : ", tx, ty, x, y, cx, cy, g);
+ board.toBoard(tx, ty, v);
+ Tile t = board.getTile((int)v.x, (int)v.y);
+ int k = board.genKey(t.x, t.y);
+ check((t.x == x), title, "x", t.x);
+ check((t.y == y), title, "y", t.y);
+ check(((int)t.cx == cx), title, "cx", (int)t.cx);
+ check(((int)t.cy == cy), title, "cy", (int)t.cy);
+ check((g == k), title, "Key", g);
+ }
+
+ private Tile getTile(int x, int y, boolean isOnMap)
+ {
+ if (isOnMap)
+ return tileStorage.getTile(x, y, board::genKey, this::buildTile);
+ return Tile.OffMap;
+ }
+
+ private Tile buildTile(int x, int y)
+ {
+ final Vector2 v = new Vector2();
+ board.centerOf(x, y, v);
+ int k = board.genKey(x, y);
+ return new Hex(x, y, v.x, v.y, k, Terrain.get(k));
+ }
+
+ private void check(boolean condition, String title, String what, int got)
+ {
+ if (!condition) {
+ System.err.println( " :: " + title + "failed on : " + what + " got " + got);
+ }
+ }
+}