summaryrefslogtreecommitdiff
path: root/core/test_pla_apply.cpp
blob: 7e18c93e6d6a4b7a44e595237e8453d5b867c932 (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
#include <boost/mpl/list.hpp>
#include <boost/mpl/pair.hpp>
#include <boost/tuple/tuple.hpp>
#include <iostream>

#include "index.hpp"
#include "index_spike.hpp"
#include "pla_apply.hpp"
#include "property_composition.hpp"
#include "property_access.hpp"
#include "context.hpp"

#include "model.hpp" // for Voltage, Weight


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

  // define a fake sim env
  typedef PropertyComposition<Lists::all> pc_t;
  pc_t pc;

  // set weight to 3.0
  pc.cast(PLA_Set<Weight>{0.0, Ptr<Synapse>{0}, 3.0});

  // create and call an apply PLA
  DelieverContext<SpikeArrival, Neuron> 
    ctx(make_tuple(Ptr<SpikeArrival>{0}, Ptr<Synapse>{0}),
	Ptr<Neuron>(0));
  PLA_Apply<SpikeArrival, Neuron, pc_t> apply(Time(0), ctx);

  assert(Property_Get<Voltage>::eval(pc, ctx, Time(0)) == 0.0);
  pc.call(apply);
  assert(Property_Get<Voltage>::eval(pc, ctx, Time(0)) == 0.0);


  // check for desired event generation pattern
  assert(!apply.generate<SpikeArrival>());
  assert(!apply.generate<GlobalMsg>());
  assert(apply.generate<Spike>());
  assert(apply.generateAny());

  // commit and test for proper change
  assert(Property_Get<Voltage>::eval(pc, ctx, Time(0)) == 0.0);
  apply.commit(pc);
  assert(Property_Get<Voltage>::eval(pc, ctx, Time(0)) == 3.0);

  // additional compile time checks of helper classes
  BOOST_MPL_ASSERT((ContinuousProperty_ApplyChangesProp<Voltage, SpikeArrival>));
  BOOST_MPL_ASSERT_NOT((ContinuousProperty_ApplyChangesProp<Weight, SpikeArrival>));

  return 0;
}
contact: Jan Huwald // Impressum