/*
 *  model_node_init.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/>.
 *
 */

/* model_node_init.sli
 
   Makeshift test to see if setting model params and then creating a neuron
   and creating a neuron and then setting node params lead to the same 
   results.

   Works by connecting device to iaf_neuron, measuring voltage trace over 1s
   and comparing traces.

   todo: - generalize for more models
*/

(unittest) run
/unittest using

%/model  /step_current_generator def
%/params << /amplitude_times  [ 100.0 200.0 300.0 500.0 ] 
%           /amplitude_values [ 100.0 -200.0 50.0 100.0 ] 
%        >> def

/model /mip_generator def
/params << /rate 100.0 /p_copy 0.5 /mother_seed 123456 >> def

/run_model {
   
   ResetKernel
   0 << /overwrite_files true >> SetStatus

   % expect boolean flag, if true init model, else init node
   % leave voltmeter potential trace and node status dict on stack
  /param_model Set
 
  param_model { 
   model params SetDefaults
  } if

  model Create /m Set
  
  param_model not {
   m params SetStatus
  } if

  /iaf_psc_alpha Create /n Set
  /voltmeter Create /vm Set
  m  n Connect
  vm n Connect
  vm << /to_file false /to_memory true >> SetStatus

  1000 Simulate

  vm [ /events /V_m ] get cva
  m GetStatus
  2 arraystore
} def

% run once with model, once with node initialization 
% and compare results
[true false] { run_model } Map
Transpose arrayload pop
/sdicts Set
/volts Set

% test status dictionaries and voltage traces
{
  sdicts arrayload pop cva_d exch cva_d eq
} assert_or_die

{
  volts arrayload pop eq
} assert_or_die
