/*
 *  test_wfr_settings.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_wfr_settings - Tests the possible settings for the waveform relaxation method

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

    Description:
    The waveform relaxation method is used for iterative solution when connections
    without delay are present (e.g. gap junctions)
    
    This test ensures that 
    - use_wfr can only be set before nodes are created
    - wfr_comm_interval can only be set greater or equal the resolution and if use_wfr = true
    - setting of use_wfr = false sets wfr_comm_interval to resolution
    - wfr_comm_interval is updated when resolution is changed and use_wfr = false
    - use_wfr is set correctly in created nodes

    Author: Jan Hahne, March 2016
    SeeAlso: testsuite::test_hh_psc_alpha_gap, hh_psc_alpha_gap, gap_junction
  */

(unittest) run
/unittest using

M_ERROR setverbosity

ResetKernel

% Check if use_wfr can be set
{
  0 << /use_wfr false >> SetStatus
} pass_or_die

% Check that use_wfr cannot be set after nodes are created
{
  /iaf_neuron Create
  0 << /use_wfr true >> SetStatus
} fail_or_die

ResetKernel
0 << /use_wfr true >> SetStatus

% Check that wfr_comm_interval cannot be set lower as the resolution
{
  0 << /resolution 0.1 >> SetStatus
  0 << /wfr_comm_interval 0.05 >> SetStatus
} fail_or_die

ResetKernel

% Check that wfr_comm_interval cannot be set if use_wfr = false
{
  0 << /use_wfr false >> SetStatus
  0 << /wfr_comm_interval 0.5 >> SetStatus
} fail_or_die

ResetKernel
0 << /use_wfr true >> SetStatus
0 << /wfr_comm_interval 0.5 >> SetStatus

% Check that wfr_comm_interval is set to resolution if use_wfr = false is set
0 << /resolution 0.1
     /use_wfr false
  >> SetStatus

0 /wfr_comm_interval get /wfr_comm Set  

{wfr_comm 0.1 eq}assert_or_die


% Check that wfr_comm_interval is updated with resolution if use_wfr = false
0 << /resolution 0.2 >> SetStatus

0 /wfr_comm_interval get /wfr_comm Set  

{wfr_comm 0.2 eq}assert_or_die

ResetKernel

% Check that wfr_comm_interval is not updated with resolution if use_wfr = true
0 << /use_wfr true
     /wfr_comm_interval 2.0
  >> SetStatus

0 << /resolution 0.1 >> SetStatus  
  
0 /wfr_comm_interval get /wfr_comm Set  

{wfr_comm 2.0 eq}assert_or_die

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

ResetKernel

% Check that setting of use_wfr is correctly set in created nodes
% case use_wfr = true
0 << /use_wfr true >> SetStatus

/hh_psc_alpha_gap Create /neuron_gap Set

5.0 Simulate

neuron_gap /node_uses_wfr get /wfr Set

{wfr true eq}assert_or_die

ResetKernel

% case use_wfr = false
0 << /use_wfr false >> SetStatus

/hh_psc_alpha_gap Create /neuron_gap Set

5.0 Simulate

neuron_gap /node_uses_wfr get /wfr Set

{wfr false eq}assert_or_die

endusing
