diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-03-11 15:14:36 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-03-11 15:14:36 +0300 |
commit | c8341b265e69d5a08f0110558297a7a36b8a5394 (patch) | |
tree | 6a7a2ac078caa8cfa96417d27d334fef35ba90c6 /src/Cell/Cell.test.ts | |
parent | 03623a7e835dde461c44acc77fe670574dfe2c4b (diff) | |
download | carcassonne-engine-ts-c8341b265e69d5a08f0110558297a7a36b8a5394.tar.gz |
chore: add tests for Cell
Diffstat (limited to 'src/Cell/Cell.test.ts')
-rw-r--r-- | src/Cell/Cell.test.ts | 51 |
1 files changed, 51 insertions, 0 deletions
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); + }); + }); +}); + |