/*
 *  test_syn_hom_wd.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_syn_hom_wd - sli script for test synapse with homogeneous weight and delay.

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

Description:
Test of the overall function of static_synapse_hom_wd.
A simple integrate-and-fire neuron is created. It is connected to a spike
generator and a voltmeter by static synapses with homogeneous weight and
delay.

FirstVersion: April 2008

Author: Moritz Helias, Susanne Kunkel
*/

/unittest (6688) require
/unittest using

1.0 /delay Set   % in ms

0.1 /h Set

ResetKernel

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

/spike_generator Create /sg Set

sg <<
     /precise_times false
     /origin 0.0            % in ms
     /spike_times [ 2.0 ]   % in ms
     /start 1.0             % in ms
     /stop 3.0              % in ms
   >> SetStatus

/iaf_neuron Create /neuron Set

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

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

/static_synapse_hom_wd
<<
    /weight 100.0
    /delay 1.0
>> SetDefaults

sg neuron /static_synapse_hom_wd Connect

vm neuron /static_synapse_hom_wd Connect

neuron sd /static_synapse_hom_wd Connect

7.0 Simulate

% function expecting testdata on stack
{                                            % reference data
 dup Transpose First /test_times Set         % times of reference 

 vm [/events [/times /V_m]] get cva   % array of recorded data
  6 ToUnitTestPrecision                      % to precision of reference
  Transpose                                  % all recorded tuples
  {First test_times exch MemberQ } Select    % those with reference
 eq                                          % compare
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%
% Expected output of this program:
% 
% The output send to std::cout is a superposition of the output of
% the voltmeter and the spike detector. Both, voltmeter and spike
% detector are connected to the same neuron.
%
% time (in steps)  voltage (in mV)
[
 [1 -70]
 [2 -70]
 [3 -70]
 [4 -70]
%
 [27 -70]
 [28 -70]
 [29 -70]
 [30 -70]
 [31 -6.999740e+01]
 [32 -6.998990e+01]
 [33 -6.997810e+01]
 [34 -6.996240e+01]
 [35 -6.994340e+01]
%
 [45 -6.964350e+01]
 [46 -6.960840e+01]
 [47 -6.957320e+01]
 [48 -6.953800e+01]
 [49 -6.950290e+01]
 [50 -6.946810e+01]
 [51 -6.943360e+01]
 [52 -6.939950e+01]
 [53 -6.936600e+01]
 [54 -6.933300e+01]
 [55 -6.930080e+01]
%
 [60 -6.915080e+01]
]

exch assert_or_die