/*
 *  test_cont_delay_synapse.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_cont_delay_synapse - test of synapse with continuous delay

Synopsis: (test_cont_delay_synapse) run -> -

Description:

 A minimal test for the continuous delay synapse.
 
FirstVersion: June 2015
Author: Plesser
References:
SeeAlso: cont_delay_synapse
*/

(unittest) run
/unittest using

M_ERROR setverbosity

% Case 1: Delay compatible with resolution, same result as with normal synapse expected
{
  ResetKernel
  0 << /resolution 1.0 >> SetStatus
  
  /sg /spike_generator << /precise_times true /spike_times [ 2.0 5.5 ] >> Create def
  /n  /iaf_psc_delta_canon Create def
  /sd /spike_detector << /precise_times true /record_to [ /memory ] >> Create def
  
  sg n 100. 1.0 /cont_delay_synapse Connect
  n sd Connect
  
  10 Simulate
  
  % expected output spike times: 3.0, 6.5
  sd GetStatus /events/times :: cva [ 3.0 6.5 ] eq
}
assert_or_die


% Case 2: Delay not compatible with resolution, set delay as default
{
  ResetKernel
  0 << /resolution 1.0 >> SetStatus
  
  /sg /spike_generator << /precise_times true /spike_times [ 2.0 5.5 ] >> Create def
  /n  /iaf_psc_delta_canon Create def
  /sd /spike_detector << /precise_times true /record_to [ /memory ] >> Create def
  
  /cont_delay_synapse << /weight 100. /delay 1.7 >> SetDefaults
  sg n /cont_delay_synapse Connect
  n sd Connect
  
  10 Simulate
  
  % expected output spike times: 3.7, 7.2
  sd GetStatus /events/times :: cva [ 3.7 7.2 ] eq
}
assert_or_die


% Case 3: Delay not compatible with resolution, explicitly set delay
{
  ResetKernel
  0 << /resolution 1.0 >> SetStatus
  
  /sg /spike_generator << /precise_times true /spike_times [ 2.0 5.5 ] >> Create def
  /n  /iaf_psc_delta_canon Create def
  /sd /spike_detector << /precise_times true /record_to [ /memory ] >> Create def
  
  sg n 100. 1.0 /cont_delay_synapse Connect
  << /source [ sg ] /synapse_model /cont_delay_synapse >> GetConnections
     { << /delay 1.7 >> SetStatus } 
  forall

  n sd Connect
  
  10 Simulate
  
  % expected output spike times: 3.7, 7.2
  sd GetStatus /events/times :: cva [ 3.7 7.2 ] eq
}
assert_or_die


% Case 4: Ensure NEST prohibits delays shorter than resolution
{
  ResetKernel
  0 << /resolution 1.0 >> SetStatus
  
  /sg /spike_generator << /precise_times true /spike_times [ 2.0 5.5 ] >> Create def
  /n  /iaf_psc_delta_canon Create def
  
  sg n 100. 1.0 /cont_delay_synapse Connect
  << /source [ sg ] /synapse_model /cont_delay_synapse >> GetConnections
     { << /delay 0.7 >> SetStatus } 
  forall
}
fail_or_die
