'use strict'; import { actions } from './actions.js'; const [ move_forward, move_backward, turn_left, turn_right, ...rest ] = actions; test("move forward", () => { const n = { id: 0, x: 0, y: 0, flags: { orientation: 'n' } }; const s = { id: 0, x: 0, y: 0, flags: { orientation: 's' } }; const e = { id: 0, x: 0, y: 0, flags: { orientation: 'e' } }; const w = { id: 0, x: 0, y: 0, flags: { orientation: 'w' } }; expect(move_forward.propose(n, [1])).toEqual([ { agent_changes: [{ agent_id: 0, x: 0, y: -1 }] }, ]); expect(move_forward.propose(s, [1])).toEqual([ { agent_changes: [{ agent_id: 0, x: 0, y: 1 }] }, ]); expect(move_forward.propose(e, [1])).toEqual([ { agent_changes: [{ agent_id: 0, x: 1, y: 0 }] }, ]); expect(move_forward.propose(w, [1])).toEqual([ { agent_changes: [{ agent_id: 0, x: -1, y: 0 }] }, ]); expect(move_forward.propose(n, [0])).toEqual([]); expect(move_forward.propose(s, [-1])).toEqual([]); expect(move_forward.propose(e, [0])).toEqual([]); expect(move_forward.propose(w, [-1])).toEqual([]); }); test("move backward", () => { const n = { id: 0, x: 0, y: 0, flags: { orientation: 'n' } }; const s = { id: 0, x: 0, y: 0, flags: { orientation: 's' } }; const e = { id: 0, x: 0, y: 0, flags: { orientation: 'e' } }; const w = { id: 0, x: 0, y: 0, flags: { orientation: 'w' } }; expect(move_backward.propose(n, [1])).toEqual([ { agent_changes: [{ agent_id: 0, x: 0, y: 1 }] }, ]); expect(move_backward.propose(s, [1])).toEqual([ { agent_changes: [{ agent_id: 0, x: 0, y: -1 }] }, ]); expect(move_backward.propose(e, [1])).toEqual([ { agent_changes: [{ agent_id: 0, x: -1, y: 0 }] }, ]); expect(move_backward.propose(w, [1])).toEqual([ { agent_changes: [{ agent_id: 0, x: 1, y: 0 }] }, ]); expect(move_backward.propose(n, [0])).toEqual([]); expect(move_backward.propose(s, [-1])).toEqual([]); expect(move_backward.propose(e, [0])).toEqual([]); expect(move_backward.propose(w, [-1])).toEqual([]); }); test("turn_left", () => { const n = { id: 0, x: 0, y: 0, flags: { orientation: 'n' } }; const s = { id: 0, x: 0, y: 0, flags: { orientation: 's' } }; const e = { id: 0, x: 0, y: 0, flags: { orientation: 'e' } }; const w = { id: 0, x: 0, y: 0, flags: { orientation: 'w' } }; expect(turn_left.propose(n, [1])).toEqual([ { agent_changes: [{ agent_id: 0, flags: { orientation: 'w' } }] }, ]); expect(turn_left.propose(s, [1])).toEqual([ { agent_changes: [{ agent_id: 0, flags: { orientation: 'e' } }] }, ]); expect(turn_left.propose(e, [1])).toEqual([ { agent_changes: [{ agent_id: 0, flags: { orientation: 'n' } }] }, ]); expect(turn_left.propose(w, [1])).toEqual([ { agent_changes: [{ agent_id: 0, flags: { orientation: 's' } }] }, ]); expect(turn_left.propose(n, [0])).toEqual([]); expect(turn_left.propose(s, [-1])).toEqual([]); expect(turn_left.propose(e, [0])).toEqual([]); expect(turn_left.propose(w, [-1])).toEqual([]); }); test("turn_right", () => { const n = { id: 0, x: 0, y: 0, flags: { orientation: 'n' } }; const s = { id: 0, x: 0, y: 0, flags: { orientation: 's' } }; const e = { id: 0, x: 0, y: 0, flags: { orientation: 'e' } }; const w = { id: 0, x: 0, y: 0, flags: { orientation: 'w' } }; expect(turn_right.propose(n, [1])).toEqual([ { agent_changes: [{ agent_id: 0, flags: { orientation: 'e' } }] }, ]); expect(turn_right.propose(s, [1])).toEqual([ { agent_changes: [{ agent_id: 0, flags: { orientation: 'w' } }] }, ]); expect(turn_right.propose(e, [1])).toEqual([ { agent_changes: [{ agent_id: 0, flags: { orientation: 's' } }] }, ]); expect(turn_right.propose(w, [1])).toEqual([ { agent_changes: [{ agent_id: 0, flags: { orientation: 'n' } }] }, ]); expect(turn_right.propose(n, [0])).toEqual([]); expect(turn_right.propose(s, [-1])).toEqual([]); expect(turn_right.propose(e, [0])).toEqual([]); expect(turn_right.propose(w, [-1])).toEqual([]); });