import _ from 'lodash'; import assert from 'assert'; import Tile, { Feature, Direction } from '../Tile/Tile'; import TileOnBoard from '../Tile/TileOnBoard'; import Board from './Board'; const { Road, Town, Grass } = Feature; const { North, East } = Direction; describe('Board', () => { describe('constructor', () => { it('Should initialize empty board with a starting tile', () => { const board = new Board(); assert.strictEqual(board.tiles.length, 1); assert.deepStrictEqual(board.tiles[0], new TileOnBoard(Road, [Town, Road, Grass, Road])); }); }); describe('getAttachments', () => { it('Should correctly determine legal attachments for 1-tile board', () => { const board = new Board(); const attachTo = board.tiles[0]; const tile = new Tile(Town, [Grass, Town, Grass, Town]); const attachments = board.getAttachments(tile); assert.strictEqual(attachments.length, 4); assert.deepStrictEqual(attachments[0], { side: 0, orientation: 1, attachTo, tile }); assert.deepStrictEqual(attachments[1], { side: 0, orientation: 3, attachTo, tile }); assert.deepStrictEqual(attachments[2], { side: 2, orientation: 0, attachTo, tile }); assert.deepStrictEqual(attachments[3], { side: 2, orientation: 2, attachTo, tile }); }); it('Should correctly return legal attachments for complex board', () => { const board = new Board(); board.attach({ tile: new Tile(Town, [Town, Grass, Town, Grass]), attachTo: board.tiles[0], orientation: 0, side: North, }); board.attach({ tile: new Tile(Town, [Road, Town, Town, Road]), attachTo: board.tiles[0], orientation: 0, side: East, }); const tile = new Tile(Grass, [Town, Grass, Grass, Grass]); const attachments = board.getAttachments(tile); // attachments.forEach(attachment => board.previewAttachment(attachment)); assert.strictEqual(attachments.length, 9); assert.deepStrictEqual(attachments[0], { side: 2, orientation: 1, tile, attachTo: board.tiles[0] }); assert.deepStrictEqual(attachments[1], { side: 2, orientation: 2, tile, attachTo: board.tiles[0] }); assert.deepStrictEqual(attachments[2], { side: 2, orientation: 3, tile, attachTo: board.tiles[0] }); assert.deepStrictEqual(attachments[3], { side: 0, orientation: 2, tile, attachTo: board.tiles[1] }); assert.deepStrictEqual(attachments[4], { side: 3, orientation: 0, tile, attachTo: board.tiles[1] }); assert.deepStrictEqual(attachments[5], { side: 3, orientation: 2, tile, attachTo: board.tiles[1] }); assert.deepStrictEqual(attachments[6], { side: 3, orientation: 3, tile, attachTo: board.tiles[1] }); assert.deepStrictEqual(attachments[7], { side: 1, orientation: 3, tile, attachTo: board.tiles[2] }); assert.deepStrictEqual(attachments[8], { side: 2, orientation: 0, tile, attachTo: board.tiles[2] }); }); }); describe('attach', () => { it('Should push new tile to the list and assign correct coordinates', () => { const board = new Board(); const attachment = { tile: new Tile(Town, [Grass, Town, Grass, Town]), attachTo: board.tiles[0], orientation: 0, side: North, }; const expectedTileOnBoard = new TileOnBoard( Town, [Grass, Town, Grass, Town], false, { x: 0, y: 1 }, 0 ); board.attach(attachment); assert.strictEqual(board.tiles.length, 2); assert.deepStrictEqual(board.tiles[1], expectedTileOnBoard); }); }); });