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
|
import assert from 'assert';
import Cell, { Direction, Item } from './Cell';
const { North, East, South, West } = Direction;
const { Road, Town, Empty, River, Church } = Item;
describe('Cell', () => {
describe('getSide', () => {
it('Should get North, East, South and West sides correctly', () => {
const cell = new Cell(Empty, [Road, Town, Empty, River]);
assert.strictEqual(cell.getSide(North), Road);
assert.strictEqual(cell.getSide(East), Town);
assert.strictEqual(cell.getSide(South), Empty);
assert.strictEqual(cell.getSide(West), River);
});
it('Should respect cell orientation', () => {
const cell = new Cell(Empty, [Road, Town, Empty, River]);
cell.rotate(5);
assert.strictEqual(cell.getSide(North), River);
assert.strictEqual(cell.getSide(East), Road);
assert.strictEqual(cell.getSide(South), Town);
assert.strictEqual(cell.getSide(West), Empty);
});
it('Should work with negative orientation', () => {
const cell = new Cell(Empty, [Road, Town, Empty, River]);
cell.rotate(-7);
assert.strictEqual(cell.getSide(North), River);
assert.strictEqual(cell.getSide(East), Road);
assert.strictEqual(cell.getSide(South), Town);
assert.strictEqual(cell.getSide(West), Empty);
});
});
describe('isAttachable', () => {
it('Should correctly test if cell is attachable', () => {
const cell = new Cell(Church, [Road, Town, Empty, River]);
const other = new Cell(Empty, [Road, Road, Town, Road], 3);
assert.strictEqual(cell.isAttachable(other, North), true);
assert.strictEqual(cell.isAttachable(other, East), true);
assert.strictEqual(cell.isAttachable(other, South), false);
assert.strictEqual(cell.isAttachable(other, West), false);
});
});
});
|