1/*
2 *  ticket-156.sli
3 *
4 *  This file is part of NEST.
5 *
6 *  Copyright (C) 2004 The NEST Initiative
7 *
8 *  NEST is free software: you can redistribute it and/or modify
9 *  it under the terms of the GNU General Public License as published by
10 *  the Free Software Foundation, either version 2 of the License, or
11 *  (at your option) any later version.
12 *
13 *  NEST is distributed in the hope that it will be useful,
14 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *  GNU General Public License for more details.
17 *
18 *  You should have received a copy of the GNU General Public License
19 *  along with NEST.  If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23/*
24   Test for Ticket 156.
25
26   This test verifies that:
27   poisson_generator_ps generates identical spike trains for given
28   start and stop for different simulation resolutions, and different
29   trains for different targets.
30
31   Protocol:
32   1. poisson_generator_ps projects to two spike_recorders
33   2. run for different resolutions, record precise spike times is ms
34   3. test all spikes are in (start, stop]
35   3. test for different results between spike_recorders
36   4. test for identical results across resolutions
37*/
38
39(unittest) run
40/unittest using
41
42/ps_params <<
43  /origin 0.0
44  /start 1.0
45  /stop  2.0
46  /rate 12345.0  % expect ~ 12.3 spikes
47>> def
48
49/resolutions [0.01 0.1 0.2 0.5 1.0] def
50
51% ensure all spikes arrive at recorder
52/simtime ps_params /stop get 2.0 add def
53
54/check_limits % true if all spikes in (origin+start, origin+stop]
55{
56  << >> begin
57    /spks Set
58    /ori ps_params /origin get def
59    spks Min ps_params /start get ori add gt
60    spks Max ps_params /stop get ori add leq
61    and
62  end
63} def
64
65/single_trial
66{
67  << >> begin
68    /h Set
69    ResetKernel
70    << /resolution h >> SetKernelStatus
71
72    /poisson_generator_ps Create /pg Set
73    pg ps_params SetStatus
74
75    [ /spike_recorder Create
76      /spike_recorder Create
77    ] /srs Set
78    srs { pg exch 1.0 1.0 Connect } forall
79
80    simtime Simulate
81    srs { [/events /times] get cva } Map
82  end
83} def
84
85resolutions { single_trial } Map
86/res Set
87
88(First test) =
89% first test: limits
90res Flatten check_limits
91
92(Second test) =
93% second test: different results between targets
94res {
95  arrayload ; neq
96} Map
97
98(Third test) =
99% third test: equality among runs
100% Test for spike time equality to within 1.0e-16 ms.
101res Transpose {
102  dup First /ref Set
103  Rest true exch { ref sub 0 exch { abs max } Fold 1.0e-15 lt and } Fold
104} Map
105
106% collect
1073 arraystore Flatten
108true exch { and } Fold
109
110assert_or_die
111