Skip to content

Commit f863f34

Browse files
authored
Merge pull request #260 from EliasH-E/Dev_Task_Refactor
Added Task Test
2 parents a4a9a82 + bb1ced3 commit f863f34

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

source/catch/main.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "../test/sgp_mode_test/StressHost.test.cc"
3636
#include "../test/sgp_mode_test/HealthHost.test.cc"
3737
#include "../test/sgp_mode_test/SGPDataNodes.test.cc"
38+
#include "../test/sgp_mode_test/tasks.test.cc"
39+
3840

3941
#include "../test/integration_test/spatial_structure/vt.test.cc"
4042
#include "../test/integration_test/lysogeny/plr.test.cc"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Comments
 (0)