/*
 *  test_pp_pop_psc_delta.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_pp_pop_psc_delta - sli script for test of pp_pop_psc_delta

Synopsis: (test_pp_pop_psc_delta) run -> compare numbers of generated spikes of the model and a group of pp_psc_delta neurons

Description:
 
 This script simulate three point process population models with different sets of parameters. After each simulation, it compares
 the number of generated spikes by the model and the same quantity of a group of pp_psc_delta neurons. The parameters of 
 pp_psc_delta neurons (including the number of neurons) are the same as represented in the point process population model. 
 The ratio of number of spikes must not be less than 1-err and greater than 1+err. Here we choose err=0.2.



Author:  May 2014, Setareh, Deger
SeeAlso: pp_pop_psc_delta, testsuite::test_pp_psc_delta

*/


(unittest) run
/unittest using


0.2 /err Set
10000.0 /T Set


/first_test
{
   
    ResetKernel
    0 << 
       /resolution 1.0
     >> SetStatus

    /pp_pop_psc_delta Create /node Set

    <<
      /N 500
      /rho_0 1.0
      /delta_u 1.0
      /tau_m  10.0
      /C_m   15.0
      /tau_eta [10.0 300.0]
      /val_eta [3.0  1.0  ]
      /len_kernel  5.0
      /I_e -0.5 
    >> /params_pop Set
    
    node params_pop SetStatus

    /dc_generator Create /current Set

    <<
       /amplitude 3.0
    >> /params_cur Set

    current  params_cur SetStatus
    
    /spike_detector Create /sd Set

    current node Connect
    node sd Connect
    T Simulate
    
    sd GetStatus /n_events get

    13179.0   % expected number of generated spikes (generated by a group of pp_psc_delta neurons with the same paramter set)
    div /ratio Set
    1.0 err sub ratio lt
    ratio 1.0 err add lt
    and assert_or_die
    
} def


/second_test
{
   
    ResetKernel
    0 << 
       /resolution 1.0
     >> SetStatus

    /pp_pop_psc_delta Create /node Set

    <<
      /N 300
      /rho_0 1.0
      /delta_u 5.0
      /tau_m  9.0
      /C_m   5.0
      /tau_eta [15.0 200.0]
      /val_eta [4.0  2.0  ]
      /len_kernel  5.0
      /I_e 1.0 
    >> /params_pop Set
    
    node params_pop SetStatus

    /dc_generator Create /current Set

    <<
       /amplitude 3.0
    >> /params_cur Set

    current  params_cur SetStatus
    
    /spike_detector Create /sd Set

    current node Connect
    node sd Connect
    T Simulate
    
    sd GetStatus /n_events get

    9667.0   % expected number of generated spikes (generated by a group of pp_psc_delta neurons with the same paramter set)
    div /ratio Set
    1.0 err sub ratio lt
    ratio 1.0 err add lt
    and assert_or_die
    
} def


/third_test
{
   
    ResetKernel
    0 << 
       /resolution 1.0
     >> SetStatus

    /pp_pop_psc_delta Create /node Set

    <<
      /N 400
      /rho_0 1.0
      /delta_u 3.0
      /tau_m  5.0
      /C_m   10.0
      /tau_eta [25.0 100.0]
      /val_eta [5.0  1.0  ]
      /len_kernel  7.0
      /I_e 8.0 
    >> /params_pop Set
    
    node params_pop SetStatus

    /dc_generator Create /current Set

    <<
       /amplitude 3.0
    >> /params_cur Set

    current  params_cur SetStatus
    
    /spike_detector Create /sd Set

    current node Connect
    node sd Connect
    T Simulate
    
    sd GetStatus /n_events get

    19128.0   % expected number of generated spikes (generated by a group of pp_psc_delta neurons with the same paramter set)
    div /ratio Set
    1.0 err sub ratio lt
    ratio 1.0 err add lt
    and assert_or_die
    
} def

first_test
second_test
third_test
