From c8341b265e69d5a08f0110558297a7a36b8a5394 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Fri, 11 Mar 2022 15:14:36 +0300 Subject: chore: add tests for Cell --- src/Cell/Cell.test.ts | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/Cell/Cell.test.ts (limited to 'src/Cell/Cell.test.ts') diff --git a/src/Cell/Cell.test.ts b/src/Cell/Cell.test.ts new file mode 100644 index 0000000..56f227f --- /dev/null +++ b/src/Cell/Cell.test.ts @@ -0,0 +1,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); + }); + }); +}); + -- cgit v1.2.3