/*
 *  ticket-520.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-520 - Ensure that multimeter returns correct number of time points in accumulator mode

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

Description:
When running in accumulator mode, multimeter must pick up the times array from only one thread,
so that value and times arrays have the same length.
 
Author: Hans Ekkehard Plesser, 2011-06-17
 */

(unittest) run
/unittest using

M_ERROR setverbosity

% test in non-accumulating mode, one mm
{
  ResetKernel

  0 << /total_num_virtual_procs 2 /local_num_threads 2 >> SetStatus
  
  /n1 /iaf_neuron << /I_e 100. >> Create def
  /n2 /iaf_neuron << /I_e 100. >> Create def
  /m1 /multimeter << /record_from [/V_m] /withtime true /withgid true >> Create def
  m1 n1 Connect
  m1 n2 Connect

  10 Simulate
 
  (M1: ) ==only
  m1 [/events [/V_m /times]] get dup ==
  
  % check that V_m and times arrays have same length
  arrayload 2 eq assert
  cva length exch cva length eq  
}
assert_or_die

% test in accumulating mode, one mm
{
  ResetKernel

  0 << /total_num_virtual_procs 2 /local_num_threads 2 >> SetStatus
  
  /n1 /iaf_neuron Create def
  /n2 /iaf_neuron Create def
  /m1 /multimeter << /record_from [/V_m] /withtime true /withgid false /to_accumulator true >> Create def
  m1 n1 Connect
  m1 n2 Connect

  10 Simulate

  (Acc M1: ) ==only
  m1 [/events [/V_m /times]] get dup ==

  % check that V_m and times arrays have same length
  arrayload 2 eq assert
  cva length exch cva length eq  
}
assert_or_die


% test in non-accumulating mode, two mm
{
  ResetKernel

  0 << /total_num_virtual_procs 2 /local_num_threads 2 >> SetStatus
  
  /n1 /iaf_neuron << /I_e 100. >> Create def
  /n2 /iaf_neuron << /I_e 100. >> Create def
  /m1 /multimeter << /record_from [/V_m] /withtime true /withgid true >> Create def
  /m2 /multimeter << /record_from [/V_m] /withtime true /withgid true >> Create def
  m1 n1 Connect
  m2 n2 Connect

  10 Simulate
 
  (M1: ) ==only
  m1 [/events [/V_m /times]] get dup ==
  % check that V_m and times arrays have same length
  arrayload 2 eq assert
  cva length exch cva length eq  

  (M2: ) ==only
  m2 [/events [/V_m /times]] get dup ==
  % check that V_m and times arrays have same length
  arrayload 2 eq assert
  cva length exch cva length eq  

  and  
}
assert_or_die

% test in accumulating mode, two mm
{
  ResetKernel

  0 << /total_num_virtual_procs 2 /local_num_threads 2 >> SetStatus
  
  /n1 /iaf_neuron Create def
  /n2 /iaf_neuron Create def
  /m1 /multimeter << /record_from [/V_m] /withtime true /withgid false /to_accumulator true >> Create def
  /m2 /multimeter << /record_from [/V_m] /withtime true /withgid false /to_accumulator true >> Create def
  m1 n1 Connect
  m2 n2 Connect

  10 Simulate

  (Acc M1: ) ==only
  m1 [/events [/V_m /times]] get dup ==
  % check that V_m and times arrays have same length
  arrayload 2 eq assert
  cva length exch cva length eq  

  (Acc M2: ) ==only
  m2 [/events [/V_m /times]] get dup ==
  % check that V_m and times arrays have same length
  arrayload 2 eq assert
  cva length exch cva length eq  

  and  
}
assert_or_die

% --- 
% Same all over again, but with time stamps
% test in non-accumulating mode, one mm
{
  ResetKernel

  0 << /total_num_virtual_procs 2 /local_num_threads 2 >> SetStatus
  
  /n1 /iaf_neuron << /I_e 100. >> Create def
  /n2 /iaf_neuron << /I_e 100. >> Create def
  /m1 /multimeter << /record_from [/V_m] /withtime true /time_in_steps true /withgid true >> Create def
  m1 n1 Connect
  m1 n2 Connect

  10 Simulate
 
  (M1: ) ==only
  m1 [/events [/V_m /times]] get dup ==
  
  % check that V_m and times arrays have same length
  arrayload 2 eq assert
  cva length exch cva length eq  
}
assert_or_die

% test in accumulating mode, one mm
{
  ResetKernel

  0 << /total_num_virtual_procs 2 /local_num_threads 2 >> SetStatus
  
  /n1 /iaf_neuron Create def
  /n2 /iaf_neuron Create def
  /m1 /multimeter << /record_from [/V_m] /withtime true /time_in_steps true /withgid false /to_accumulator true >> Create def
  m1 n1 Connect
  m1 n2 Connect

  10 Simulate

  (Acc M1: ) ==only
  m1 [/events [/V_m /times]] get dup ==

  % check that V_m and times arrays have same length
  arrayload 2 eq assert
  cva length exch cva length eq  
}
assert_or_die


% test in non-accumulating mode, two mm
{
  ResetKernel

  0 << /total_num_virtual_procs 2 /local_num_threads 2 >> SetStatus
  
  /n1 /iaf_neuron << /I_e 100. >> Create def
  /n2 /iaf_neuron << /I_e 100. >> Create def
  /m1 /multimeter << /record_from [/V_m] /withtime true /time_in_steps true /withgid true >> Create def
  /m2 /multimeter << /record_from [/V_m] /withtime true /time_in_steps true /withgid true >> Create def
  m1 n1 Connect
  m2 n2 Connect

  10 Simulate
 
  (M1: ) ==only
  m1 [/events [/V_m /times]] get dup ==
  % check that V_m and times arrays have same length
  arrayload 2 eq assert
  cva length exch cva length eq  

  (M2: ) ==only
  m2 [/events [/V_m /times]] get dup ==
  % check that V_m and times arrays have same length
  arrayload 2 eq assert
  cva length exch cva length eq  

  and  
}
assert_or_die

% test in accumulating mode, two mm
{
  ResetKernel

  0 << /total_num_virtual_procs 2 /local_num_threads 2 >> SetStatus
  
  /n1 /iaf_neuron Create def
  /n2 /iaf_neuron Create def
  /m1 /multimeter << /record_from [/V_m] /withtime true /time_in_steps true /withgid false /to_accumulator true >> Create def
  /m2 /multimeter << /record_from [/V_m] /withtime true /time_in_steps true /withgid false /to_accumulator true >> Create def
  m1 n1 Connect
  m2 n2 Connect

  10 Simulate

  (Acc M1: ) ==only
  m1 [/events [/V_m /times]] get dup ==
  % check that V_m and times arrays have same length
  arrayload 2 eq assert
  cva length exch cva length eq  

  (Acc M2: ) ==only
  m2 [/events [/V_m /times]] get dup ==
  % check that V_m and times arrays have same length
  arrayload 2 eq assert
  cva length exch cva length eq  

  and  
}
assert_or_die



endusing