diff options
Diffstat (limited to 'src/simulation/game.test.js')
-rw-r--r-- | src/simulation/game.test.js | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/simulation/game.test.js b/src/simulation/game.test.js index ac65618..219dce6 100644 --- a/src/simulation/game.test.js +++ b/src/simulation/game.test.js @@ -1,6 +1,7 @@ 'use strict'; -import { setup_board } from './game.js'; +import { apply } from '../util.js'; +import { setup_board, create_world } from './game.js'; test("set up boards correctly", () => { @@ -31,3 +32,28 @@ test("set up boards correctly", () => { [ W, W, W, W, W, W, W, W, W, ], ]); }); + + +test("creating a world works correctly", () => { + const id = 0; + const agent = (id) => ({ id, net: `${id}`, state: `s${id}` }); + const team1 = [agent(0), agent(1)]; + const team2 = [agent(2), agent(3)]; + const team3 = [agent(4), agent(5)]; + const team4 = [agent(6), agent(7)]; + + const world = create_world(6, [team1, team2, team3, team4]); + const agent_cell = (agent) => { + const { x, y } = agent; + return world.lattice[y][x]; + }; + + expect(agent_cell(world.agents[0])).toEqual({ type: 'empty', flags: { team: 0 } }); + expect(agent_cell(world.agents[1])).toEqual({ type: 'empty', flags: { team: 0 } }); + expect(agent_cell(world.agents[2])).toEqual({ type: 'empty', flags: { team: 1 } }); + expect(agent_cell(world.agents[3])).toEqual({ type: 'empty', flags: { team: 1 } }); + expect(agent_cell(world.agents[4])).toEqual({ type: 'empty', flags: { team: 2 } }); + expect(agent_cell(world.agents[5])).toEqual({ type: 'empty', flags: { team: 2 } }); + expect(agent_cell(world.agents[6])).toEqual({ type: 'empty', flags: { team: 3 } }); + expect(agent_cell(world.agents[7])).toEqual({ type: 'empty', flags: { team: 3 } }); +}); |