1/* 2 * ticket-800.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/** @BeginDocumentation 24 25Name: testsuite::ticket-800 Ensure that spatial parameters check their parameters 26 27Synopsis: (ticket-800) run -> NEST exits if test fails 28 29Description: 30This ticket ensures that spatial parameters check their parameters for 31validity, e.g., strictly positive sigma for a Gaussian. 32 33Author: Hans Ekkehard Plesser, 2014-12-13 34 */ 35 36(unittest) run 37/unittest using 38 39M_ERROR setverbosity 40 41/good_random_parameters 42[ 43 << /uniform << /min 0. /max 1. >> >> 44 << /normal << /mean 0. /std 1. >> >> 45 << /lognormal << /mean 0. /std 1. >> >> 46 << /exponential << /beta 1. >> >> 47] 48def 49 50/good_distance_parameters 51[ 52 << /distance << >> >> 53 << /distance << /dimension 1 >> >> 54 << /distance << /dimension 2 >> >> 55] 56def 57 58/good_parameters good_random_parameters good_distance_parameters join def 59 60/bad_random_parameters 61[ 62 << /uniform << /min 0. /max 0. >> >> 63 << /normal << /mean 0. /sigma 1. >> >> % check if bad parameter names are detected 64 << /normal << /mean 0. /std 0. >> >> 65 << /normal << /mean 0. /std -1. >> >> 66 << /lognormal << /mu 0. /std 0. >> >> 67 << /lognormal << /mu 0. /std -1. >> >> 68 << /lognormal << /mu 0. /std 1. >> >> 69] 70def 71 72/bad_distance_parameters 73[ 74 << /distance << /dim 1 >> >> 75 << /distance << /dimension 1 /min 0. >> >> 76] 77def 78 79/bad_parameters bad_random_parameters bad_distance_parameters join def 80 81/good_masks_2d 82[ 83 << /circular << /radius 1. >> >> 84 << /circular << /radius 1. >> /anchor [0.5 0.5] >> 85 << /rectangular << /lower_left [-0.1 -0.1] /upper_right [0.1 0.1] >> >> 86 << /doughnut << /inner_radius 0.1 /outer_radius 0.2 >> >> 87] 88def 89 90/bad_masks_2d 91[ 92 << /circular << /r 0. >> >> % check if bad parameter names are detected 93 << /circular << /radius 1. /foo 1 >> >> % spurious parameter 94 << /circular << /radius 0. >> >> 95 << /circular << /radius -1. >> >> 96 << /rectangular << /lower_left [-0.1 -0.1] /upper_right [-0.1 0.1] >> >> 97 << /rectangular << /lower_left [-0.1 -0.1] /upper_right [0.1 -0.1] >> >> 98 << /doughnut << /inner_radius 0.1 /outer_radius 0.1 >> >> 99] 100def 101 102/good_masks_3d 103[ 104 << /spherical << /radius 1. >> >> 105 << /box << /lower_left [-0.1 -0.1 -0.1] /upper_right [0.1 0.1 0.1] >> >> 106] 107def 108 109/bad_masks_3d 110[ 111 << /spherical << /radius 0. >> >> 112 << /spherical << /radius -1. >> >> 113 << /box << /lower_left [-0.1 -0.1 -0.1] /upper_right [-0.1 0.1 0.1] >> >> 114 << /box << /lower_left [-0.1 -0.1 -0.1] /upper_right [0.1 -0.1 0.1] >> >> 115 << /box << /lower_left [-0.1 -0.1 -0.1] /upper_right [0.1 0.1 -0.1] >> >> 116] 117def 118 119/good_layers 120[ 121 << /shape [ 2 2 ] /elements /iaf_psc_alpha >> 122 << /shape [ 2 2 ] /elements /iaf_psc_alpha 123 /extent [2. .5] /center [.2 .3] /edge_wrap true >> 124 << /shape [ 2 2 ] /elements /iaf_psc_alpha 125 /extent [2. .5] /center [.2 .3] /edge_wrap false >> 126 << /positions [[0.1 0.1] [0.2 0.2]] /elements /iaf_psc_alpha 127 /extent [2. .5] /edge_wrap true >> 128 << /positions [[0.1 0.1 0.1] [0.2 0.2 0.2]] /elements /iaf_psc_alpha 129 /extent [2. .5 3.] /edge_wrap true >> 130] 131def 132 133/bad_layers 134[ 135 << /shape [ 1 ] /elements /iaf_psc_alpha >> % too few elements in shape 136 << /shape [ 2 2 ] /elementsss /iaf_psc_alpha >> % misspelling 137 << /shape [ 2 2 ] /elements /iaf_psc_alpha 138 /extent [2. .5] /center [.2 .3] /edge_wrap 3 >> % bad data type 139 << /positions [[0.1 0.1] [0.2 0.2 0.2]] /elements /iaf_psc_alpha % dim mix 140 /extent [2. .5] /edge_wrap true >> 141 << /positions [[0.1 0.1 0.1] [0.2 0.2 0.2]] /elements /iaf_psc_alpha % dim mix 142 /extent [2. .5] /edge_wrap true >> 143] 144def 145 146/good_connspecs 147[ 148 << /connection_type /pairwise_bernoulli_on_source >> 149 << /connection_type /pairwise_bernoulli_on_target >> 150 << /connection_type /pairwise_bernoulli_on_source /allow_oversized_mask true >> 151 << /connection_type /pairwise_bernoulli_on_source /synapse_model /static_synapse >> 152 << /connection_type /pairwise_bernoulli_on_source /allow_multapses false >> 153 << /connection_type /pairwise_bernoulli_on_source /allow_autapses false >> 154 << /connection_type /pairwise_bernoulli_on_source /allow_oversized_mask true >> 155 << /connection_type /pairwise_bernoulli_on_source /number_of_connections 2 >> 156 << /connection_type /pairwise_bernoulli_on_target /number_of_connections 2 >> 157 << /connection_type /pairwise_bernoulli_on_source /delay 2.0 >> 158] 159def 160 161/bad_connspecs 162[ 163 << /connection_type /population >> % unknown type 164 << /kernel 0.1 >> % type missing 165] 166def 167 168%% Test runner for 2d connections 169/conn_layers_test_2d 170{ 171 /conndict Set 172 173 ResetKernel 174 << /elements /iaf_psc_alpha /shape [ 1 1 ] >> CreateLayer 175 dup 176 conndict ConnectLayers 177} def 178 179%% Test runner for 3d connections 180/conn_layers_test_3d 181{ 182 /conndict Set 183 184 ResetKernel 185 << /elements /iaf_psc_alpha /positions [ [0. 0. 0.] ] >> CreateLayer 186 dup 187 conndict ConnectLayers 188} def 189 190 191%% first: test CreateParameter on good parameter sets 192good_parameters 193{ 194 /pset Set 195 (Test 1: ) =only 196 pset keys == 197 { pset CreateParameter } pass_or_die 198 clear 199} forall 200 201%% second: test CreateParameter on bad parameter sets 202bad_parameters 203{ 204 /pset Set 205 (Test 2: ) =only 206 pset keys == 207 { pset CreateParameter } fail_or_die 208 clear 209} forall 210 211%% third: test CreateMask on good masks 212good_masks_2d good_masks_3d join 213{ 214 /mask Set 215 (Test 3: ) =only 216 mask keys == 217 { mask CreateMask } pass_or_die 218 clear 219} forall 220 221%% fourth: test CreateMask on bad masks 222bad_masks_2d bad_masks_3d join 223{ 224 /mask Set 225 (Test 4: ) =only 226 mask keys == 227 { mask CreateMask } fail_or_die 228 clear 229} forall 230 231%% fifth: test CreateLayer on good specs 232good_layers 233{ 234 /lspec Set 235 ResetKernel 236 (Test 5: ) =only 237 lspec keys == 238 { lspec CreateLayer } pass_or_die 239 clear 240} forall 241 242%% sixth: test CreateLayer on bad specs 243bad_layers 244{ 245 /lspec Set 246 ResetKernel 247 (Test 6: ) =only 248 lspec keys == 249 { lspec CreateLayer } fail_or_die 250 clear 251} forall 252 253%% seventh: test ConnectLayers with good kernels 254good_distance_parameters [ 0.5 1.0 ] join 255{ 256 /kspec Set 257 (Test 7: ) =only 258 kspec DictQ { keys == } { == } ifelse 259 { << /connection_type /pairwise_bernoulli_on_source /kernel kspec >> 260 conn_layers_test_2d 261 } pass_or_die 262 clear 263} forall 264 265%% eighth: test ConnectLayers with bad kernels 266bad_distance_parameters 267{ 268 /kspec Set 269 (Test 8: ) =only 270 kspec DictQ { keys == } { == } ifelse 271 { << /connection_type /pairwise_bernoulli_on_source /kernel kspec >> 272 conn_layers_test_2d 273 } fail_or_die 274 clear 275} forall 276 277%% ninth: test ConnectLayers with good weights 278good_parameters [ 0.5 1.0 ] join 279{ 280 /wspec Set 281 (Test 9: ) =only 282 wspec DictQ { keys == } { == } ifelse 283 { << /connection_type /pairwise_bernoulli_on_source /weight wspec >> 284 conn_layers_test_2d 285 } pass_or_die 286 clear 287} forall 288 289%% tenth: test ConnectLayers with bad weights 290bad_parameters 291{ 292 /wspec Set 293 (Test 10: ) =only 294 wspec DictQ { keys == } { == } ifelse 295 { << /connection_type /pairwise_bernoulli_on_source /weight wspec >> 296 conn_layers_test_2d 297 } fail_or_die 298 clear 299} forall 300 301%% elevnth: test ConnectLayers with good 2d masks 302good_masks_2d 303{ 304 /mspec Set 305 (Test 11: ) =only 306 mspec DictQ { keys == } { == } ifelse 307 { << /connection_type /pairwise_bernoulli_on_source /mask mspec >> 308 conn_layers_test_2d 309 } pass_or_die 310 clear 311} forall 312 313%% twelfth: test ConnectLayers with bad 2d masks 314bad_masks_2d 315{ 316 /mspec Set 317 (Test 12: ) =only 318 mspec DictQ { keys == } { == } ifelse 319 { << /connection_type /pairwise_bernoulli_on_source /mask mspec >> 320 conn_layers_test_2d 321 } fail_or_die 322 clear 323} forall 324 325%% thirteenth: test ConnectLayers with good 3d masks 326good_masks_3d 327{ 328 /mspec Set 329 (Test 13: ) =only 330 mspec DictQ { keys == } { == } ifelse 331 { << /connection_type /pairwise_bernoulli_on_source /mask mspec >> 332 conn_layers_test_3d 333 } pass_or_die 334 clear 335} forall 336 337%% fourteenth: test ConnectLayers with bad 3d masks 338bad_masks_3d 339{ 340 /mspec Set 341 (Test 14: ) =only 342 mspec DictQ { keys == } { == } ifelse 343 { << /connection_type /pairwise_bernoulli_on_source /mask mspec >> 344 conn_layers_test_3d 345 } fail_or_die 346 clear 347} forall 348 349%% fifteenth test: various good cases 350good_connspecs 351{ 352 /cspec Set 353 (Test 15: ) =only 354 cspec DictQ { keys == } { == } ifelse 355 { cspec 356 conn_layers_test_2d 357 } pass_or_die 358 clear 359} forall 360 361%% sixteenth test: various bad cases 362bad_connspecs 363{ 364 /cspec Set 365 (Test 16: ) =only 366 cspec DictQ { keys == } { == } ifelse 367 { cspec 368 conn_layers_test_2d 369 } fail_or_die 370 clear 371} forall 372 373endusing 374