/*
 *  test_common_props_setting.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_common_props_setting - test that common properties can be set as defaults, not else

Synopsis: (test_common_props_setting) run -> compare response with reference data

Description:
For synapses with common properties, ensure that common and individual properties can be set by 
SetDefaults and CopyModel, but that an exception is raised if they are set via an individual connection.

FirstVersion: November 2014

Author: Hans E Plesser
*/

(unittest) run
/unittest using

/synmodels 
  [/stdp_synapse_hom /stdp_pl_synapse_hom /stdp_facetshw_synapse_hom 
  /stdp_dopamine_synapse]
  { synapsedict exch known } Select
def

% prepare stdp_dopamine_synapse, which needs a
% volume transmitter assigned to it before connecting
/vol /volume_transmitter Create def
/stdp_dopamine_synapse << /vt vol >> SetDefaults

% first test: do everything correctly
{
  true
  synmodels
  {
    /synmod Set 
    synmod << /tau_plus 5.0 /weight 2.0 >> SetDefaults 
    synmod GetDefaults [[/tau_plus /weight]] get [5.0 2.0] eq
    synmod dup cvs (_copy) join cvlit /copmod Set
    copmod << /tau_plus 15.0 /weight 20.0 >> CopyModel 
    copmod GetDefaults [[/tau_plus /weight]] get [15.0 20.0] eq and
    
    /iaf_neuron Create /n Set
    n n synmod Connect
    << /source [n] >> GetConnections 0 get dup << /weight 3.0 >> SetStatus 
    GetStatus /weight get 3.0 eq and
  } Fold
} assert_or_die

ResetKernel

% prepare stdp_dopamine_synapse, which needs a
% volume transmitter assigned to it before connecting
/vol /volume_transmitter Create def
/stdp_dopamine_synapse << /vt vol >> SetDefaults

% second test: set common prop on synapse
synmodels
{
  /synmod Set
  synmod GetDefaults /tau_plus get /tpref Set
  
  /iaf_neuron Create /n Set
  n n synmod Connect
  << /source [n] >> GetConnections 0 get /c Set
  { c << /tau_plus tpref 1. add 3. mul >> SetStatus } fail_or_die
  { synmod GetDefaults /tau_plus get tpref eq } assert_or_die   
} forall