/*
 *  ticket-921.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::ticket-921 Ensure rport in synapse defaults is unaffected by Connect

Synopsis: (ticket-921) run -> NEST exits if test fails

Description:
This ticket ensures that synapse defaults are unaffected if Connect is called with
a syn_spec containing parameter values, especially that receptor_type is unchanged.

Author: Hans Ekkehard Plesser, 2014-11-06
 */

(unittest) run
/unittest using

M_ERROR setverbosity

% first test: static_synapse
{
  /sdefs /static_synapse GetDefaults def

  /n /iaf_psc_exp_multisynapse << /tau_syn [0.1 0.2] >> Create def
  [n] [n] /one_to_one << /model /static_synapse /receptor_type 2 /weight 1234. /delay 2.3 >> Connect

  /pdefs /static_synapse GetDefaults def
  
  true [/delay /weight /receptor_type] { dup sdefs exch get exch pdefs exch get eq and } Fold
} assert_or_die

% second test: static_synapse, but failing
{
  /sdefs /static_synapse GetDefaults def

  /n /iaf_psc_exp_multisynapse << /tau_syn [0.1 0.2] >> Create def
  mark
  {
    [n] [n] /one_to_one << /model /static_synapse /receptor_type 5 /weight 1234. /delay 2.3 >> Connect
  }
  stopped
  { 
    errordict /newerror false put
    counttomark npop pop  % pop mark separately
  }
  {
    pop   % mark
  } ifelse

  /pdefs /static_synapse GetDefaults def
  
  true [/delay /weight /receptor_type] { dup sdefs exch get exch pdefs exch get eq and } Fold
} assert_or_die

% third test: stdp_synapse with many parameters
{
  /sdefs /stdp_synapse GetDefaults def

  /n /iaf_psc_exp_multisynapse << /tau_syn [0.1 0.2] >> Create def
  [n] [n] /one_to_one << /model /stdp_synapse /receptor_type 2 /weight 1234. /delay 2.3
                         /alpha 7. /lambda 0.05 /mu_minus 2. /mu_plus 3. /tau_plus 50. /Wmax 99.
                      >> Connect

  /pdefs /stdp_synapse GetDefaults def
  
  true [/delay /weight /receptor_type /alpha /lambda /mu_minus /mu_plus /tau_plus /Wmax] 
    { dup sdefs exch get exch pdefs exch get eq and } Fold
} assert_or_die

endusing