44#include " ../../sgp_mode/SGPDataNodes.h"
55
66TEST_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-
6866TEST_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