summaryrefslogtreecommitdiff
path: root/src/simulation/actions.test.js
blob: 457015d89b9feae2ab9eda0ba43f1cd5ad0ca778 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'use strict';

import { actions } from './actions.js';


const [move_forward, move_backward, turn_left, ...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([]);
});