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 _ = { type: 'empty', flags: {} }; const l = { type: 'active', flags: { emit: [0, 0, 0, 0, 0, 0, 0, 1] } }; const d = { type: 'empty', flags: { emit: [0, 0, 0, 0, 0, 0, 0, -1] } }; const lattice = [ [ _, _, _, _, _ ], [ _, _, _, _, _ ], [ _, L, L, L, _ ], [ _, _, _, _, _ ], [ _, _, _, _, _ ], ]; const world = { lattice, lattice_rules, agents: [], senses: [], actions: [], validity: [] }; expect(world_update(world).lattice).toEqual([ [ _, _, _, _, _ ], [ _, _, l, _, _ ], [ _, d, L, d, _ ], [ _, _, l, _, _ ], [ _, _, _, _, _ ], ]); expect(world_update(world_update(world)).lattice).toEqual([ [ _, _, _, _, _ ], [ _, _, d, _, _ ], [ _, l, L, l, _ ], [ _, _, d, _, _ ], [ _, _, _, _, _ ], ]); }); test("glider", () => { const L = { type: 'active', flags: {} }; const _ = { type: 'empty', flags: {} }; const l = { type: 'active', flags: { emit: [0, 0, 0, 0, 0, 0, 0, 1] } }; const d = { type: 'empty', flags: { emit: [0, 0, 0, 0, 0, 0, 0, -1] } }; const lattice = [ [ _, _, _, _, _, _ ], [ _, _, _, L, _, _ ], [ _, L, _, L, _, _ ], [ _, _, L, L, _, _ ], [ _, _, _, _, _, _ ], [ _, _, _, _, _, _ ], ]; const world = { lattice, lattice_rules, agents: [], senses: [], actions: [], validity: [] }; //expect(world_update(world).lattice).toEqual([ expect(apply(world_update, 1, world).lattice).toEqual([ [ _, _, _, _, _, _ ], [ _, _, l, d, _, _ ], [ _, d, _, L, l, _ ], [ _, _, L, L, _, _ ], [ _, _, _, _, _, _ ], [ _, _, _, _, _, _ ], ]); expect(apply(world_update, 2, world).lattice).toEqual([ [ _, _, _, _, _, _ ], [ _, _, d, l, _, _ ], [ _, _, _, d, L, _ ], [ _, _, L, L, l, _ ], [ _, _, _, _, _, _ ], [ _, _, _, _, _, _ ], ]); expect(apply(world_update, 3, world).lattice).toEqual([ [ _, _, _, _, _, _ ], [ _, _, _, d, _, _ ], [ _, _, l, _, L, _ ], [ _, _, d, L, L, _ ], [ _, _, _, l, _, _ ], [ _, _, _, _, _, _ ], ]); expect(apply(world_update, 4, world).lattice).toEqual([ [ _, _, _, _, _, _ ], [ _, _, _, _, _, _ ], [ _, _, d, _, L, _ ], [ _, _, l, d, L, _ ], [ _, _, _, L, l, _ ], [ _, _, _, _, _, _ ], ]); }); test("beehive", () => { const L = { type: 'active', flags: {} }; const _ = { type: 'empty', flags: {} }; const lattice = [ [ _, _, _, _, _, _ ], [ _, _, L, L, _, _ ], [ _, L, _, _, L, _ ], [ _, _, L, L, _, _ ], [ _, _, _, _, _, _ ], ]; const world = { lattice, lattice_rules, agents: [], senses: [], actions: [], validity: [] }; //expect(world_update(world).lattice).toEqual([ expect(apply(world_update, 1, world).lattice).toEqual(lattice); });