aboutsummaryrefslogtreecommitdiff
path: root/src/Tile/Tile.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/Tile/Tile.test.ts')
-rw-r--r--src/Tile/Tile.test.ts47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/Tile/Tile.test.ts b/src/Tile/Tile.test.ts
new file mode 100644
index 0000000..33bb16f
--- /dev/null
+++ b/src/Tile/Tile.test.ts
@@ -0,0 +1,47 @@
+import assert from 'assert';
+import Tile from './Tile';
+import { Direction } from './Tile';
+
+const { North, East, South, West } = Direction;
+
+describe('Tile', () => {
+ describe('getEdge', () => {
+ it('Should get North, East, South and West edges correctly', () => {
+ const tile = new Tile('F', 'RCFR');
+
+ assert.strictEqual(tile.edges[North], 'R');
+ assert.strictEqual(tile.edges[East], 'C');
+ assert.strictEqual(tile.edges[South], 'F');
+ assert.strictEqual(tile.edges[West], 'R');
+ });
+
+ it('Should respect tile orientation', () => {
+ const tile = new Tile('F', 'RCFR');
+ tile.orientation = 5;
+
+ assert.strictEqual(tile.edges, 'RRCF')
+ });
+
+ it('Should work with negative orientation', () => {
+ const tile = new Tile('F', 'RCFR');
+ tile.orientation = -7
+
+ assert.strictEqual(tile.edges, 'RRCF')
+ });
+ });
+
+ describe('getAttachments', () => {
+ it('Should correclty list legal attachments', () => {
+ const attachTo = new Tile('C', 'RCCR')
+ const tile = new Tile('R', 'FRRF')
+
+ const attachments = attachTo.getAttachments(tile);
+ assert.strictEqual(attachments.length, 4);
+ assert.deepStrictEqual(attachments[0], { edge: 0, orientation: 1, tile, attachTo });
+ assert.deepStrictEqual(attachments[1], { edge: 0, orientation: 0, tile, attachTo });
+ assert.deepStrictEqual(attachments[2], { edge: 3, orientation: 0, tile, attachTo });
+ assert.deepStrictEqual(attachments[3], { edge: 3, orientation: 3, tile, attachTo });
+ });
+ });
+});
+