/*
 *  issue-211.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_threaded_neuron_device_connections - test for correct creation of neuron-neuron, neuron-device, device-neuron and device-device connections using multiple threads

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

Description:
this script creates connections between neurons and devices and checks whether the actually created connections coincide with the expected connections

Author: Jakob Jordan
FirstVersion: January 2016
SeeAlso:
*/

(unittest) run
/unittest using

skip_if_not_threaded

M_ERROR setverbosity

ResetKernel
0 << /total_num_virtual_procs 2 >> SetStatus

% create nodes
/n1 /iaf_psc_delta Create def
/n2 /iaf_psc_delta Create def
/n3 /iaf_psc_delta Create def
/d4 /spike_detector Create def
/g5 /spike_generator Create def
/v6 /volume_transmitter Create def
/stdp_dopamine_synapse << /vt v6 >> SetDefaults

% neuron-neuron
[n1 n2] [n3 n3] /one_to_one Connect
[n2 n3] [n1] Connect
n2 n1 << /weight 1. >> Connect

% neuron-device
[n1 n1] [d4 n3] /one_to_one Connect
[n2 n3] [d4] Connect
n2 d4 << /weight 1. >> Connect

% device-neuron
[g5 g5] [n2 n3] /one_to_one Connect
[g5 g5] [n1] Connect
g5 n3 << /weight 1. >> Connect

% device-device
[g5 g5] [d4] Connect
g5 d4 << /weight 1. >> Connect

% neuron-globally receiving device (volume transmitter)
n1 v6 Connect
n2 v6 Connect

/conn << >> GetConnections def

% expected connections with expected threads
/target_conn <[1 3 1] [2 3 1] [2 1 1] [3 1 1] [2 1 1] % neuron-neuron
              [1 4 1] [1 3 1] [2 4 0] [3 4 1] [2 4 0] % neuron-device
              [5 2 0] [5 3 1] [5 1 1] [5 1 1] [5 3 1] % device-neuron
              [5 4 0] [5 4 0] [5 4 0]                 % device-device
              [1 6 0] [1 6 1] [2 6 0] [2 6 1]> def    % neuron-globally receiving device

conn {
  target_conn exch cva [[1 2 3]] Part MemberQ assert
} forall
conn length_a target_conn length_a eq assert
