diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-03-14 20:52:08 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-03-14 20:52:08 +0300 |
commit | d64c44c432ccb5574909edd77b8b882e8543ef1b (patch) | |
tree | feb4035bf7301f9b627634695b7650027e5eecc4 /src/Tile/Tile.test.ts | |
parent | 9cf681ff497150e4d56b13bde4f57f4f0e9633c0 (diff) | |
download | carcassonne-engine-ts-d64c44c432ccb5574909edd77b8b882e8543ef1b.tar.gz |
refactor!: change internal edge representation
Diffstat (limited to 'src/Tile/Tile.test.ts')
-rw-r--r-- | src/Tile/Tile.test.ts | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/Tile/Tile.test.ts b/src/Tile/Tile.test.ts new file mode 100644 index 0000000..33bb16f --- /dev/null +++ b/src/Tile/Tile.test.ts @@ -0,0 +1,47 @@ +import assert from 'assert'; +import Tile from './Tile'; +import { Direction } from './Tile'; + +const { North, East, South, West } = Direction; + +describe('Tile', () => { + describe('getEdge', () => { + it('Should get North, East, South and West edges correctly', () => { + const tile = new Tile('F', 'RCFR'); + + assert.strictEqual(tile.edges[North], 'R'); + assert.strictEqual(tile.edges[East], 'C'); + assert.strictEqual(tile.edges[South], 'F'); + assert.strictEqual(tile.edges[West], 'R'); + }); + + it('Should respect tile orientation', () => { + const tile = new Tile('F', 'RCFR'); + tile.orientation = 5; + + assert.strictEqual(tile.edges, 'RRCF') + }); + + it('Should work with negative orientation', () => { + const tile = new Tile('F', 'RCFR'); + tile.orientation = -7 + + assert.strictEqual(tile.edges, 'RRCF') + }); + }); + + describe('getAttachments', () => { + it('Should correclty list legal attachments', () => { + const attachTo = new Tile('C', 'RCCR') + const tile = new Tile('R', 'FRRF') + + const attachments = attachTo.getAttachments(tile); + assert.strictEqual(attachments.length, 4); + assert.deepStrictEqual(attachments[0], { edge: 0, orientation: 1, tile, attachTo }); + assert.deepStrictEqual(attachments[1], { edge: 0, orientation: 0, tile, attachTo }); + assert.deepStrictEqual(attachments[2], { edge: 3, orientation: 0, tile, attachTo }); + assert.deepStrictEqual(attachments[3], { edge: 3, orientation: 3, tile, attachTo }); + }); + }); +}); + |