1/*
2 *  test_distance.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% simple tests for distance calculations
24
25(unittest) run
26/unittest using
27
28% fixed grid, distance from node
29{
30  ResetKernel
31
32  % nodes at [-1,0,1]x[-1,0,1]
33  /l << /elements /iaf_psc_alpha /shape [ 3 3 ] /extent [3. 3.] >> CreateLayer def
34  % nodes placed downward columnwise
35  l [1] Take l Distance
36  [0. 1. 2.            % first column
37   1. 2. sqrt 5. sqrt  % second column
38   2. 5. sqrt 8. sqrt] % third column
39  eq
40} assert_or_die
41
42% fixed grid with periodic BC, distance from node
43{
44  ResetKernel
45
46  % nodes at [-1,0,1]x[-1,0,1]
47  /l << /elements /iaf_psc_alpha /shape [ 3 3 ] /extent [3. 3.] /edge_wrap true >> CreateLayer def
48  % nodes placed downward columnwise
49  l [1] Take l Distance
50  [0. 1. 1.            % first column
51   1. 2. sqrt 2. sqrt  % second column
52   1. 2. sqrt 2. sqrt] % third column
53  eq
54} assert_or_die
55
56% fixed grid, distance from location
57{
58  ResetKernel
59
60  ('THIRD test') ==
61
62  % nodes at [-1,0,1]x[-1,0,1]
63  /l << /elements /iaf_psc_alpha /shape [ 3 3 ] /extent [3. 3.] >> CreateLayer def
64  % nodes placed downward columnwise
65  [[0. 0.]] l Distance
66  [2. sqrt 1. 2. sqrt   % first column
67   1.      0. 1.        % second column
68   2. sqrt 1. 2. sqrt ] % third column
69  eq
70} assert_or_die
71
72% fixed grid with periodic BC, distance from location
73{
74  ResetKernel
75
76  % nodes at [-1,0,1]x[-1,0,1]
77  /l << /elements /iaf_psc_alpha /shape [ 3 3 ] /extent [3. 3.] /edge_wrap true >> CreateLayer def
78  % nodes placed downward columnwise
79  [[1. 0.]] l Distance
80  [2. sqrt 1. 2. sqrt   % first column
81   2. sqrt 1. 2. sqrt   % second column
82      1.   0.    1. ] % third column
83  eq
84} assert_or_die
85
86
87% free grid, distance from node
88{
89  ResetKernel
90
91  /l << /elements /iaf_psc_alpha /positions [ [-0.75 0.5] [0.75 0.] ] /extent [2. 2.] >> CreateLayer def
92  % nodes placed downward columnwise
93  l [1 2] Take l [1] Take Distance
94  [0. 1.5 sqr 0.5 sqr add sqrt ]
95  eq
96} assert_or_die
97
98% free grid, periodic bc, distance from node
99{
100  ResetKernel
101
102  /l << /elements /iaf_psc_alpha /positions [ [-0.75 0.5] [0.75 0.] ] /extent [2. 2.] /edge_wrap true >> CreateLayer def
103  % nodes placed downward columnwise
104  l [1 2] Take l [1] Take Distance
105  [0. 0.5 sqr 0.5 sqr add sqrt ]
106  eq
107} assert_or_die
108
109endusing
110