aboutsummaryrefslogtreecommitdiff
path: root/src/Tile/Tile.test.ts
blob: 33bb16f15a3061a77057bdabdc8f10ece05df4de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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 });
    });
  });
});