summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-11-09 16:54:41 -0600
committersanine <sanine.not@pm.me>2023-11-09 16:54:41 -0600
commitdd1ac16fce099588d1333cba324810299b1029b6 (patch)
treec1280af39f1dde3e73259a86950b617c9f4723bb
parent55b714abf83e01aa0ff513ad6ba4978f4b4da6cd (diff)
add glider test
-rw-r--r--src/simulation/lattice_rules.test.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/simulation/lattice_rules.test.js b/src/simulation/lattice_rules.test.js
index a91400e..681b721 100644
--- a/src/simulation/lattice_rules.test.js
+++ b/src/simulation/lattice_rules.test.js
@@ -2,6 +2,15 @@ import { world_update } from '../world/world.js';
import { lattice_rules } from './lattice_rules.js';
+function apply(f, n, x0) {
+ if (n == 0) {
+ return x0;
+ } else {
+ return f(apply(f, n-1, x0));
+ }
+}
+
+
test("blinker", () => {
const L = { type: 'active', flags: {} };
const D = { type: 'empty', flags: {} };
@@ -23,3 +32,52 @@ test("blinker", () => {
]);
expect(world_update(world_update(world)).lattice).toEqual(lattice);
});
+
+
+test("glider", () => {
+ const L = { type: 'active', flags: {} };
+ const D = { type: 'empty', flags: {} };
+ const lattice = [
+ [ D, D, D, D, D, D ],
+ [ D, D, D, L, D, D ],
+ [ D, L, D, L, D, D ],
+ [ D, D, L, L, D, D ],
+ [ D, D, D, D, D, D ],
+ [ D, D, D, D, D, D ],
+ ];
+
+ const world = { lattice, lattice_rules, agents: [], senses: [], actions: [] };
+ //expect(world_update(world).lattice).toEqual([
+ expect(apply(world_update, 1, world).lattice).toEqual([
+ [ D, D, D, D, D, D ],
+ [ D, D, L, D, D, D ],
+ [ D, D, D, L, L, D ],
+ [ D, D, L, L, D, D ],
+ [ D, D, D, D, D, D ],
+ [ D, D, D, D, D, D ],
+ ]);
+ expect(apply(world_update, 2, world).lattice).toEqual([
+ [ D, D, D, D, D, D ],
+ [ D, D, D, L, D, D ],
+ [ D, D, D, D, L, D ],
+ [ D, D, L, L, L, D ],
+ [ D, D, D, D, D, D ],
+ [ D, D, D, D, D, D ],
+ ]);
+ expect(apply(world_update, 3, world).lattice).toEqual([
+ [ D, D, D, D, D, D ],
+ [ D, D, D, D, D, D ],
+ [ D, D, L, D, L, D ],
+ [ D, D, D, L, L, D ],
+ [ D, D, D, L, D, D ],
+ [ D, D, D, D, D, D ],
+ ]);
+ expect(apply(world_update, 4, world).lattice).toEqual([
+ [ D, D, D, D, D, D ],
+ [ D, D, D, D, D, D ],
+ [ D, D, D, D, L, D ],
+ [ D, D, L, D, L, D ],
+ [ D, D, D, L, L, D ],
+ [ D, D, D, D, D, D ],
+ ]);
+});