/*
 *  conngen_interface.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_conngen_interface - Test runability of all CGConnect variants

   Synopsis: (test_conngen_interface) run

   Description:

   Tests if all variants of CGConnect can be run. This test only checks the
   SLI part of the ConnectionGenerator interface. The PyNEST interface is
   tested in pynest/nest/tests/test_csa.py.

   FirstVersion: June 2016
   Author: Jochen Martin Eppler
   SeeAlso: CGConnect
 */

M_ERROR setverbosity

(unittest) run
/unittest using

% Only run the test if NEST was compiled with support for libneurosim
statusdict/have_libneurosim :: not { exit_test_gracefully } if 

% Tell the ConnectionGenerator interface, which implementation to use
(CSA) (libcsa.so) CGSelectImplementation

% Obtain a connectiongeneratortype object by parsing an XML definition
(<?xml version='1.0' encoding='UTF-8'?>\n)
(<CSA xmlns="http://software.incf.org/software/csa/1.0">) join
(<oneToOne/>) join
(</CSA>) join
CGParse /cg Set


% Test if the array variant works
ResetKernel
/iaf_psc_alpha 16 Create ;
cg [  1  2 ] [  3  4 ]                       CGConnect
cg [  5  6 ] [  7  8 ] << >>                 CGConnect
cg [  9 10 ] [ 11 12 ]       /static_synapse CGConnect
cg [ 13 14 ] [ 15 16 ] << >> /static_synapse CGConnect

<< /source [  1  2 ] >> GetConnections
  { GetStatus /target get } Map [  3  4 ] eq assert_or_die
<< /source [  5  6 ] >> GetConnections
  { GetStatus /target get } Map [  7  8 ] eq assert_or_die
<< /source [  9 10 ] >> GetConnections
  { GetStatus /target get } Map [ 11 12 ] eq assert_or_die
<< /source [ 13 14 ] >> GetConnections
  { GetStatus /target get } Map [ 15 16 ] eq assert_or_die


% Test if the intvector variant works
ResetKernel
/iaf_psc_alpha 16 Create ;
cg [  1  2 ] cv_iv [  3  4 ] cv_iv                       CGConnect
cg [  5  6 ] cv_iv [  7  8 ] cv_iv << >>                 CGConnect
cg [  9 10 ] cv_iv [ 11 12 ] cv_iv       /static_synapse CGConnect
cg [ 13 14 ] cv_iv [ 15 16 ] cv_iv << >> /static_synapse CGConnect

<< /source [  1  2 ] >> GetConnections
  { GetStatus /target get } Map [  3  4 ] eq assert_or_die
<< /source [  5  6 ] >> GetConnections
  { GetStatus /target get } Map [  7  8 ] eq assert_or_die
<< /source [  9 10 ] >> GetConnections
  { GetStatus /target get } Map [ 11 12 ] eq assert_or_die
<< /source [ 13 14 ] >> GetConnections
  { GetStatus /target get } Map [ 15 16 ] eq assert_or_die


% Test if the gidcollection variant works
/cvgc /cvgidcollection load def
ResetKernel
/iaf_psc_alpha 16 Create ;
cg [  1  2 ] cvgc [  3  4 ] cvgc                       CGConnect
cg [  5  6 ] cvgc [  7  8 ] cvgc << >>                 CGConnect
cg [  9 10 ] cvgc [ 11 12 ] cvgc       /static_synapse CGConnect
cg [ 13 14 ] cvgc [ 15 16 ] cvgc << >> /static_synapse CGConnect

<< /source [  1  2 ] >> GetConnections
  { GetStatus /target get } Map [  3  4 ] eq assert_or_die
<< /source [  5  6 ] >> GetConnections
  { GetStatus /target get } Map [  7  8 ] eq assert_or_die
<< /source [  9 10 ] >> GetConnections
  { GetStatus /target get } Map [ 11 12 ] eq assert_or_die
<< /source [ 13 14 ] >> GetConnections
  { GetStatus /target get } Map [ 15 16 ] eq assert_or_die
