summaryrefslogtreecommitdiff
path: root/core/test_pla_evolve.cpp
blob: 4187c9a2a8ec80987dfbce398b7ee7c61d853461 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include <boost/mpl/list.hpp>
#include <boost/mpl/pair.hpp>
#include <boost/mpl/bool.hpp>


#include "context.hpp"
#include "continuous_property.hpp"
#include "pla_evolve.hpp"
#include "pla_get.hpp"
#include "pla_init_default.hpp"
#include "property_composition.hpp"

#include "mempool.hpp"

// create some extra properties

#include "property_abbrevations_begin.hpp"

GEN_CP(Neuron, ConstProp, "const_prop", int, 42);
GEN_CP_EVOLVE(ConstProp, _CP(ConstProp));

GEN_CP(Neuron, ArithProp, "arith_prop", int, 0);
GEN_CP_EVOLVE(ArithProp, (_CP(ArithProp) + 1));

GEN_CP(Neuron, GeomProp, "geom_prop", int, 1);
GEN_CP_EVOLVE(GeomProp, (2*_CP(GeomProp)));

GEN_CP(Neuron, TimeProp, "time_prop", Time, 0.0);
GEN_CP_EVOLVE(TimeProp, _CP(TimeProp) + td);

GEN_CP(Neuron, Alter1, "alter1", bool, true);
GEN_CP(Neuron, Alter2, "alter2", bool, false);
GEN_CP_EVOLVE(Alter1, _CP(Alter2));
GEN_CP_EVOLVE(Alter2, _CP(Alter1));

#include "property_abbrevations_end.hpp"

using namespace std;

int main() {
  using boost::mpl::pair;
  using boost::mpl::list;
  using boost::mpl::bool_;

  // below is bullshit
  PropertyComposition<list<
    pair<ConstProp, bool_<true>>,
    pair<ArithProp, bool_<true>>,
    pair<GeomProp, bool_<true>>,
    pair<TimeProp, bool_<true>>,
    pair<Alter1, bool_<true>>,
    pair<Alter2, bool_<true>>
  >> pc;

  // init with default values
  //PLA_Init_Default<ArithProp> action_init;
  //  pc.call(action_init);

  // create an instance ptr (we only consider a single instance)
  Ptr<Neuron> inst{0};
  ContinuousContext<Neuron> context{inst};

  // evolve and check result using specific gets
  for (int i=1; i<20; i++) {
    Time t{double{i}};
    PLA_Evolve<Neuron> evolve(context, t);
    
    // evolve
    pc.call(evolve);

    // check
    #define CHECK(PN, COND)	{		\
	PLA_Get<PN> action{t,inst}; \
	PN::type res(pc.call(action));	\
	assert(res == (COND));			 \
      }
    
    CHECK(ConstProp, 42);
    CHECK(ArithProp, i);
    CHECK(GeomProp, (1 << i));
    CHECK(TimeProp, t);

    PLA_Get<Alter1>    ag_a1   (t, inst);
    PLA_Get<Alter2>    ag_a2   (t, inst);
    assert(pc.call(ag_a1) ^ pc.call(ag_a2));
  }
}
contact: Jan Huwald // Impressum