/*
 *  ticket-541.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::ticket-541 - Regression test for aeif_cond_alpha reset

Synopsis: (ticket-541) run -> NEST exits if test fails

Description:
This test is based on an original Python demonstrator by Abigail Morrison
(see #541).
Per r10018, no-one can reproduce the error and the test is very slow.
Therefore, this test resides in manualtests.

Author: Yury V. Zaytsev, Hans E. Plesser, 2012-11-29
 */

(unittest) run
/unittest using

M_ERROR setverbosity

/test_reset {

  /connect_neurons Set
  /use_aeif Set

  ResetKernel

  0 <<
    /resolution     0.1
    /print_time     false
    /rng_seeds      [ 123 ]
    /overwrite_files true
  >> SetStatus

  /poisson_generator << /rate 10000. >> SetDefaults
  /background /poisson_generator Create def

  /msn_model use_aeif {
    <<
      /C_m        200.
      /Delta_T      2.
      /E_L        -58.
      /E_ex         0.
      /E_in       -64.
      /I_e          0.
      /V_peak       0.
      /V_reset    -46.
      /V_th       -50.
      /a            1.
      /b          100.
      /g_L         10.
      /t_ref        0.
      /tau_syn_ex   0.3
      /tau_syn_in   2.
      /tau_w      200.
      /w            0.
      /gsl_error_tol 1e-9
    >> /aeif_cond_alpha
  } {
    <<
      /V_th -55.
    >> /iaf_psc_exp
  } ifelse rollu CopyModel

  /neurons [
    background 1 add
    /msn_model 500 Create 
  ] Range def

  connect_neurons {
    neurons
    neurons
    << /rule /fixed_outdegree /outdegree 50 >>
    << /weight 14500. -0.0003 mul /delay 2. >>
    Connect
  } if

  [background]
  neurons
  << /rule /all_to_all >>
  << /weight 5000. 0.00346 mul /delay 1. >>
  Connect

  /meter /spike_detector Create def
  meter <<
    /withgid    true
    /withtime   true
    /to_file    false
    /to_memory  true
  >> SetStatus

  neurons [meter] Connect

  /run_simulation {
    /label Set
    ResetNetwork
    0 << /time 0.0 /rng_seeds [ 123 ] >> SetStatus
    meter << /n_events 0 /label label >> SetStatus
    500 Simulate 
    /results meter GetStatus def
  } def

  (sr1) run_simulation
  /ev1 results/events/senders :: def
  /st1 results/events/times   :: def

  (sr2) run_simulation
  /ev2 results/events/senders :: def
  /st2 results/events/times   :: def

  ev1 cva ev2 cva eq 
  st1 cva st2 cva eq 
  and 
} def

(true true) ==
true  true  test_reset assert_or_die

(true false) ==
true  false test_reset assert_or_die

(false true) ==
false true  test_reset assert_or_die

(false false) ==
false false test_reset assert_or_die

endusing
