aboutsummaryrefslogtreecommitdiff
path: root/src/Cell/Cell.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/Cell/Cell.test.ts')
-rw-r--r--src/Cell/Cell.test.ts51
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);
+ });
+ });
+});
+