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
48
49
50
51
52
53
54
|
import assert from 'assert';
import TileOnBoard from './TileOnBoard';
import { Direction, Feature } from './Tile';
const { North, East, South, West } = Direction;
const { Road, Town, Grass, River } = Feature;
describe('TileOnBoard', () => {
describe('getSide', () => {
it('Should get North, East, South and West sides correctly', () => {
const tile = new TileOnBoard(Grass, [Road, Town, Grass, River]);
assert.strictEqual(tile.getSide(North), Road);
assert.strictEqual(tile.getSide(East), Town);
assert.strictEqual(tile.getSide(South), Grass);
assert.strictEqual(tile.getSide(West), River);
});
it('Should respect tile orientation', () => {
const tile = new TileOnBoard(Grass, [Road, Town, Grass, 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), Grass);
});
it('Should work with negative orientation', () => {
const tile = new TileOnBoard(Grass, [Road, Town, Grass, 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), Grass);
});
});
describe('getAttachments', () => {
it('Should correclty list legal attachments', () => {
const attachTo = new TileOnBoard(Town, [Road, Town, Town, Road])
const tile = new TileOnBoard(Road, [Grass, Road, Road, Grass])
const attachments = attachTo.getAttachments(tile);
assert.strictEqual(attachments.length, 4);
assert.deepStrictEqual(attachments[0], { side: 0, orientation: 0, tile, attachTo });
assert.deepStrictEqual(attachments[1], { side: 0, orientation: 1, tile, attachTo });
assert.deepStrictEqual(attachments[2], { side: 3, orientation: 0, tile, attachTo });
assert.deepStrictEqual(attachments[3], { side: 3, orientation: 3, tile, attachTo });
});
});
});
|