1+ #include " ../../sgp_mode/SGPWorld.h"
2+ #include " ../../sgp_mode/SGPHost.h"
3+ #include " ../../sgp_mode/SGPWorldSetup.cc"
4+
5+ #include " ../../catch/catch.hpp"
6+
7+ TEST_CASE (" When only first task credit is on" ," [ony]" ){
8+ emp::Random random (1 );
9+ SymConfigSGP config;
10+ config.SEED (1 );
11+ config.MUTATION_RATE (0.0 );
12+ config.MUTATION_SIZE (0.002 );
13+ config.TRACK_PARENT_TASKS (1 );
14+ config.VT_TASK_MATCH (1 );
15+ config.ONLY_FIRST_TASK_CREDIT (1 );
16+
17+ SGPWorld world (random, &config, LogicTasks);
18+
19+
20+ WHEN (" Hosts are able to complete both NOT and NAND tasks" ){
21+
22+ // Builds program that does both NOT and NAND operations
23+ ProgramBuilder program;
24+ program.AddNot ();
25+ program.AddNand ();
26+ ProgramBuilder empty_program;
27+
28+ // Creates a host that does both Not and Nand operations
29+ emp::Ptr<SGPHost> host = emp::NewPtr<SGPHost>(&random, &world, &config, program.Build (100 ));
30+
31+ // Creates a symbiont that can not do any tasks
32+ emp::Ptr<SGPSymbiont> sym = emp::NewPtr<SGPSymbiont>(&random, &world, &config, empty_program.Build (100 ));
33+
34+ // Adds host to world and sym to host.
35+ world.AddOrgAt (host, 0 );
36+ host->AddSymbiont (sym);
37+
38+
39+ WHEN (" Host completes both NOT and NAND tasks" ){
40+
41+ host->GetCPU ().RunCPUStep (0 , 100 );
42+
43+ int tasks_completed = 0 ;
44+ for (int i = 0 ; i < CPU_BITSET_LENGTH ; i++) {
45+ tasks_completed += host->GetCPU ().state .tasks_performed ->Get (i);
46+ }
47+ THEN (" Host should only get credit for completing 1 task" ){
48+ REQUIRE (tasks_completed == 1 );
49+ REQUIRE (host->GetPoints () == 5 );
50+
51+ }
52+ }
53+ }
54+ }
0 commit comments