/*
 *  test_hh_cond_exp_traub.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_hh_cond_exp_traub - sli script for overall test of hh_cond_exp_traub model

    Synopsis: (test_hh_cond_exp_traub) run -> 

    Description:

    Author:  
    SeeAlso: 
*/

(unittest) run
/unittest using

% The following test needs the model hh_cond_exp_traub, so
% this test should only run if we have GSL
skip_if_without_gsl

0.1 /h Set

ResetKernel

0 << 
      /local_num_threads 1 
      /resolution h
    >> SetStatus

%% Test: Node creation

/hh_cond_exp_traub Create /neuron Set

%% Test: Set/GetStatus

<< /V_m 10.0
   /g_Na 19000.0
   /g_K	  5000.0
   /g_L	     9.0
   /C_m	   110.0
   /E_Na    40.0
   /E_K    -80.0   
   /E_L	   -70.0
   %/U_tr   -60.0
   /E_ex     1.0
   /E_in   -90.0
   /tau_syn_ex 0.3
   /tau_syn_in 3.0
   /I_e	     1.0
>> /hh_params Set

neuron hh_params SetStatus
neuron GetStatus /result Set

{
  result /V_m  get 6 ToUnitTestPrecision 10 eq
  result /g_Na get 6 ToUnitTestPrecision 19000 eq and
  result /g_K  get 6 ToUnitTestPrecision 5000 eq and
  result /g_L  get 6 ToUnitTestPrecision 9 eq and
  result /C_m  get 6 ToUnitTestPrecision 110 eq and
  result /E_Na get 6 ToUnitTestPrecision 40 eq and
  result /E_K  get 6 ToUnitTestPrecision -80 eq and
  result /E_L  get 6 ToUnitTestPrecision -70 eq and
  result /E_ex get 6 ToUnitTestPrecision  1 eq and
  result /E_in get 6 ToUnitTestPrecision -90 eq and
  result /tau_syn_ex get 6 ToUnitTestPrecision 0.3 eq and
  result /tau_syn_in get 6 ToUnitTestPrecision 3 eq and
  result /I_e get 6 ToUnitTestPrecision 1 eq and
} assert_or_die

%% Test: Handling of events

% CurrentEvent
/dc_generator Create /dc_gen Set
dc_gen << /amplitude 100.0 >> SetStatus

% SpikeEvent
/spike_generator Create /sg Set
sg << /precise_times false /spike_times [0.1 1.2] >> SetStatus

% PotentialRequest
/voltmeter Create /vm Set
vm << /withtime true  /time_in_steps true /interval h >> SetStatus

/spike_detector Create /sp_det Set
sp_det << /withtime true /withgid true /time_in_steps true >> SetStatus

% SynapticConductanceRequest
/multimeter Create /mm Set
mm << /withtime true /time_in_steps true /interval h /record_from [/g_ex /g_in] >> SetStatus

sg neuron Connect
dc_gen neuron Connect
vm neuron Connect
mm neuron Connect
neuron sp_det Connect

%% Test: Simulation
5 Simulate

{
  vm [/events [/times /V_m]] get cva     % array of recorded data
  6 ToUnitTestPrecision Transpose dup == % to precision of reference
  [[1 3.919340e+01] [2 3.850370e+01] [3 3.315630e+01] [4 2.217610e+01]
   [5 7.131720e+00] [6 -8.728460e+00] [7 -2.312210e+01] [8 -3.595260e+01]
   [9 -5.182590e+01] [10 -6.699940e+01] [11 -7.398330e+01] [12 -7.647150e+01]
   [13 -7.748650e+01] [14 -7.793770e+01] [15 -7.813580e+01] [16 -7.820390e+01]
   [17 -7.819780e+01] [18 -7.814580e+01] [19 -7.806380e+01] [20 -7.796150e+01]
   [21 -7.784520e+01] [22 -7.771910e+01] [23 -7.752600e+01] [24 -7.734640e+01]
   [25 -7.717640e+01] [26 -7.701340e+01] [27 -7.685560e+01] [28 -7.670190e+01]
   [29 -7.655140e+01] [30 -7.640350e+01] [31 -7.625770e+01] [32 -7.611370e+01]
   [33 -7.597140e+01] [34 -7.583060e+01] [35 -7.569110e+01] [36 -7.555300e+01]
   [37 -7.541600e+01] [38 -7.528030e+01] [39 -7.514570e+01] [40 -7.501230e+01]]
  eq 
} assert_or_die

{
  mm [/events [/times /g_ex /g_in]] get cva   % array of recorded data
  6 ToUnitTestPrecision Transpose dup ==      % to precision of reference
  [[1 0 0] [2 0 0] [3 0 0] [4 0 0] [5 0 0] [6 0 0] [7 0 0] [8 0 0] [9 0 0]
   [10 0 0] [11 1 0] [12 7.165310e-01 0] [13 5.134160e-01 0] [14 3.678790e-01 0]
   [15 2.635960e-01 0] [16 1.888750e-01 0] [17 1.353340e-01 0] [18 9.697120e-02 0]
   [19 6.948280e-02 0] [20 4.978650e-02 0] [21 3.567350e-02 0] [22 1.025560e+00 0]
   [23 7.348450e-01 0] [24 5.265390e-01 0] [25 3.772810e-01 0] [26 2.703330e-01 0]
   [27 1.937020e-01 0] [28 1.387930e-01 0] [29 9.944960e-02 0] [30 7.125860e-02 0]
   [31 5.105890e-02 0] [32 3.658530e-02 0] [33 2.621440e-02 0] [34 1.878340e-02 0]
   [35 1.345890e-02 0] [36 9.643710e-03 0] [37 6.910010e-03 0] [38 4.951230e-03 0]
   [39 3.547710e-03 0] [40 2.542040e-03 0]] eq
} assert_or_die

{
  sp_det [/events /times] get cva dup ==
  [2 3 4 5 6 7] eq 
} assert_or_die
