/*
 *  test_multisynapse_models.sli
 *
 *  This file is part of NEST.
 *
 *  Copyright (C) 2004 The NEST Initiative
 *
 *  NEST is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  NEST is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with NEST.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
 
 /* BeginDocumentation
   Name: testsuite::test_multisynapse_models - test properties of multisynapse models

   Synopsis: (test_multisynapse_models) run

   Description:
   For all models with names ending in _multisynapse, this test checks
   
   - that the neuron does not accept input to rport 0
   - that the neuron will accept input to rport 1 in default config
   - that it is possible to set tau_syn/E_rev to empty vectors
     
   SeeAlso:

   FirstVersion: December 2016
   Author: Hans Ekkehard Plesser
 */
 
(unittest) run
/unittest using

M_WARNING setverbosity

% select multisynapse models
/models
 modeldict keys 
 { cvs dup length neg -13 max Take (_multisynapse) eq } Select
 def

% test 1 --- no connection to rport 0
( == Test 1 == ) =
ResetKernel
models
{
  dup == 
  { Create dup Connect } fail_or_die
  4 npop  % remove debris after failed test
} forall

{ count 0 eq } assert_or_die  % check for empty stack

% test 2 --- connect to default port
( == Test 2 == ) =
ResetKernel
models
{
  exch dup ==
  { 
    Create dup << /receptor_type 1 >> Connect
    
    1 add  % index + 1 == num expected connections
    0 /num_connections get eq
  } assert_or_die
} forallindexed

{ count 0 eq } assert_or_die  % check for empty stack

% test 3 --- empty tau_syn/E_rev
( == Test 3 == ) =
<< >> begin
ResetKernel
models
{
  dup ==
  { 
    Create /n Set
    /sdict << >> def
    sdict begin
    [ /E_rev /tau_syn /tau_rise /tau_decay ]
    {
      dup n exch known { [] def } { pop } ifelse
    } forall
    end
    n sdict SetStatus 
    true sdict keys { n exch get empty exch ; and } Fold
  } assert_or_die
} forall
end

{ count 0 eq } assert_or_die  % check for empty stack

endusing
