/*
 *  test_spike_det_reset.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_spike_det_reset - test if resetting works on spike_detector

Synopsis: (test_spike_det_reset) run -> dies if assertion fails

Description:
	Feeds spike detector with given set of spikes, checks if they
	are recorded properly to memory, then resets, then records a
	few more and checks.

Author: August 2008, Plesser
SeeAlso: spike_detector
*/

/unittest (7471) require
/unittest using

{
  ResetKernel

  /spike_generator Create /sg Set
  sg << /precise_times false /spike_times [ 10. 200. 10. ] Range >> SetStatus

  /spike_detector Create /sd Set
  sd << /record_to [/memory] /withtime true /withgid true >> SetStatus

  sg sd Connect

  /res [] def  % array to collect bool results

  105 Simulate  % should record spikes 10..100 -> 10 spikes
  sd [ /n_events ] get                   10 eq res exch append /res Set
  sd [ /events /senders ] get cva length 10 eq res exch append /res Set
  sd [ /events /times   ] get cva length 10 eq res exch append /res Set
  
  % reset
  sd << /n_events 0 >> SetStatus
  sd [ /n_events ] get                   0 eq res exch append /res Set
  sd [ /events /senders ] get cva length 0 eq res exch append /res Set
  sd [ /events /times   ] get cva length 0 eq res exch append /res Set

  % simulate more
  55 Simulate % spikes 110 .. 150 -> 5 spikes
  sd [ /n_events ] get                   5 eq res exch append /res Set
  sd [ /events /senders ] get cva length 5 eq res exch append /res Set
  sd [ /events /times   ] get cva length 5 eq res exch append /res Set

  % combine results
  res First res Rest { and } Fold

} assert_or_die

endusing