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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
'use strict';
import { actions } from './actions.js';
const [
move_forward, move_backward,
turn_left, turn_right,
place, trigger,
...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(null, n, [1])).toEqual([
{ agent_changes: [{ agent_id: 0, x: 0, y: -1 }] },
]);
expect(move_forward.propose(null, s, [1])).toEqual([
{ agent_changes: [{ agent_id: 0, x: 0, y: 1 }] },
]);
expect(move_forward.propose(null, e, [1])).toEqual([
{ agent_changes: [{ agent_id: 0, x: 1, y: 0 }] },
]);
expect(move_forward.propose(null, w, [1])).toEqual([
{ agent_changes: [{ agent_id: 0, x: -1, y: 0 }] },
]);
expect(move_forward.propose(null, n, [0])).toEqual([]);
expect(move_forward.propose(null, s, [-1])).toEqual([]);
expect(move_forward.propose(null, e, [0])).toEqual([]);
expect(move_forward.propose(null, 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(null, n, [1])).toEqual([
{ agent_changes: [{ agent_id: 0, x: 0, y: 1 }] },
]);
expect(move_backward.propose(null, s, [1])).toEqual([
{ agent_changes: [{ agent_id: 0, x: 0, y: -1 }] },
]);
expect(move_backward.propose(null, e, [1])).toEqual([
{ agent_changes: [{ agent_id: 0, x: -1, y: 0 }] },
]);
expect(move_backward.propose(null, w, [1])).toEqual([
{ agent_changes: [{ agent_id: 0, x: 1, y: 0 }] },
]);
expect(move_backward.propose(null, n, [0])).toEqual([]);
expect(move_backward.propose(null, s, [-1])).toEqual([]);
expect(move_backward.propose(null, e, [0])).toEqual([]);
expect(move_backward.propose(null, 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(null, n, [1])).toEqual([
{ agent_changes: [{ agent_id: 0, flags: { orientation: 'w' } }] },
]);
expect(turn_left.propose(null, s, [1])).toEqual([
{ agent_changes: [{ agent_id: 0, flags: { orientation: 'e' } }] },
]);
expect(turn_left.propose(null, e, [1])).toEqual([
{ agent_changes: [{ agent_id: 0, flags: { orientation: 'n' } }] },
]);
expect(turn_left.propose(null, w, [1])).toEqual([
{ agent_changes: [{ agent_id: 0, flags: { orientation: 's' } }] },
]);
expect(turn_left.propose(null, n, [0])).toEqual([]);
expect(turn_left.propose(null, s, [-1])).toEqual([]);
expect(turn_left.propose(null, e, [0])).toEqual([]);
expect(turn_left.propose(null, 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(null, n, [1])).toEqual([
{ agent_changes: [{ agent_id: 0, flags: { orientation: 'e' } }] },
]);
expect(turn_right.propose(null, s, [1])).toEqual([
{ agent_changes: [{ agent_id: 0, flags: { orientation: 'w' } }] },
]);
expect(turn_right.propose(null, e, [1])).toEqual([
{ agent_changes: [{ agent_id: 0, flags: { orientation: 's' } }] },
]);
expect(turn_right.propose(null, w, [1])).toEqual([
{ agent_changes: [{ agent_id: 0, flags: { orientation: 'n' } }] },
]);
expect(turn_right.propose(null, n, [0])).toEqual([]);
expect(turn_right.propose(null, s, [-1])).toEqual([]);
expect(turn_right.propose(null, e, [0])).toEqual([]);
expect(turn_right.propose(null, w, [-1])).toEqual([]);
});
test("place", () => {
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(place.propose(null, n, [1])).toEqual([
{ lattice_changes: [
{
x: 0, y: -1, from: 'empty', to: 'mutable',
flags: { emit: [1, 0, 0, 0, 0, 0, 0, 0] }
}
]}
]);
expect(place.propose(null, s, [1])).toEqual([
{ lattice_changes: [
{
x: 0, y: 1, from: 'empty', to: 'mutable',
flags: { emit: [1, 0, 0, 0, 0, 0, 0, 0] }
}
]}
]);
expect(place.propose(null, e, [1])).toEqual([
{ lattice_changes: [
{
x: 1, y: 0, from: 'empty', to: 'mutable',
flags: { emit: [1, 0, 0, 0, 0, 0, 0, 0] }
}
]}
]);
expect(place.propose(null, w, [1])).toEqual([
{ lattice_changes: [
{
x: -1, y: 0, from: 'empty', to: 'mutable',
flags: { emit: [1, 0, 0, 0, 0, 0, 0, 0] }
}
]}
]);
expect(place.propose(null, n, [0])).toEqual([]);
expect(place.propose(null, s, [-1])).toEqual([]);
expect(place.propose(null, e, [0])).toEqual([]);
expect(place.propose(null, w, [-1])).toEqual([]);
});
test("trigger", () => {
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(trigger.propose(null, n, [1])).toEqual([
{ lattice_changes: [{
x: 0, y: -1, from: 'mutable', to: 'active',
flags: { emit: [1, 0, 0, 0, 0, 0, 0, 0] },
}]},
]);
expect(trigger.propose(null, s, [1])).toEqual([
{ lattice_changes: [{
x: 0, y: 1, from: 'mutable', to: 'active',
flags: { emit: [1, 0, 0, 0, 0, 0, 0, 0] },
}]},
]);
expect(trigger.propose(null, e, [1])).toEqual([
{ lattice_changes: [{
x: 1, y: 0, from: 'mutable', to: 'active',
flags: { emit: [1, 0, 0, 0, 0, 0, 0, 0] },
}]},
]);
expect(trigger.propose(null, w, [1])).toEqual([
{ lattice_changes: [{
x: -1, y: 0, from: 'mutable', to: 'active',
flags: { emit: [1, 0, 0, 0, 0, 0, 0, 0] },
}]},
]);
expect(trigger.propose(null, n, [0])).toEqual([]);
expect(trigger.propose(null, s, [-1])).toEqual([]);
expect(trigger.propose(null, e, [0])).toEqual([]);
expect(trigger.propose(null, w, [-1])).toEqual([]);
});
|