forked from anyaevostinar/SymbulationEmp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSenseTask_Tasks.test.cc
More file actions
227 lines (188 loc) · 7.95 KB
/
Copy pathSenseTask_Tasks.test.cc
File metadata and controls
227 lines (188 loc) · 7.95 KB
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#include "../../test_utils.h"
#include "../../../default_mode/SymWorld.h"
#include "../../../default_mode/WorldSetup.cc"
#include "../../../default_mode/DataNodes.h"
#include "../../../sgp_mode/SGPWorld.h"
#include "../../../sgp_mode/SGPWorld.cc"
#include "../../../sgp_mode/SGPWorldSetup.cc"
#include "../../../sgp_mode/SGPWorldData.cc"
#include "../../../sgp_mode/SGPW_InteractionMechanismSetup.cc"
#include "../../../sgp_mode/SGPW_TaskProfileSetup.cc"
#include "../../../sgp_mode/ProgramBuilder.h"
#include "../../../catch/catch.hpp"
using world_t = sgpmode::SGPWorld;
using cpu_state_t = sgpmode::CPUState<world_t>;
using hw_spec_t = sgpmode::SGPHardwareSpec<sgpmode::Library, cpu_state_t, world_t>;
using hardware_t = sgpmode::SGPHardware<hw_spec_t>;
using program_t = typename world_t::sgp_prog_t;
using sgp_host_t = sgpmode::SGPHost<hw_spec_t>;
using sgp_sym_t = sgpmode::SGPSymbiont<hw_spec_t>;
using tag_t = typename hw_spec_t::tag_t;
TEST_CASE("Test host SenseTask instruction after a rewarded task", "[sgp]"){
sgpmode::SymConfigSGP config;
config.CYCLES_PER_UPDATE(0);
config.SEED(61);
config.TASK_ENV_CFG_PATH("source/test/sgp_mode_test/hardware-test-env.json");
config.FILE_PATH("Instructions_test_output");
config.START_MOI(0);
config.TASK_IO_UNIQUE_OUTPUT(true);
config.TASK_IO_BANK_SIZE(10);
config.ENABLE_TEMP_CHANGING_ENVIRONMENT(true);
config.TEMP_CHANGING_ENVIRONMENT_ORG_TYPE("plastic-both");
test_utils::SetWellMixed(config, 1, 1);
emp::Random random(config.SEED());
world_t world(random, &config);
world.Setup();
auto& prog_builder = world.GetProgramBuilder();
auto& org = world.GetOrg(0);
auto& sgp_host = static_cast<sgp_host_t&>(org);
hardware_t& host_hw = sgp_host.GetHardware();
size_t not_task_id = world.GetTaskEnv().GetTaskSet().GetID("NOT");
// setup correct reward/punishment values for update 0
world.Update();
WHEN("A host runs a task which is rewarded and then the SenseTask instruction") {
program_t host_program;
prog_builder.AddStartAnchor(host_program);
prog_builder.AddInst(host_program, "IO", 0);
prog_builder.AddTask_Not(host_program);
prog_builder.AddInst(host_program, "SenseTask", 0, 1);
host_hw.Reset();
host_hw.SetProgram(host_program);
world.AssignNewEnvIO(host_hw.GetCPUState());
// NOT is currently not rewarded.
REQUIRE(world.GetTaskEnv().GetHostTaskReq(not_task_id).task_value < 0);
// Initial register values
host_hw.SetRegisters({3, 2, 5});
// Run host program
host_hw.RunCPUStep(4);
THEN("SenseTask puts a 0 into register 1"){
REQUIRE(host_hw.GetRegister(1) == 0);
}
}
}
TEST_CASE("Test host SenseTask instruction after a punished task", "[sgp]"){
sgpmode::SymConfigSGP config;
config.CYCLES_PER_UPDATE(0);
config.SEED(61);
config.TASK_ENV_CFG_PATH("source/test/sgp_mode_test/hardware-test-env.json");
config.FILE_PATH("Instructions_test_output");
config.START_MOI(0);
config.TASK_IO_UNIQUE_OUTPUT(true);
config.ENABLE_TEMP_CHANGING_ENVIRONMENT(true);
config.TEMP_CHANGING_ENVIRONMENT_ORG_TYPE("plastic-both");
config.TASK_IO_BANK_SIZE(10);
test_utils::SetWellMixed(config, 1, 1);
emp::Random random(config.SEED());
world_t world(random, &config);
world.Setup();
auto& prog_builder = world.GetProgramBuilder();
auto& org = world.GetOrg(0);
auto& sgp_host = static_cast<sgp_host_t&>(org);
hardware_t& host_hw = sgp_host.GetHardware();
size_t nand_task_id = world.GetTaskEnv().GetTaskSet().GetID("NAND");
// setup correct reward/punishment values for update 0
world.Update();
WHEN("A host runs a task which is punished and then the SenseTask instruction") {
program_t host_program;
prog_builder.AddStartAnchor(host_program);
prog_builder.AddInst(host_program, "IO", 0);
prog_builder.AddInst(host_program, "IO", 1);
prog_builder.AddTask_Nand(host_program);
prog_builder.AddInst(host_program, "SenseTask", 0, 1);
host_hw.Reset();
host_hw.SetProgram(host_program);
world.AssignNewEnvIO(host_hw.GetCPUState());
// NAND is not currently punished.
REQUIRE(world.GetTaskEnv().GetHostTaskReq(nand_task_id).task_value > 0);
// Initial register values
host_hw.SetRegisters({7, 12, 9});
// Run host program
host_hw.RunCPUStep(5);
THEN("SenseTask puts a 1 into register 1"){
REQUIRE(host_hw.GetRegister(1) == 1);
}
}
}
TEST_CASE("Test symbiont SenseTask instruction after a punished task", "[sgp]"){
sgpmode::SymConfigSGP config;
config.CYCLES_PER_UPDATE(0);
config.SEED(61);
config.TASK_ENV_CFG_PATH("source/test/sgp_mode_test/hardware-test-env.json");
config.FILE_PATH("Instructions_test_output");
config.START_MOI(1);
config.TASK_IO_UNIQUE_OUTPUT(true);
config.ENABLE_TEMP_CHANGING_ENVIRONMENT(true);
config.TEMP_CHANGING_ENVIRONMENT_ORG_TYPE("plastic-both");
config.TASK_IO_BANK_SIZE(10);
test_utils::SetWellMixed(config, 1, 1);
emp::Random random(config.SEED());
world_t world(random, &config);
world.Setup();
auto& prog_builder = world.GetProgramBuilder();
auto& sgp_sym = static_cast<sgp_sym_t&>(*world.GetOrg(0).GetSymbionts().at(0));
hardware_t& sym_hw = sgp_sym.GetHardware();
size_t not_task_id = world.GetTaskEnv().GetTaskSet().GetID("NOT");
// setup correct reward/punishment values for update 0
world.Update();
WHEN("A symbiont runs a task which is punished and then the SenseTask instruction"){
program_t sym_program;
prog_builder.AddStartAnchor(sym_program);
prog_builder.AddInst(sym_program, "IO", 0);
prog_builder.AddTask_Not(sym_program);
prog_builder.AddInst(sym_program, "SenseTask", 0, 1);
sym_hw.Reset();
sym_hw.SetProgram(sym_program);
world.AssignNewEnvIO(sym_hw.GetCPUState());
// NOT is currently punished.
REQUIRE(world.GetTaskEnv().GetHostTaskReq(not_task_id).task_value < 0);
// Initial register values
sym_hw.SetRegisters({3, 2, 5});
// Run symbiont program
sym_hw.RunCPUStep(4);
THEN("SenseTask puts a 0 into register 1"){
REQUIRE(sym_hw.GetRegister(1) == 0);
}
}
}
TEST_CASE("Test symbiont SenseTask instruction after a rewarded task", "[sgp]"){
sgpmode::SymConfigSGP config;
config.CYCLES_PER_UPDATE(0);
config.SEED(61);
config.TASK_ENV_CFG_PATH("source/test/sgp_mode_test/hardware-test-env.json");
config.FILE_PATH("Instructions_test_output");
config.START_MOI(1);
config.TASK_IO_UNIQUE_OUTPUT(true);
config.ENABLE_TEMP_CHANGING_ENVIRONMENT(true);
config.TEMP_CHANGING_ENVIRONMENT_ORG_TYPE("plastic-both");
config.TASK_IO_BANK_SIZE(10);
test_utils::SetWellMixed(config, 1, 1);
emp::Random random(config.SEED());
world_t world(random, &config);
world.Setup();
auto& prog_builder = world.GetProgramBuilder();
auto& sgp_sym = static_cast<sgp_sym_t&>(*world.GetOrg(0).GetSymbionts().at(0));
hardware_t& sym_hw = sgp_sym.GetHardware();
size_t nand_task_id = world.GetTaskEnv().GetTaskSet().GetID("NAND");
// setup correct reward/punishment values for update 0
world.Update();
WHEN("A symbiont runs a task which is rewarded and then the SenseTask instruction") {
program_t sym_program;
prog_builder.AddStartAnchor(sym_program);
prog_builder.AddInst(sym_program, "IO", 0);
prog_builder.AddInst(sym_program, "IO", 1);
prog_builder.AddTask_Nand(sym_program);
prog_builder.AddInst(sym_program, "SenseTask", 0, 1);
sym_hw.Reset();
sym_hw.SetProgram(sym_program);
world.AssignNewEnvIO(sym_hw.GetCPUState());
// NAND is currently rewarded.
REQUIRE(world.GetTaskEnv().GetHostTaskReq(nand_task_id).task_value > 0);
// Initial register values
sym_hw.SetRegisters({7, 12, 9});
// run symbiont program
sym_hw.RunCPUStep(5);
THEN("SenseTask puts a 1 into register 1"){
REQUIRE(sym_hw.GetRegister(1) == 1);
}
}
}