/*
 *  issue-740.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::issue-740

Synopsis: (issue-740) run -> NEST exits if test fails

Description:
This test ensures that step_current_generator can only be parameterized
with amplitude_times that are strictly increasing after conversion to
time steps.

Author: Hans Ekkehard Plesser
FirstVersion: August 2017
*/

(unittest) run
/unittest using

M_ERROR setverbosity

/run_sim [ /doubletype /booltype ]  % resolution, allow_offgrid
{
  /offgrid Set
  /res Set
  ResetKernel
  0 << /tics_per_ms 1024. /resolution res >> SetStatus
  
  /scg /step_current_generator 
    << /amplitude_times  [ 1. 1.0625 1.125 1.1875 1.25 2. 2.5 ]
       /amplitude_values [ 10. -20.  40.   -80.   160. -320. 640. ] 
       /allow_offgrid_times offgrid
    >> Create def
  scg /amplitude_times get ==
  /nrn /iaf_psc_alpha << /V_th 1e10 /C_m 1.0 /tau_m 1.0
                         /E_L 0.0 /V_m 0.0 /V_reset 0.0 >> Create def
  
  scg nrn Connect

  5 res div cvi res mul Simulate
}
def

% Test 1: Resolution finer than shortest interval
%         all intervals are multiple of resolution
(Test 1) ==
{
  2. -5 pow false run_sim
} pass_or_die

% Test 2: Resolution finer than shortest interval,
%         intervals not multiples or resolution
(Test 2) ==
{
  2. -10 pow 3. mul false run_sim
} fail_or_die

% Test 3: Resolution finer than shortest interval,
%         intervals not multiples or resolution,
%         allow off-grid
(Test 3) ==
{
  2. -10 pow 3. mul true run_sim
} pass_or_die

% Test 4: Resolution equal to shortest interval
(Test 4) ==
{
  2. -4 pow false run_sim
} pass_or_die

% Test 5: Resolution larger than shortest interval
(Test 5) ==
{
  2. -3 pow false run_sim
} fail_or_die

% Test 6: Resolution larger than shortest interval
%         off-grid allowed
(Test 6) ==
{
  2. -3 pow true run_sim
} fail_or_die

endusing
