/*
 *  test_gif_psc_exp_multisynapse.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_gif_psc_exp_multisynapse - sli script for test of
gif_psc_exp_multisynapse with external DC current and spike generators

Synopsis: (test_gif_psc_exp_multisynapse) run


Description:

 This testscript checks the correctness of gif_psc_exp_multisynapse neuron
 model. It injects external DC current and also six spikes to neuron and
 measures its spike times. The spike times should match the expected values.
 The expected spike times are computed by the Python code used for the
 publication (Code/GIF.py in
 http://wiki.epfl.ch/giftoolbox/documents/GIF_Toolbox.zip).
 In order to use the Python code, the adaptation parameters (q_stc/sfa) should
 be converted using the formula described in the model documentation.

Author:  March 2016, Setareh
SeeAlso: gif_psc_exp_multisynapse, testsuite::test_gif_psc_exp
*/

(unittest) run
/unittest using

% neuron with default parameters should fire spikes at 43.5, 83.1 and 125.5 ms
435  /t1_neuron1  Set 
831  /t2_neuron1  Set
1255 /t3_neuron1  Set

% neuron with defined parameters should fire spikes at 20.9 and 79.7 ms
209  /t1_neuron2  Set 
797  /t2_neuron2  Set

/:run_test
{
  /params Set 

  ResetKernel
  0 << 
      /local_num_threads 1 
      /resolution 0.1
      /grng_seed 1
      /rng_seeds [1]
  >> SetStatus

  /gif_psc_exp_multisynapse Create /neuron Set
  neuron params SetStatus

  neuron << /tau_syn [8.0 4.0]>> SetStatus

  /spike_generator Create /sg1 Set
  sg1 << /spike_times [10.0 20.0 30.0]>> SetStatus

  /spike_generator Create /sg2 Set
  sg2 << /spike_times [15.0 25.0 35.0]>> SetStatus

  /dc_generator Create /dc_gen Set
  dc_gen <<  /amplitude 170. >> SetStatus

  /spike_detector Create /sd Set
  sd << /withtime true /to_memory true /time_in_steps true >> SetStatus

  dc_gen neuron Connect

  neuron sd Connect

  sg1 neuron << /weight 1.0 /receptor_type 1 >> Connect
  sg2 neuron << /weight 1.0 /receptor_type 2 >> Connect

  150.0 Simulate

  sd GetStatus /events get /times get
} def

% Test 1: wrong parameters (negative lambda)
{
  << /lambda_0 -10.0 >> :run_test
} fail_or_die
clear

% Test 2: wrong parameters (unequal size of arrays)
{
  << /tau_sfa [120.0] /q_sfa [10.0 25.0] >> :run_test
} fail_or_die
clear

% Test 3: default parameters
{
  << >> :run_test
  arrayload 3 eq rot
  t3_neuron1 eq rot
  t2_neuron1 eq rot
  t1_neuron1 eq and and and
} assert_or_die

% Test 4: defined parameters
{
  << /C_m 40.0 /Delta_V 0.2 /tau_sfa [120.0 10.0] /q_sfa [10.0 25.0] 
     /tau_stc [10.0 20.0] /q_stc [20.0 -5.0] >> :run_test
  arrayload 2 eq rot
  t2_neuron2 eq rot
  t1_neuron2 eq and and
} assert_or_die
