summaryrefslogtreecommitdiff
path: root/src/simulation/actions.test.js
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-11-10 16:57:23 -0600
committersanine <sanine.not@pm.me>2023-11-10 16:57:23 -0600
commita85f61cef6aef51bf6983f98020f3284aeb5020d (patch)
treef86af3b7f9b63914079d0ff8c55b8f17b47df5fd /src/simulation/actions.test.js
parent3f8b3ea65df956c23b397913561cc8ebe5403c6e (diff)
implement move_forward action
Diffstat (limited to 'src/simulation/actions.test.js')
-rw-r--r--src/simulation/actions.test.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/simulation/actions.test.js b/src/simulation/actions.test.js
new file mode 100644
index 0000000..a870352
--- /dev/null
+++ b/src/simulation/actions.test.js
@@ -0,0 +1,32 @@
+'use strict';
+
+import { actions } from './actions.js';
+
+
+const [move_forward, ...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([]);
+});