@inglorious/utils 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +10 -11
  2. package/package.json +4 -4
  3. package/src/algorithms/decision-tree.js +24 -0
  4. package/src/algorithms/decision-tree.test.js +153 -0
  5. package/src/algorithms/path-finding.js +150 -0
  6. package/src/algorithms/path-finding.test.js +151 -0
  7. package/src/algorithms/types.d.ts +28 -0
  8. package/src/data-structures/array.js +93 -0
  9. package/src/data-structures/array.test.js +185 -0
  10. package/src/data-structures/board.js +159 -0
  11. package/src/data-structures/board.test.js +242 -0
  12. package/src/data-structures/boolean.js +9 -0
  13. package/src/data-structures/heap.js +164 -0
  14. package/src/data-structures/heap.test.js +103 -0
  15. package/src/data-structures/object.js +138 -0
  16. package/src/data-structures/object.test.js +218 -0
  17. package/src/data-structures/objects.js +66 -0
  18. package/src/data-structures/objects.test.js +99 -0
  19. package/src/data-structures/set.js +9 -0
  20. package/src/data-structures/set.test.js +15 -0
  21. package/src/data-structures/tree.js +36 -0
  22. package/src/data-structures/tree.test.js +33 -0
  23. package/src/data-structures/types.d.ts +4 -0
  24. package/src/functions/functions.js +19 -0
  25. package/src/functions/functions.test.js +23 -0
  26. package/src/math/geometry/circle.js +69 -0
  27. package/src/math/geometry/circle.test.js +97 -0
  28. package/src/math/geometry/hitmask.js +70 -0
  29. package/src/math/geometry/hitmask.test.js +155 -0
  30. package/src/math/geometry/line.js +34 -0
  31. package/src/math/geometry/line.test.js +49 -0
  32. package/src/math/geometry/point.js +78 -0
  33. package/src/math/geometry/point.test.js +81 -0
  34. package/src/math/geometry/rectangle.js +76 -0
  35. package/src/math/geometry/rectangle.test.js +42 -0
  36. package/src/math/geometry/segment.js +72 -0
  37. package/src/math/geometry/segment.test.js +183 -0
  38. package/src/math/geometry/triangle.js +15 -0
  39. package/src/math/geometry/triangle.test.js +11 -0
  40. package/src/math/geometry/types.d.ts +23 -0
  41. package/src/math/linear-algebra/2d.js +28 -0
  42. package/src/math/linear-algebra/2d.test.js +17 -0
  43. package/src/math/linear-algebra/quaternion.js +22 -0
  44. package/src/math/linear-algebra/quaternion.test.js +25 -0
  45. package/src/math/linear-algebra/quaternions.js +20 -0
  46. package/src/math/linear-algebra/quaternions.test.js +29 -0
  47. package/src/math/linear-algebra/types.d.ts +4 -0
  48. package/src/math/linear-algebra/vector.js +337 -0
  49. package/src/math/linear-algebra/vector.test.js +265 -0
  50. package/src/math/linear-algebra/vectors.js +122 -0
  51. package/src/math/linear-algebra/vectors.test.js +65 -0
  52. package/src/math/linear-interpolation.js +9 -0
  53. package/src/math/numbers.js +90 -0
  54. package/src/math/numbers.test.js +137 -0
  55. package/src/math/rng.js +44 -0
  56. package/src/math/rng.test.js +39 -0
  57. package/src/math/statistics.js +43 -0
  58. package/src/math/statistics.test.js +47 -0
  59. package/src/math/trigonometry.js +89 -0
  60. package/src/math/trigonometry.test.js +52 -0
  61. package/src/physics/acceleration.js +56 -0
  62. package/src/physics/friction.js +24 -0
  63. package/src/physics/friction.test.js +42 -0
  64. package/src/physics/gravity.js +69 -0
  65. package/src/physics/gravity.test.js +77 -0
  66. package/src/physics/jump.js +31 -0
  67. package/src/physics/velocity.js +32 -0
@@ -0,0 +1,185 @@
1
+ import { expect, test } from "vitest"
2
+
3
+ import { contains, ensureArray, max, min, pop, push, remove } from "./array.js"
4
+
5
+ test("it should check if an array contains a value", () => {
6
+ const arr = [3, 2, 6, 1, 7, 4, 5]
7
+ const item = 1
8
+ const expectedResult = true
9
+
10
+ expect(contains(arr, item)).toBe(expectedResult)
11
+ })
12
+
13
+ test("it should check if an array contains an object", () => {
14
+ const arr = [
15
+ { value: 3 },
16
+ { value: 2 },
17
+ { value: 6 },
18
+ { value: 1 },
19
+ { value: 7 },
20
+ { value: 4 },
21
+ { value: 5 },
22
+ ]
23
+ const item = arr[3]
24
+ const expectedResult = true
25
+
26
+ expect(contains(arr, item)).toBe(expectedResult)
27
+ })
28
+
29
+ test("it should return the same array if the value is already an array", () => {
30
+ const arr = [1, "two", { three: 3 }]
31
+
32
+ expect(ensureArray(arr)).toBe(arr)
33
+ })
34
+
35
+ test("it should wrap the value in an array if it is not an array", () => {
36
+ const str = "hello"
37
+
38
+ expect(ensureArray(str)).toStrictEqual([str])
39
+ })
40
+
41
+ test("it should find the maximum value of an array", () => {
42
+ const arr = [3, 2, 6, 1, 7, 4, 5]
43
+ const expectedResult = 7
44
+
45
+ expect(max(arr)).toBe(expectedResult)
46
+ })
47
+
48
+ test("it should find the maximum value in an array of objects", () => {
49
+ const arr = [
50
+ { value: 3 },
51
+ { value: 2 },
52
+ { value: 6 },
53
+ { value: 1 },
54
+ { value: 7 },
55
+ { value: 4 },
56
+ { value: 5 },
57
+ ]
58
+ const comparator = (a, b) => b.value - a.value
59
+ const expectedResult = { value: 7 }
60
+
61
+ expect(max(arr, comparator)).toStrictEqual(expectedResult)
62
+ })
63
+
64
+ test("it should find the minimum value of an array", () => {
65
+ const arr = [3, 2, 6, 1, 7, 4, 5]
66
+ const expectedResult = 1
67
+
68
+ expect(min(arr)).toBe(expectedResult)
69
+ })
70
+
71
+ test("it should find the minimum value in an array of objects", () => {
72
+ const arr = [
73
+ { value: 3 },
74
+ { value: 2 },
75
+ { value: 6 },
76
+ { value: 1 },
77
+ { value: 7 },
78
+ { value: 4 },
79
+ { value: 5 },
80
+ ]
81
+ const comparator = (a, b) => b.value - a.value
82
+ const expectedResult = { value: 1 }
83
+
84
+ expect(min(arr, comparator)).toStrictEqual(expectedResult)
85
+ })
86
+
87
+ test("it should remove the minimum value from an array", () => {
88
+ const arr = [3, 2, 6, 1, 7, 4, 5]
89
+ const expectedResult = [3, 2, 6, 7, 4, 5]
90
+
91
+ expect(pop(arr)).toStrictEqual(expectedResult)
92
+ })
93
+
94
+ test("it should remove the minimum object from an array", () => {
95
+ const arr = [
96
+ { value: 3 },
97
+ { value: 2 },
98
+ { value: 6 },
99
+ { value: 1 },
100
+ { value: 7 },
101
+ { value: 4 },
102
+ { value: 5 },
103
+ ]
104
+ const comparator = (a, b) => b.value - a.value
105
+ const expectedResult = [
106
+ { value: 3 },
107
+ { value: 2 },
108
+ { value: 6 },
109
+ { value: 7 },
110
+ { value: 4 },
111
+ { value: 5 },
112
+ ]
113
+
114
+ expect(pop(arr, comparator)).toStrictEqual(expectedResult)
115
+ })
116
+
117
+ test("it should remove the maximum value from an array", () => {
118
+ const arr = [3, 2, 6, 1, 7, 4, 5]
119
+ const comparator = (a, b) => a - b
120
+ const expectedResult = [3, 2, 6, 1, 4, 5]
121
+
122
+ expect(pop(arr, comparator)).toStrictEqual(expectedResult)
123
+ })
124
+
125
+ test("it should remove the maximum object from an array", () => {
126
+ const arr = [
127
+ { value: 3 },
128
+ { value: 2 },
129
+ { value: 6 },
130
+ { value: 1 },
131
+ { value: 7 },
132
+ { value: 4 },
133
+ { value: 5 },
134
+ ]
135
+ const comparator = (a, b) => a.value - b.value
136
+ const expectedResult = [
137
+ { value: 3 },
138
+ { value: 2 },
139
+ { value: 6 },
140
+ { value: 1 },
141
+ { value: 4 },
142
+ { value: 5 },
143
+ ]
144
+
145
+ expect(pop(arr, comparator)).toStrictEqual(expectedResult)
146
+ })
147
+
148
+ test("it should add a value at the end of the array", () => {
149
+ const arr = [3, 2, 6, 1, 7, 4]
150
+ const item = 5
151
+ const expectedResult = [3, 2, 6, 1, 7, 4, 5]
152
+
153
+ expect(push(arr, item)).toStrictEqual(expectedResult)
154
+ })
155
+
156
+ test("it should remove a primitive value from an array", () => {
157
+ const arr = [3, 2, 6, 1, 7, 4, 5]
158
+ const item = 1
159
+ const expectedResult = [3, 2, 6, 7, 4, 5]
160
+
161
+ expect(remove(arr, item)).toStrictEqual(expectedResult)
162
+ })
163
+
164
+ test("it should remove an object from an array", () => {
165
+ const arr = [
166
+ { value: 3 },
167
+ { value: 2 },
168
+ { value: 6 },
169
+ { value: 1 },
170
+ { value: 7 },
171
+ { value: 4 },
172
+ { value: 5 },
173
+ ]
174
+ const item = arr[3]
175
+ const expectedResult = [
176
+ { value: 3 },
177
+ { value: 2 },
178
+ { value: 6 },
179
+ { value: 7 },
180
+ { value: 4 },
181
+ { value: 5 },
182
+ ]
183
+
184
+ expect(remove(arr, item)).toStrictEqual(expectedResult)
185
+ })
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Default filler function for board cells.
3
+ * @returns {null} Default value for a cell.
4
+ */
5
+ const DEFAULT_FILLER = () => null
6
+
7
+ /**
8
+ * Default function to convert a cell to a string.
9
+ * @param {*} cell - The cell value.
10
+ * @returns {string} String representation of the cell.
11
+ */
12
+ const DEFAULT_CELL_TO_STRING = (cell) => `${cell}`
13
+
14
+ const FIRST_ROW = 0
15
+ const FIRST_COLUMN = 0
16
+ const LAST_ROW_OFFSET = 1
17
+ const LAST_COLUMN_OFFSET = 1
18
+ const MOVE_DOWN = 1
19
+ const MOVE_LEFT = -1
20
+ const MOVE_RIGHT = 1
21
+ const MOVE_UP = -1
22
+
23
+ /**
24
+ * Calculates the index in a one-dimensional array for given row and column.
25
+ * @param {number} row - The row index.
26
+ * @param {number} column - The column index.
27
+ * @param {number} columns - The total number of columns.
28
+ * @returns {number} The calculated index.
29
+ */
30
+ function getIndex(row, column, columns) {
31
+ return row * columns + column
32
+ }
33
+
34
+ /**
35
+ * Creates a 1D board with the specified dimensions and fills it using the provided filler function.
36
+ * @param {[number, number]} dimensions - Array containing the number of rows and columns.
37
+ * @param {Function} [filler=DEFAULT_FILLER] - Function to fill each cell of the board.
38
+ * @returns {any[]} The created board.
39
+ */
40
+ export function createBoard([rows, columns], filler = DEFAULT_FILLER) {
41
+ return new Array(rows * columns).fill(null).map((_, index) => {
42
+ const row = Math.floor(index / columns)
43
+ const column = index % columns
44
+ return filler(row, column)
45
+ })
46
+ }
47
+
48
+ /**
49
+ * Moves the given coordinates one step down.
50
+ * @param {[number, number]} coords - The current coordinates [row, column].
51
+ * @param {[number]} size - Array containing the number of rows.
52
+ * @returns {[number, number]} The new coordinates after moving down.
53
+ * @throws {Error} If the movement goes out of bounds.
54
+ */
55
+ export function down([i, j], [rows]) {
56
+ if (i === rows - LAST_ROW_OFFSET) {
57
+ throw new Error()
58
+ }
59
+ return [i + MOVE_DOWN, j]
60
+ }
61
+
62
+ /**
63
+ * Moves the given coordinates one step down and one step left.
64
+ * @param {[number, number]} coords - The current coordinates [row, column].
65
+ * @param {[number, number]} size - Array containing the number of rows and columns.
66
+ * @returns {[number, number]} The new coordinates after moving down-left.
67
+ */
68
+ export function downLeft(coords, size) {
69
+ return down(left(coords, size), size)
70
+ }
71
+
72
+ /**
73
+ * Moves the given coordinates one step down and one step right.
74
+ * @param {[number, number]} coords - The current coordinates [row, column].
75
+ * @param {[number, number]} size - Array containing the number of rows and columns.
76
+ * @returns {[number, number]} The new coordinates after moving down-right.
77
+ */
78
+ export function downRight(coords, size) {
79
+ return down(right(coords, size), size)
80
+ }
81
+
82
+ /**
83
+ * Moves the given coordinates one step left.
84
+ * @param {[number, number]} coords - The current coordinates [row, column].
85
+ * @returns {[number, number]} The new coordinates after moving left.
86
+ * @throws {Error} If the movement goes out of bounds.
87
+ */
88
+ export function left([i, j]) {
89
+ if (j === FIRST_COLUMN) {
90
+ throw new Error()
91
+ }
92
+ return [i, j + MOVE_LEFT]
93
+ }
94
+
95
+ /**
96
+ * Moves the given coordinates one step right.
97
+ * @param {[number, number]} coords - The current coordinates [row, column].
98
+ * @param {[number, number]} size - Array containing the number of rows and columns.
99
+ * @returns {[number, number]} The new coordinates after moving right.
100
+ * @throws {Error} If the movement goes out of bounds.
101
+ */
102
+ export function right([i, j], [, columns]) {
103
+ if (j === columns - LAST_COLUMN_OFFSET) {
104
+ throw new Error()
105
+ }
106
+ return [i, j + MOVE_RIGHT]
107
+ }
108
+
109
+ /**
110
+ * Converts the board to a string representation.
111
+ * @param {any[]} board - The 1D board to convert.
112
+ * @param {[number, number]} dimensions - Array containing the number of rows and columns.
113
+ * @param {Function} [cellToString=DEFAULT_CELL_TO_STRING] - Function to convert each cell to a string.
114
+ * @returns {string} The string representation of the board.
115
+ */
116
+ export function toString(
117
+ board,
118
+ [rows, columns],
119
+ cellToString = DEFAULT_CELL_TO_STRING,
120
+ ) {
121
+ return Array.from({ length: rows }, (_, i) =>
122
+ Array.from({ length: columns }, (_, j) =>
123
+ cellToString(board[getIndex(i, j, columns)], i, j),
124
+ ).join(" "),
125
+ ).join("\n")
126
+ }
127
+
128
+ /**
129
+ * Moves the given coordinates one step up.
130
+ * @param {[number, number]} coords - The current coordinates [row, column].
131
+ * @returns {[number, number]} The new coordinates after moving up.
132
+ * @throws {Error} If the movement goes out of bounds.
133
+ */
134
+ export function up([i, j]) {
135
+ if (i === FIRST_ROW) {
136
+ throw new Error()
137
+ }
138
+ return [i + MOVE_UP, j]
139
+ }
140
+
141
+ /**
142
+ * Moves the given coordinates one step up and one step left.
143
+ * @param {[number, number]} coords - The current coordinates [row, column].
144
+ * @param {[number, number]} size - Array containing the number of rows and columns.
145
+ * @returns {[number, number]} The new coordinates after moving up-left.
146
+ */
147
+ export function upLeft(coords, size) {
148
+ return up(left(coords, size), size)
149
+ }
150
+
151
+ /**
152
+ * Moves the given coordinates one step up and one step right.
153
+ * @param {[number, number]} coords - The current coordinates [row, column].
154
+ * @param {[number, number]} size - Array containing the number of rows and columns.
155
+ * @returns {[number, number]} The new coordinates after moving up-right.
156
+ */
157
+ export function upRight(coords, size) {
158
+ return up(right(coords, size), size)
159
+ }
@@ -0,0 +1,242 @@
1
+ import { expect, test } from "vitest"
2
+
3
+ import { mod } from "../math/numbers.js"
4
+ import {
5
+ createBoard,
6
+ down,
7
+ downLeft,
8
+ downRight,
9
+ left,
10
+ right,
11
+ toString,
12
+ up,
13
+ upLeft,
14
+ upRight,
15
+ } from "./board.js"
16
+
17
+ test("it should create an empty board", () => {
18
+ const size = [4, 4]
19
+ const expectedResult = [
20
+ null,
21
+ null,
22
+ null,
23
+ null,
24
+ null,
25
+ null,
26
+ null,
27
+ null,
28
+ null,
29
+ null,
30
+ null,
31
+ null,
32
+ null,
33
+ null,
34
+ null,
35
+ null,
36
+ ]
37
+
38
+ expect(createBoard(size)).toStrictEqual(expectedResult)
39
+ })
40
+
41
+ test("it should create a checkerboard", () => {
42
+ const size = [4, 4]
43
+ const filler = (i, j) => (!mod(i + j, 2) ? 1 : 0)
44
+ const expectedResult = [1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1]
45
+
46
+ expect(createBoard(size, filler)).toStrictEqual(expectedResult)
47
+ })
48
+
49
+ test("it should return the coordinates of the cell downward", () => {
50
+ const size = [8, 8]
51
+ const coordinates = [3, 4]
52
+ const expectedResult = [4, 4]
53
+
54
+ expect(down(coordinates, size)).toStrictEqual(expectedResult)
55
+ })
56
+
57
+ test("it should throw going down if cell is downmost", () => {
58
+ const size = [8, 8]
59
+ const coordinates = [7, 4]
60
+
61
+ expect(() => down(coordinates, size)).toThrow()
62
+ })
63
+
64
+ test("it should return the coordinates of the cell down left", () => {
65
+ const size = [8, 8]
66
+ const coordinates = [3, 4]
67
+ const expectedResult = [4, 3]
68
+
69
+ expect(downLeft(coordinates, size)).toStrictEqual(expectedResult)
70
+ })
71
+
72
+ test("it should throw going down left if cell is downmost", () => {
73
+ const size = [8, 8]
74
+ const coordinates = [7, 4]
75
+
76
+ expect(() => downLeft(coordinates, size)).toThrow()
77
+ })
78
+
79
+ test("it should throw going down left if cell is downmost", () => {
80
+ const size = [8, 8]
81
+ const coordinates = [3, 0]
82
+
83
+ expect(() => downLeft(coordinates, size)).toThrow()
84
+ })
85
+
86
+ test("it should throw going down left if cell is on the angle", () => {
87
+ const size = [8, 8]
88
+ const coordinates = [7, 0]
89
+
90
+ expect(() => downLeft(coordinates, size)).toThrow()
91
+ })
92
+
93
+ test("it should return the coordinates of the cell down right", () => {
94
+ const size = [8, 8]
95
+ const coordinates = [3, 4]
96
+ const expectedResult = [4, 5]
97
+
98
+ expect(downRight(coordinates, size)).toStrictEqual(expectedResult)
99
+ })
100
+
101
+ test("it should throw going down right if cell is downmost", () => {
102
+ const size = [8, 8]
103
+ const coordinates = [7, 4]
104
+
105
+ expect(() => downRight(coordinates, size)).toThrow()
106
+ })
107
+
108
+ test("it should throw going down right if cell is downmost", () => {
109
+ const size = [8, 8]
110
+ const coordinates = [3, 7]
111
+
112
+ expect(() => downRight(coordinates, size)).toThrow()
113
+ })
114
+
115
+ test("it should throw going down right if cell is on the angle", () => {
116
+ const size = [8, 8]
117
+ const coordinates = [7, 7]
118
+
119
+ expect(() => downRight(coordinates, size)).toThrow()
120
+ })
121
+
122
+ test("it should return the coordinates of the cell to the left", () => {
123
+ const size = [8, 8]
124
+ const coordinates = [3, 4]
125
+ const expectedResult = [3, 3]
126
+
127
+ expect(left(coordinates, size)).toStrictEqual(expectedResult)
128
+ })
129
+
130
+ test("it should not return coordinates to the left if cell is leftmost", () => {
131
+ const size = [8, 8]
132
+ const coordinates = [3, 0]
133
+
134
+ expect(() => left(coordinates, size)).toThrow()
135
+ })
136
+
137
+ test("it should return the coordinates of the cell to the right", () => {
138
+ const size = [8, 8]
139
+ const coordinates = [3, 4]
140
+ const expectedResult = [3, 5]
141
+
142
+ expect(right(coordinates, size)).toStrictEqual(expectedResult)
143
+ })
144
+
145
+ test("it should not return coordinates to the right if cell is rightmost", () => {
146
+ const size = [8, 8]
147
+ const coordinates = [3, 7]
148
+
149
+ expect(() => right(coordinates, size)).toThrow()
150
+ })
151
+
152
+ test("it should return a string representation of the given board", () => {
153
+ const board = [1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1]
154
+
155
+ expect(toString(board, [4, 4])).toBe(`1 0 1 0
156
+ 0 1 0 1
157
+ 1 0 1 0
158
+ 0 1 0 1`)
159
+ })
160
+
161
+ test("it should return a custom string representation of the given board", () => {
162
+ const board = [1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1]
163
+ const cellToString = (cell) => cell.toFixed(1)
164
+
165
+ expect(toString(board, [4, 4], cellToString)).toBe(`1.0 0.0 1.0 0.0
166
+ 0.0 1.0 0.0 1.0
167
+ 1.0 0.0 1.0 0.0
168
+ 0.0 1.0 0.0 1.0`)
169
+ })
170
+
171
+ test("it should return the coordinates of the cell upward", () => {
172
+ const size = [8, 8]
173
+ const coordinates = [3, 4]
174
+ const expectedResult = [2, 4]
175
+
176
+ expect(up(coordinates, size)).toStrictEqual(expectedResult)
177
+ })
178
+
179
+ test("it should throw going upward if cell is topmost", () => {
180
+ const size = [8, 8]
181
+ const coordinates = [0, 4]
182
+
183
+ expect(() => up(coordinates, size)).toThrow()
184
+ })
185
+
186
+ test("it should return the coordinates of the cell up left", () => {
187
+ const size = [8, 8]
188
+ const coordinates = [3, 4]
189
+ const expectedResult = [2, 3]
190
+
191
+ expect(upLeft(coordinates, size)).toStrictEqual(expectedResult)
192
+ })
193
+
194
+ test("it should throw going up left if cell is upmost", () => {
195
+ const size = [8, 8]
196
+ const coordinates = [0, 4]
197
+
198
+ expect(() => upLeft(coordinates, size)).toThrow()
199
+ })
200
+
201
+ test("it should throw going up left if cell is leftmost", () => {
202
+ const size = [8, 8]
203
+ const coordinates = [3, 0]
204
+
205
+ expect(() => upLeft(coordinates, size)).toThrow()
206
+ })
207
+
208
+ test("it should throw going up left if cell is on the angle", () => {
209
+ const size = [8, 8]
210
+ const coordinates = [0, 0]
211
+
212
+ expect(() => upLeft(coordinates, size)).toThrow()
213
+ })
214
+
215
+ test("it should return the coordinates of the cell up right", () => {
216
+ const size = [8, 8]
217
+ const coordinates = [3, 4]
218
+ const expectedResult = [2, 5]
219
+
220
+ expect(upRight(coordinates, size)).toStrictEqual(expectedResult)
221
+ })
222
+
223
+ test("it should throw going up right if cell is upmost", () => {
224
+ const size = [8, 8]
225
+ const coordinates = [0, 4]
226
+
227
+ expect(() => upRight(coordinates, size)).toThrow()
228
+ })
229
+
230
+ test("it should throw going down right if cell is rightmost", () => {
231
+ const size = [8, 8]
232
+ const coordinates = [3, 7]
233
+
234
+ expect(() => upRight(coordinates, size)).toThrow()
235
+ })
236
+
237
+ test("it should throw going down right if cell is on the angle", () => {
238
+ const size = [8, 8]
239
+ const coordinates = [0, 7]
240
+
241
+ expect(() => upRight(coordinates, size)).toThrow()
242
+ })
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Converts a boolean value to its string representation.
3
+ *
4
+ * @param {boolean} bool - The boolean value to convert.
5
+ * @returns {string} The string "true" if the input is true, otherwise "false".
6
+ */
7
+ export function toString(bool) {
8
+ return bool ? "true" : "false"
9
+ }