diff options
author | sanine <sanine.not@pm.me> | 2023-11-08 00:47:06 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-11-08 00:47:06 -0600 |
commit | f78493e192daf4639b91352909e4029b9970fcdb (patch) | |
tree | 5b43952cc5da05ffcc942d079f0c3b60674060be /src/world/cell.test.js | |
parent | 3ae8f476f3865982ca69d0e39b05b5aa8ec43694 (diff) |
implement basic sensing & refactor world/cells -> lattice
Diffstat (limited to 'src/world/cell.test.js')
-rw-r--r-- | src/world/cell.test.js | 99 |
1 files changed, 0 insertions, 99 deletions
diff --git a/src/world/cell.test.js b/src/world/cell.test.js deleted file mode 100644 index fb901eb..0000000 --- a/src/world/cell.test.js +++ /dev/null @@ -1,99 +0,0 @@ -'use strict'; - -import { cells_update, cells_valid, cells_apply } from './cell.js'; - - -test("growth update rule", () => { - const cells = [[ - { type: 'empty', flags: {} }, - { type: 'empty', flags: {} }, - { type: 'plant', flags: {} }, - ]]; - const update_rules = { - plant: () => {}, - empty: (cells, x, y) => { - if (cells[y][x+1].type === 'plant') { - return { world_updates: [{ x, y, from: 'empty', to: 'plant' }] }; - } - }, - }; - - expect(cells_update(cells, update_rules)).toEqual([ - { world_updates: [{ x: 1, y: 0, from: 'empty', to: 'plant' }] }, - ]); - - cells[0][1] = { type: 'plant' }; - - expect(cells_update(cells, update_rules)).toEqual([ - { world_updates: [{ x: 0, y: 0, from: 'empty', to: 'plant' }] }, - ]); - - cells[0][0] = { type: 'plant' }; - - expect(cells_update(cells, update_rules)).toEqual([]); -}); - - -test("growth update rule applied", () => { - const cells = [[ - { type: 'empty', flags: {} }, - { type: 'empty', flags: {} }, - { type: 'plant', flags: {} }, - ]]; - expect(cells_apply(cells, [{ world_updates:[{ x: 1, y: 0, from: 'empty', to: 'plant' }]}])).toEqual([[ - { type: 'empty', flags: {} }, - { type: 'plant', flags: {} }, - { type: 'plant', flags: {} }, - ]]); - - expect(cells_apply(cells, [ - { world_updates: [{ x: 2, y: 0, from: 'plant', to: 'empty' } ]}, - { world_updates: [{ x: 1, y: 0, from: 'empty', to: 'plant' } ]}, - { world_updates: [{ x: 0, y: 0, from: 'empty', to: 'plant' } ]}, - ])).toEqual([[ - { type: 'plant', flags: {} }, - { type: 'plant', flags: {} }, - { type: 'empty', flags: {} }, - ]]); -}); - - -test("check proposals agains cells for validity", () => { - const cells = [[ { type: 'empty' }, { type: 'empty' }, { type: 'plant' } ]]; - expect(cells_valid(cells, { world_updates: [{ x: -1, y: 0, from: 'blah', to: 'blah' }] })).toBe(false); - expect(cells_valid(cells, { world_updates: [{ x: 0, y: 0, from: 'blah', to: 'blah' }] })).toBe(false); - expect(cells_valid(cells, { world_updates: [{ x: 0, y: 0, from: 'empty', to: 'blah' }] })).toBe(true); - expect(cells_valid(cells, { world_updates: [{ x: 2, y: 0, from: 'empty', to: 'blah' }] })).toBe(false); - expect(cells_valid(cells, { world_updates: [{ x: 2, y: 1, from: 'empty', to: 'blah' }] })).toBe(false); -}); - - -test("proposals update cell flags appropriately", () => { - const cells = [ - [ - { type: 'empty', flags: { step: 1} }, - { type: 'empty', flags: {} }, - { type: 'plant', flags: { foo: 'bar' } }, - ] - ]; - - // flags are reset each time step - expect(cells_apply(cells, [{ world_updates:[{ x: 1, y: 0, from: 'empty', to: 'plant' }]}])).toEqual([[ - { type: 'empty', flags: {} }, - { type: 'plant', flags: {} }, - { type: 'plant', flags: {} }, - ]]); - - // flags are combined when updating - expect(cells_apply(cells, [ - { world_updates: [{ x: 1, y: 0, flags: { foo: 'bar' } } ]}, - { world_updates: [{ x: 1, y: 0, from: 'empty', to: 'plant', flags: { baz: 'baz' } } ]}, - { world_updates: [{ x: 0, y: 0, from: 'empty', to: 'plant', flags: { foo: 'foo' } } ]}, - { world_updates: [{ x: 0, y: 0, flags: { beep: 'boop' } } ]}, - ])).toEqual([[ - { type: 'plant', flags: { foo: 'foo', beep: 'boop' } }, - { type: 'plant', flags: { foo: 'bar', baz: 'baz' } }, - { type: 'plant', flags: {} }, - ]]); - -}); |