Skip to content

Commit c93c43b

Browse files
Merge branch 'complex-syms-clean' into additional_tests
2 parents 5dcb687 + 05cf3ba commit c93c43b

3 files changed

Lines changed: 86 additions & 14 deletions

File tree

source/sgp_mode/CPU.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class CPU {
252252
{"Nop-0", 0}, {"ShiftLeft", 1}, {"ShiftRight", 1}, {"Increment", 1},
253253
{"Decrement", 1}, {"Push", 1}, {"Pop", 1}, {"SwapStack", 0},
254254
{"Swap", 2}, {"Add", 3}, {"Subtract", 3}, {"Nand", 3},
255-
{"Reproduce", 0}, {"PrivateIO", 1}, {"Donate", 0}, {"Steal", 0}};
255+
{"Reproduce", 0}, {"SharedIO", 1}, {"Donate", 0}, {"Steal", 0}};
256256

257257
for (auto i : program) {
258258
PrintOp(i, arities, cpu.GetActiveCore().GetGlobalJumpTable(), out);

source/test/sgp_mode_test/GenomeLibrary.test.cc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ void TestGenome(emp::Ptr<Task> task, void (ProgramBuilder::*method)()) {
3636
TEST_CASE("Generate NOT program", "[sgp]") {
3737
TestGenome(emp::NewPtr<InputTask>(NOT), &ProgramBuilder::AddNot);
3838
}
39-
4039
TEST_CASE("Generate NAND program", "[sgp]") {
4140
TestGenome(emp::NewPtr<InputTask>(NAND), &ProgramBuilder::AddNand);
4241
}
@@ -88,4 +87,25 @@ TEST_CASE("Empty ProgramBuilder can't do tasks", "[sgp]") {
8887
for (auto data : world.GetTaskSet()) {
8988
REQUIRE(data.n_succeeds_host == 0);
9089
}
90+
}
91+
92+
TEST_CASE("BuildNoRepro creates obligate mutualist program", "[sgp]") {
93+
ProgramBuilder builder;
94+
size_t program_len = 100;
95+
96+
sgpl::Program<Spec> program = builder.BuildNoRepro(program_len);
97+
98+
REQUIRE(program.size() == program_len);
99+
100+
for (size_t i = program.size() - 5; i < program.size(); ++i) {
101+
REQUIRE(program[i].op_code == Library::GetOpCode("Donate"));
102+
}
103+
104+
for (auto &inst : program) {
105+
REQUIRE(inst.op_code != Library::GetOpCode("Reproduce"));
106+
}
107+
108+
REQUIRE(program[0].op_code == Library::GetOpCode("Global Anchor"));
109+
REQUIRE(program[0].tag == START_TAG);
110+
91111
}

source/test/sgp_mode_test/SGPSymbiont.test.cc

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@
44
#include "../../sgp_mode/SGPDataNodes.h"
55

66
TEST_CASE("SGPSymbiont Reproduce", "[sgp]") {
7-
emp::Random random(31);
8-
SymConfigSGP config;
9-
SGPWorld world(random, &config, LogicTasks);
10-
emp::Ptr<SGPSymbiont> sym_parent = emp::NewPtr<SGPSymbiont>(&random, &world, &config, CreateNotProgram(100));
11-
7+
emp::Random random(31);
8+
SymConfigSGP config;
9+
SGPWorld world(random, &config, LogicTasks);
10+
emp::Ptr<SGPSymbiont> sym_parent = emp::NewPtr<SGPSymbiont>(&random, &world, &config, CreateNotProgram(100));
1211

13-
THEN("Symbiont child increases its lineage reproduction count"){
14-
emp::Ptr<SGPSymbiont> sym_baby = (sym_parent->Reproduce()).DynamicCast<SGPSymbiont>();
15-
REQUIRE(sym_parent->GetReproCount() == sym_baby->GetReproCount() - 1);
16-
sym_baby.Delete();
12+
THEN("Symbiont child increases its lineage reproduction count") {
13+
emp::Ptr<SGPSymbiont> sym_baby = (sym_parent->Reproduce()).DynamicCast<SGPSymbiont>();
14+
REQUIRE(sym_parent->GetReproCount() == sym_baby->GetReproCount() - 1);
15+
sym_baby.Delete();
1716
sym_parent.Delete();
18-
}
17+
}
1918

2019
WHEN("Parental task tracking is on") {
21-
2220
emp::Ptr<SGPHost> host = emp::NewPtr<SGPHost>(&random, &world, &config, CreateNotProgram(100));
2321
config.TRACK_PARENT_TASKS(1);
2422
world.AddOrgAt(host, 0);
@@ -40,6 +38,7 @@ TEST_CASE("SGPSymbiont Reproduce", "[sgp]") {
4038
REQUIRE(sym_baby->GetCPU().state.parent_tasks_performed->CountOnes() == 1);
4139
}
4240

41+
4342
THEN("The symbiont child tracks any gains or loses in task completions") {
4443
// in this second generation, we expect the symbiont to gain the NOT task
4544
// since first-gen organisms are marked as having parents who have completed no tasks
@@ -64,7 +63,6 @@ TEST_CASE("SGPSymbiont Reproduce", "[sgp]") {
6463
}
6564
}
6665

67-
6866
TEST_CASE("When ONLY_FIRST_TASK_CREDIT is 1, the most tasks a symbiont can receive credit for is 1", "[sgp]"){
6967

7068
emp::Random random(1);
@@ -305,3 +303,57 @@ TEST_CASE("When ONLY_FIRST_TASK_CREDIT is 0, symbionts receive credit for all ta
305303

306304

307305
}
306+
307+
TEST_CASE("Symbiont comparison operators", "[sgp]") {
308+
emp::Random random(31);
309+
SymConfigSGP config;
310+
SGPWorld world(random, &config, LogicTasks);
311+
emp::Ptr<SGPSymbiont> sym_parent = emp::NewPtr<SGPSymbiont>(&random, &world, &config, CreateNotProgram(100));
312+
313+
emp::Ptr<SGPHost> host = emp::NewPtr<SGPHost>(&random, &world, &config, CreateNotProgram(100));
314+
config.TRACK_PARENT_TASKS(1);
315+
world.AddOrgAt(host, 0);
316+
host->AddSymbiont(sym_parent);
317+
318+
for (int i = 0; i < 25; i++) {
319+
world.Update();
320+
}
321+
emp::Ptr<SGPSymbiont> clone1 = emp::NewPtr<SGPSymbiont>(*sym_parent);
322+
emp::Ptr<SGPSymbiont> clone2 = emp::NewPtr<SGPSymbiont>(*sym_parent);
323+
emp::Ptr<SGPSymbiont> different = emp::NewPtr<SGPSymbiont>(&random, &world, &config, CreateNotProgram(99)); // For comparing
324+
325+
REQUIRE(*sym_parent == *clone1);
326+
REQUIRE(*clone1 == *clone2);
327+
328+
REQUIRE_FALSE(*sym_parent == *different);
329+
330+
// Can't assert true/false without knowing bitcode ordering,
331+
// assert that bitcode ordering is well-defined
332+
bool lt = *sym_parent < *different || *different < *sym_parent;
333+
REQUIRE(lt);
334+
335+
clone1.Delete();
336+
clone2.Delete();
337+
different.Delete();
338+
}
339+
340+
TEST_CASE("SGPSymbiont destructor cleans up shared pointers and in-progress reproduction", "[sgp]") {
341+
emp::Random random(31);
342+
SymConfigSGP config;
343+
SGPWorld world(random, &config, LogicTasks);
344+
emp::Ptr<SGPSymbiont> sym = emp::NewPtr<SGPSymbiont>(&random, &world, &config, CreateNotProgram(100));
345+
sym->GetCPU().state.in_progress_repro = 3;
346+
world.to_reproduce.resize(5);
347+
world.to_reproduce[3].second = emp::WorldPosition(1, 2);
348+
349+
REQUIRE(world.to_reproduce[3].second.IsValid());
350+
351+
WHEN("Symbionts is destroyed") {
352+
sym.Delete();
353+
354+
THEN("Reproduction queue is invalidated after symbiont is destroyed") {
355+
REQUIRE_FALSE(world.to_reproduce[3].second.IsValid());
356+
}
357+
}
358+
}
359+

0 commit comments

Comments
 (0)