-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.test.ts
99 lines (87 loc) · 3.05 KB
/
utils.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { assertEquals } from 'deps'
import { Board, eastColumn, northRow, southRow, westColumn } from './utilts.ts'
const boardInput = `
..#
.#.
#..
`
Deno.test("Utils - Board adjacent coordinates", () => {
const board = new Board(boardInput.trim())
assertEquals(board.adjacentCoordinates({ y: 1, x: 1 }), [
{ y: 0, x: 0 },
{ y: 0, x: 1 },
{ y: 0, x: 2 },
{ y: 1, x: 2 },
{ y: 2, x: 2 },
{ y: 2, x: 1 },
{ y: 2, x: 0 },
{ y: 1, x: 0 },
])
})
Deno.test("Utils - Board adjacent tiles", () => {
const board = new Board(boardInput.trim())
assertEquals(board.adjacentTiles({ y: 1, x: 1 }), [
".", ".", "#", ".", ".", ".", "#", "."
])
})
Deno.test("Utils - Board adjacent tiles and coordinates", () => {
const board = new Board(boardInput.trim())
assertEquals(board.adjacentTilesWithCoordinates({ y: 1, x: 1 }), [
{ y: 0, x: 0, tile: "." },
{ y: 0, x: 1, tile: "." },
{ y: 0, x: 2, tile: "#" },
{ y: 1, x: 2, tile: "." },
{ y: 2, x: 2, tile: "." },
{ y: 2, x: 1, tile: "." },
{ y: 2, x: 0, tile: "#" },
{ y: 1, x: 0, tile: "." },
])
})
Deno.test("Utils - Board adjacent tiles on north row", () => {
const board = new Board(boardInput.trim())
assertEquals(board.adjacentTiles({ y: 1, x: 1 }, northRow), [".", ".", "#"])
})
Deno.test("Utils - Board adjacent tiles on east column", () => {
const board = new Board(boardInput.trim())
assertEquals(board.adjacentTiles({ y: 1, x: 1 }, eastColumn), ["#", ".", "."])
})
Deno.test("Utils - Board adjacent tiles on south row", () => {
const board = new Board(boardInput.trim())
assertEquals(board.adjacentTiles({ y: 1, x: 1 }, southRow), ["#", ".", "."])
})
Deno.test("Utils - Board adjacent tiles on west column", () => {
const board = new Board(boardInput.trim())
assertEquals(board.adjacentTiles({ y: 1, x: 1 }, westColumn), [".", ".", "#"])
})
Deno.test("Utils - Board adjacent tiles and coordinates on north row", () => {
const board = new Board(boardInput.trim())
assertEquals(board.adjacentTilesWithCoordinates({ y: 1, x: 1 }, northRow), [
{ y: 0, x: 0, tile: "." },
{ y: 0, x: 1, tile: "." },
{ y: 0, x: 2, tile: "#" },
])
})
Deno.test("Utils - Board adjacent tiles and coordinates on east column", () => {
const board = new Board(boardInput.trim())
assertEquals(board.adjacentTilesWithCoordinates({ y: 1, x: 1 }, eastColumn), [
{ y: 0, x: 2, tile: "#" },
{ y: 1, x: 2, tile: "." },
{ y: 2, x: 2, tile: "." },
])
})
Deno.test("Utils - Board adjacent tiles and coordinates on south row", () => {
const board = new Board(boardInput.trim())
assertEquals(board.adjacentTilesWithCoordinates({ y: 1, x: 1 }, southRow), [
{ y: 2, x: 0, tile: "#" },
{ y: 2, x: 1, tile: "." },
{ y: 2, x: 2, tile: "." },
])
})
Deno.test("Utils - Board adjacent tiles and coordinates on west column", () => {
const board = new Board(boardInput.trim())
assertEquals(board.adjacentTilesWithCoordinates({ y: 1, x: 1 }, westColumn), [
{ y: 0, x: 0, tile: "." },
{ y: 1, x: 0, tile: "." },
{ y: 2, x: 0, tile: "#" },
])
})