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

Synopsis: (test_gif_psc_exp) run


Description:

 This testscript checks the correctness of gif_psc_exp neuron model. It injects
 external DC current and also three 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, testsuite::test_gif_psc_exp_multisynapse
*/

(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 Create /neuron Set
  neuron params SetStatus

  /spike_generator Create /sg Set
  sg << /spike_times [10.0 20.0 30.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

  sg neuron << /weight 1.0 >> 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_syn_ex 8.0 /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
