From 555d604d1e67ed6eac8c09a8b99c59d342660bb7 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 13 Mar 2022 14:48:30 +0300 Subject: feat: implement correct getAttachments for board --- src/Board/Board.test.ts | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'src/Board/Board.test.ts') diff --git a/src/Board/Board.test.ts b/src/Board/Board.test.ts index 5023f0b..4bd6182 100644 --- a/src/Board/Board.test.ts +++ b/src/Board/Board.test.ts @@ -17,20 +17,20 @@ describe('Board', () => { }); describe('getAttachments', () => { - it('Should correctly determine legal moves for 1-tile board', () => { + 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 legalMoves = board.getAttachments(tile); + const attachments = board.getAttachments(tile); - assert.strictEqual(legalMoves.length, 4); - assert.deepStrictEqual(legalMoves[0], { side: 0, orientation: 1, attachTo, tile }); - assert.deepStrictEqual(legalMoves[1], { side: 0, orientation: 3, attachTo, tile }); - assert.deepStrictEqual(legalMoves[2], { side: 2, orientation: 0, attachTo, tile }); - assert.deepStrictEqual(legalMoves[3], { side: 2, orientation: 2, attachTo, 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.skip('Have a look at my nice attachments manually bro', () => { + it('Should correctly return legal attachments for complex board', () => { const board = new Board(); board.attach({ @@ -50,7 +50,19 @@ describe('Board', () => { const tile = new Tile(Grass, [Town, Grass, Grass, Grass]); const attachments = board.getAttachments(tile); - attachments.forEach(attachment => board.previewAttachment(attachment)); + + // 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] }); }); }); -- cgit v1.2.3