summaryrefslogtreecommitdiff
path: root/src/simulation/validity.test.js
blob: ba9e6842c7f9b57c4c35da60b11ff207e1402dda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';

import { world_update } from '../world/world.js';
import { validity } from './validity.js';

test("agents are not allowed to move into immutables", () => {
  const actions = [{
    size: 1, propose: (world, agent, head) => {
      return [{
        agent_changes: [{
          agent_id: agent.id,
          x: agent.x + 1, y: agent.y,
        }],
      }];
    },
  }];

  const agent = {
    id: 1,
    net: { compute: () => [[1], null] },
    state: null,
    x: 0, y: 0,
    flags: {},
  };

  const lattice = [[{ type: 'empty', flags: {} }, { type: 'immutable', flags: {} }]];
  
  const world = {
    lattice,
    lattice_rules: { empty: ()=>{}, immutable: ()=>{} },
    agents: [agent],
    senses: [],
    actions,
    validity,
  };

  expect(world_update(world).agents[0]).toEqual(agent);
  world.validity = [];
  expect(world_update(world).agents[0]).toEqual({
    ...agent,
    x: 1, y: 0,
  });
});