/*
 *  test_DoubleVector_IntVector.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_DoubleVector_IntVector.sli - test vector operations

Synopsis: (test_DoubleVector_IntVector) run -> 

Description:

This test checks the basic operations on IntVector and DoubleVector objects. Tested are
 - conversion and creation
 - arange, ones and zeros 
 - put and get
 - Map and forall
 - add, mul 

Author:  December 2012, Gewaltig
SeeAlso: testsuite::test_iaf_psp, testsuite::test_iaf_ps_dc_accuracy
*/

(unittest) run
/unittest using

M_ERROR setverbosity

% test manual constructors and conversion
{ [1 2 3 4] array2intvector <# 1 2 3 4 #> eq } assert_or_die
{ [1.0 2.0 3.0 4.0] array2doublevector <. 1.0 2.0 3.0 4.0 .> eq} assert_or_die

% test ranges - all three cases for both vector types 

{[1 2 3 4] array2intvector [4] arange eq }assert_or_die
{[1.0 2.0 3.0 4.0] array2doublevector [4.0] arange eq } assert_or_die

{[ 2 3 4] array2intvector [2 4] arange eq} assert_or_die
{[ 2.0 3.0 4.0] array2doublevector [2.0 4.0]  arange eq} assert_or_die

{[4 3 2 1] array2intvector [4 1 -1] arange eq } assert_or_die
{[4.0 3.0 2.0 1.0] array2doublevector [4.0 1.0 -1.0] arange eq } assert_or_die

% cv_ functions are permissive and implicitly convert types
{[1 2 3 4] cv_dv [4.0] arange eq } assert_or_die
{[1 2 3 4] cv_iv [4] arange eq } assert_or_die

% test element access put and get

{  [2 23 55 23 89 21 -1 0 -12.12 ] cv_iv  8 get -12 eq } assert_or_die 
{  [2 23 55 23 89 21 -1 0 -12.12 ] cv_iv  8 13 put 8 get 13 eq } assert_or_die 
{  [2 23 55 23 89 21 -1 0 -12.12 ] cv_dv  8 get -12.12 eq } assert_or_die 
{  [2 23 55 23 89 21 -1 0 -12.12 ] cv_dv  8 13.56 put 8 get 13.56 eq } assert_or_die 

{  [2 23 55 23 89 21 -1 0 -12.12 ] cv_iv  <# 2 5 7 #> get <# 55 21 0 #> eq } assert_or_die 
{  [2 23 55 23 89 21 -1 0 -12.12 ] cv_dv  <# 2 5 7 #> get <. 55.0 21.0 0.0 .> eq } assert_or_die 

% test loops
{ [2 23 55 23 89 21 -1 0 -12.12 ] cv_iv { 2 mul   } Map <# 4 46 110 46 178 42 -2 0 -24 #>  eq } assert_or_die 
{ [2 23 55 23 89 21 -1 0 -12.12 ] cv_dv { 2.0 mul } Map <. 4. 46. 110. 46. 178. 42. -2. 0. -24.24 .>  eq } assert_or_die 

% test loops with basic math
{ 0 10 ones { add } forall 10. eq }  assert_or_die
{ 0 10 ones 2.0 mul { add } forall 20. eq }  assert_or_die
{ 0 10 ones dup add { add } forall 20. eq }  assert_or_die
{ 0 10 zeros 1.0 add { add } forall 10. eq }  assert_or_die
{ 0 10 ones_iv { add } forall 10 eq }  assert_or_die
{ 0 10 ones_iv 2 mul { add } forall 20 eq }  assert_or_die
{ 0 10 ones_iv dup add { add } forall 20 eq }  assert_or_die
{ 0 10 zeros_iv 1 add { add } forall 10 eq }  assert_or_die
