/*
 *  test_count_connections.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_count_connections - Test connection counting for total
number of connections and specific types of connections.

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

Description: 
This test uses fixed-indegree Connect to connect a net of 100 neurons
to itself, with 100 connections per neuron, a total of 10000 connections.
It is checked whether the total number of connections and the number of
static connections equals 10000. Then additional 10000 connections of type
stdp_synapse are created. It is checked whether the total number of
connections is 20000 and the number of stdp connections is 10000.
 
Author: Susanne Kunkel, 2013-03-25
*/

% don't run this test if we didn't compile with OpenMP 
statusdict/threading :: (openmp) eq not {statusdict/exitcodes/success :: quit_i} if

(unittest) run
/unittest using

M_ERROR setverbosity

/N    100  def % number of neurons
/C    100  def % number of connections per neuron
/N_VP 4    def % number of virtual processes
/ConnExpected N C mul def

ResetKernel
0 << /total_num_virtual_procs N_VP >> SetStatus
  
/net /iaf_neuron [ N ] LayoutNetwork def
/nodes net GetGlobalNodes def
/local_nodes net GetLocalNodes def

nodes local_nodes << /rule /fixed_indegree /indegree C >> Connect

{ 0 /num_connections get ConnExpected eq } assert_or_die
{ /static_synapse GetDefaults /num_connections get ConnExpected eq } assert_or_die

nodes local_nodes << /rule /fixed_indegree /indegree C >> << /model /stdp_synapse >> Connect

{ 0 /num_connections get ConnExpected 2 mul eq } assert_or_die
{ /stdp_synapse GetDefaults /num_connections get ConnExpected eq } assert_or_die

endusing
