import assert from 'assert'; import Tile, { Direction, Feature } from './Tile'; const { North, East, South, West } = Direction; const { Road, Town, Empty, River } = Feature; describe('Tile', () => { describe('getSide', () => { it('Should get North, East, South and West sides correctly', () => { const cell = new Tile(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 Tile(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 Tile(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('getAttachments', () => { it('Should correclty list legal attachments', () => { const attachTo = new Tile(Town, [Road, Town, Town, Road]) const cell = new Tile(Road, [Empty, Road, Road, Empty]) cell.print(); attachTo.print(); const attachments = attachTo.getAttachments(cell); assert.strictEqual(attachments.length, 4); assert.deepStrictEqual(attachments[0], { side: 0, rotation: 0, cell, attachTo }); assert.deepStrictEqual(attachments[1], { side: 0, rotation: 1, cell, attachTo }); assert.deepStrictEqual(attachments[2], { side: 3, rotation: 0, cell, attachTo }); assert.deepStrictEqual(attachments[3], { side: 3, rotation: 3, cell, attachTo }); }); }); });