|
| 1 | +import { |
| 2 | + DIRECTIONS, |
| 3 | + isOnTiles, |
| 4 | + isSameTile, |
| 5 | + move, |
| 6 | + rotate, |
| 7 | + Tile |
| 8 | +} from "../src/navigation"; |
| 9 | + |
| 10 | +const zeroTile: Tile = { x: 0, y: 0 }; |
| 11 | + |
| 12 | +describe("move", () => { |
| 13 | + it("should move a tile north", () => { |
| 14 | + const moved: Tile = { x: 0, y: -1 }; |
| 15 | + expect(move(zeroTile, DIRECTIONS.North)).toEqual(moved); |
| 16 | + }); |
| 17 | + |
| 18 | + it("should move a tile east", () => { |
| 19 | + const moved: Tile = { x: 1, y: 0 }; |
| 20 | + expect(move(zeroTile, DIRECTIONS.East)).toEqual(moved); |
| 21 | + }); |
| 22 | + |
| 23 | + it("should move a tile south", () => { |
| 24 | + const moved: Tile = { x: 0, y: 1 }; |
| 25 | + expect(move(zeroTile, DIRECTIONS.South)).toEqual(moved); |
| 26 | + }); |
| 27 | + |
| 28 | + it("should move a tile west", () => { |
| 29 | + const moved: Tile = { x: -1, y: 0 }; |
| 30 | + expect(move(zeroTile, DIRECTIONS.West)).toEqual(moved); |
| 31 | + }); |
| 32 | +}); |
| 33 | + |
| 34 | +describe("rotate", () => { |
| 35 | + it("should rotate from north to east", () => { |
| 36 | + expect(rotate(DIRECTIONS.North)).toBe(DIRECTIONS.East); |
| 37 | + }); |
| 38 | + |
| 39 | + it("should rotate from west to north", () => { |
| 40 | + expect(rotate(DIRECTIONS.West)).toBe(DIRECTIONS.North); |
| 41 | + }); |
| 42 | +}); |
| 43 | + |
| 44 | +describe("is the same tile", () => { |
| 45 | + it("should be the same tile", () => { |
| 46 | + expect(isSameTile(zeroTile, zeroTile)).toBeTruthy(); |
| 47 | + expect(isSameTile(zeroTile, { ...zeroTile })).toBeTruthy(); |
| 48 | + }); |
| 49 | + |
| 50 | + it("should NOT be the same tile", () => { |
| 51 | + expect(isSameTile(zeroTile, { x: 1, y: 0 })).toBeFalsy(); |
| 52 | + expect(isSameTile(zeroTile, { x: 0, y: 1 })).toBeFalsy(); |
| 53 | + }); |
| 54 | +}); |
| 55 | + |
| 56 | +describe("is on tiles", () => { |
| 57 | + it("should be on tiles", () => { |
| 58 | + expect(isOnTiles(zeroTile, [{ ...zeroTile }, { x: 1, y: 1 }])).toBeTruthy(); |
| 59 | + }); |
| 60 | + |
| 61 | + it("should NOT be on tiles", () => { |
| 62 | + expect(isOnTiles(zeroTile, [{ x: 1, y: 1 }, { x: 2, y: 2 }])).toBeFalsy(); |
| 63 | + }); |
| 64 | +}); |
0 commit comments