summaryrefslogtreecommitdiff
path: root/src/simulation
diff options
context:
space:
mode:
Diffstat (limited to 'src/simulation')
-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 ],
+ ]);
+});