aboutsummaryrefslogtreecommitdiff
path: root/src/Tile/TileOnBoard.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/Tile/TileOnBoard.test.ts')
-rw-r--r--src/Tile/TileOnBoard.test.ts57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/Tile/TileOnBoard.test.ts b/src/Tile/TileOnBoard.test.ts
new file mode 100644
index 0000000..7448435
--- /dev/null
+++ b/src/Tile/TileOnBoard.test.ts
@@ -0,0 +1,57 @@
+import assert from 'assert';
+import TileOnBoard from './TileOnBoard';
+import { Direction, Feature } from './Tile';
+
+const { North, East, South, West } = Direction;
+const { Road, Town, Empty, River } = Feature;
+
+describe('TileOnBoard', () => {
+ describe('getSide', () => {
+ it('Should get North, East, South and West sides correctly', () => {
+ const tile = new TileOnBoard(Empty, [Road, Town, Empty, River]);
+
+ assert.strictEqual(tile.getSide(North), Road);
+ assert.strictEqual(tile.getSide(East), Town);
+ assert.strictEqual(tile.getSide(South), Empty);
+ assert.strictEqual(tile.getSide(West), River);
+ });
+
+ it('Should respect tile orientation', () => {
+ const tile = new TileOnBoard(Empty, [Road, Town, Empty, River]);
+ tile.rotate(5);
+
+ assert.strictEqual(tile.getSide(North), River);
+ assert.strictEqual(tile.getSide(East), Road);
+ assert.strictEqual(tile.getSide(South), Town);
+ assert.strictEqual(tile.getSide(West), Empty);
+ });
+
+ it('Should work with negative orientation', () => {
+ const tile = new TileOnBoard(Empty, [Road, Town, Empty, River]);
+ tile.rotate(-7);
+
+ assert.strictEqual(tile.getSide(North), River);
+ assert.strictEqual(tile.getSide(East), Road);
+ assert.strictEqual(tile.getSide(South), Town);
+ assert.strictEqual(tile.getSide(West), Empty);
+ });
+ });
+
+ describe('getAttachments', () => {
+ it('Should correclty list legal attachments', () => {
+ const attachTo = new TileOnBoard(Town, [Road, Town, Town, Road])
+ const tile = new TileOnBoard(Road, [Empty, Road, Road, Empty])
+
+ tile.print();
+ attachTo.print();
+
+ const attachments = attachTo.getAttachments(tile);
+ assert.strictEqual(attachments.length, 4);
+ assert.deepStrictEqual(attachments[0], { side: 0, rotation: 0, tile, attachTo });
+ assert.deepStrictEqual(attachments[1], { side: 0, rotation: 1, tile, attachTo });
+ assert.deepStrictEqual(attachments[2], { side: 3, rotation: 0, tile, attachTo });
+ assert.deepStrictEqual(attachments[3], { side: 3, rotation: 3, tile, attachTo });
+ });
+ });
+});
+