about summary refs log tree commit diff stats
path: root/ts/bun/__tests__
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2024-06-07 19:02:36 -0400
committerelioat <elioat@tilde.institute>2024-06-07 19:02:36 -0400
commita860fa1fc561209ee7924746e0dc0f425227c43c (patch)
tree393a347bd4d7833238548aaf1c6f6648c4e49616 /ts/bun/__tests__
parent6adc6a232cc4a76206195451d51a233268b2280a (diff)
downloadtour-a860fa1fc561209ee7924746e0dc0f425227c43c.tar.gz
*
Diffstat (limited to 'ts/bun/__tests__')
-rw-r--r--ts/bun/__tests__/gameOfLife.test.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/ts/bun/__tests__/gameOfLife.test.ts b/ts/bun/__tests__/gameOfLife.test.ts
new file mode 100644
index 0000000..1fef3de
--- /dev/null
+++ b/ts/bun/__tests__/gameOfLife.test.ts
@@ -0,0 +1,27 @@
+import { step, countNeighbors } from '../index';
+
+describe('Game of Life', () => {
+    test('countNeighbors counts the number of live neighbors', () => {
+        const grid = [
+            [false, true, false],
+            [false, true, false],
+            [false, true, false]
+        ];
+        expect(countNeighbors(grid, 1, 1)).toBe(2);
+        expect(countNeighbors(grid, 0, 0)).toBe(1);
+    });
+
+    test('step advances the game by one step', () => {
+        const initial = [
+            [false, true, false],
+            [false, true, false],
+            [false, true, false]
+        ];
+        const expected = [
+            [false, true, false],
+            [false, true, false],
+            [false, true, false]
+        ];
+        expect(step(initial)).toEqual(expected);
+    });
+});
\ No newline at end of file