Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
Classes | Functions
test.cc File Reference
#include <assert.h>
#include <iostream>
#include <boost/test/unit_test.hpp>
#include "../Environment.hh"
#include "../env_param_func_collection.hh"
#include "../env_state_func_collection.hh"
Include dependency graph for test.cc:

Classes

struct  EnvParam
 A non-abstract EnvParam, derived from the base class. More...
 
struct  EnvCellState
 A non-abstract EnvCellState, derived from the base class. More...
 

Functions

template<typename T >
void assert_eq (T arg1, T arg2, const double epsilon=1e-12)
 
template<typename Model >
void test_add_env_func (Model &model)
 
int main ()
 

Function Documentation

◆ assert_eq()

template<typename T >
void assert_eq ( arg1,
arg2,
const double  epsilon = 1e-12 
)
14 {
15 T diff = std::abs(arg1 - arg2);
17}
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213

◆ main()

int main ( )
141{
142 try {
143 // Initialize the PseudoParent from config file path
144 Utopia::PseudoParent pp("test.yml");
145
146 // Initialize the main model instance and directly run it
147 // Use the constructed EnvParam and EnvCellState; Have the model in
148 // standalone mode.
150 "Environment", pp);
151
152 // use the register function
153 model.track_state("some_het_parameter");
154 model.track_parameter("some_glob_parameter");
155
156 // Use the push rule function
158
159 return 0;
160 }
161 catch (std::exception& e) {
162 std::cerr << e.what() << std::endl;
163 return 1;
164 }
165 catch (...) {
166 std::cerr << "Exception occurred!" << std::endl;
167 return 1;
168 }
169}
A class to use at the top level of the model hierarchy as a mock parent.
Definition model.hh:1017
void test_add_env_func(Model &model)
Definition test.cc:20

◆ test_add_env_func()

template<typename Model >
void test_add_env_func ( Model model)
20 {
21 using EnvStateFunc = typename Model::EnvStateFunc;
22 using EnvParamFunc = typename Model::EnvParamFunc;
23
24 // Add a custom lambda
25 model.add_env_param_func("test_param", []() { return -1; },
26 "some_glob_parameter", {true, true, {}});
27
28 EnvParamFunc epf = []() { return -2; };
29
30 // Add with update mode
31 model.add_env_param_func("another param test", epf, "some_glob_parameter",
32 {true, true, {}});
33
34
35 // Add a custom lambda
36 model.add_env_state_func("test_state",
37 [](const auto& env_cell) {
38 auto& env_state = env_cell->state;
39 env_state.set_env("some_het_parameter", -1.);
40 return env_state;
41 }
42 );
43
44 EnvStateFunc esf = [](const auto& env_cell) {
45 auto& env_state = env_cell->state;
46 env_state.set_env("some_het_parameter", -1.);
47 return env_state;
48 };
49
50 // Add with update mode
51 model.add_env_state_func("another state test", esf, Update::async);
52
53 // Add initial env func
54 model.template add_env_state_func<true>("initial state", esf);
55 // will not be invoked, but this still tests the interface
56
57 // Use getter
58 double my_param = model.get_parameter("some_glob_parameter");
59 BOOST_TEST(my_param == 0.);
60
61 // use setter
62 model.set_parameter("some_glob_parameter", 100.);
63 BOOST_TEST(model.get_parameter("some_glob_parameter") == 100.);
64
65 // Iterate
66 model.iterate();
67}
BOOST_TEST(constrain_angle(+1.)==+1.)
Assert the basic working of the regularisation function for angles.