/*
 *  issue-832.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-832 - The test ensures that the marker primary_end
    is still valid if particular connections are deleted

    Synopsis: (issue-832) run -> compares response to current step with reference data

    Description:
    The test is a modified version of test_hh_psc_alpha_gap.sli that also creates
    and deletes additional primary connections.
    Two neurons of whom one receives an constant input current of 200 pA are connected
    by gap_junction with an (unrealistic) high gap weight. The accurate functionality
    of the gap_junction feature is tested by measuring the membrane potential of the
    neuron without input current.

    The expected output is documented at the end of
    the script. The textual output of the voltmeter documented in this file
    can be regenerated by setting adding /to_screen true to the SetStatus
    call of vm below.

    Author:  October 2017, Hahne
    SeeAlso: testsuite::test_hh_psc_alpha_gap
*/

(unittest) run
/unittest using

% The following test needs the model hh_psc_alpha_gap, so
% this test should only run if we have GSL
skip_if_without_gsl

0.1 /h Set

ResetKernel

0 << 
      /local_num_threads 1 
      /resolution h
      /use_wfr true
      /wfr_tol 0.0001
      /wfr_interpolation_order 3
      /wfr_max_iterations 10
      /wfr_comm_interval 1.0
    >> SetStatus
    
/hh_psc_alpha_gap Create /neuron1 Set
/hh_psc_alpha_gap Create /neuron2 Set

/static_synapse /static1 CopyModel
/static_synapse /static2 CopyModel

neuron1
<< 
  /I_e 200.
>> SetStatus

/voltmeter Create /vm Set
vm << /withtime true  /time_in_steps true /interval h >> SetStatus

[neuron1] [neuron2]
<< /rule /one_to_one /make_symmetric true >>
<< /model /gap_junction /weight 20.0 >>  Connect

vm neuron2     1.0 h Connect

[neuron1] [neuron2]
<< /rule /one_to_one >>
<< /model /static1 /weight 0.0 >>  Connect

[neuron1] [neuron2]
<< /rule /one_to_one >>
<< /model /static2 /weight 0.0 >>  Connect

[neuron1] cvgidcollection [neuron2] cvgidcollection
<< /rule /all_to_all >>
<< /model /static1 >> Disconnect_g_g_D_D

20 Simulate

{                                             % reference data
 dup Transpose First /test_times Set         % times of reference 
                               
 vm [/events [/times /V_m]] get cva   % array of recorded data
  5 ToUnitTestPrecision                      % to precision of reference
  Transpose                                  % all recorded tuples
  {First test_times exch MemberQ } Select    % those with reference
 eq                                          % compare
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%
% Expected output of this program:
% 
% The output send to std::cout is a superposition of 
% the output of the voltmeter.
%
% time (in steps)  voltage (in mV)
[
[ 1    -69.592 ]
[ 2    -69.559 ]
[ 3    -69.507 ]
[ 4    -69.439 ]
[ 5    -69.357 ]
[ 6    -69.264 ]
[ 7    -69.162 ]
[ 8    -69.051 ]
[ 9    -68.933 ]
[ 10   -68.809 ]
[ 11   -68.681 ]
[ 12   -68.548 ]
[ 13   -68.413 ]
[ 14   -68.276 ]
[ 15   -68.136 ] 
%
% ...
%
[ 117  -33.771 ]
[ 118  -24.103 ]
[ 119    8.7117 ]
[ 120   62.019 ]
[ 121   39.042 ]
[ 122   27.485 ]
[ 123   18.856 ]
[ 124   11.201 ]
[ 125    3.6210 ]
[ 126   -4.6956 ]
[ 127  -15.006 ]
[ 128  -29.464 ]
[ 129  -49.786 ]
[ 130  -71.323 ]
[ 131  -83.787 ]
% 
% ...
%   
[ 190  -71.023 ]
[ 191  -70.833 ]
[ 192  -70.647 ]
[ 193  -70.466 ]
[ 194  -70.289 ]
[ 195  -70.116 ]
[ 196  -69.948 ]
[ 197  -69.783 ]
[ 198  -69.622 ]
[ 199  -69.464 ]
]   

exch assert_or_die


