1#!/usr/bin/perl
2use strict;
3use warnings;
4use Test::More tests => 34;
5BEGIN { use_ok('li_carrays_cpp') }
6require_ok('li_carrays_cpp');
7
8# array_class
9{
10  my $length = 5;
11  my $xyArray = new li_carrays_cpp::XYArray($length);
12  for (my $i=0; $i<$length; $i++) {
13    my $xy = $xyArray->getitem($i);
14    $xy->{x} = $i*10;
15    $xy->{y} = $i*100;
16    $xyArray->setitem($i, $xy);
17  }
18  for (my $i=0; $i<$length; $i++) {
19    is($xyArray->getitem($i)->{x}, $i*10);
20    is($xyArray->getitem($i)->{y}, $i*100);
21  }
22}
23
24{
25  # global array variable
26  my $length = 3;
27  my $xyArrayPointer = $li_carrays_cpp::globalXYArray;
28  my $xyArray = li_carrays_cpp::XYArray::frompointer($xyArrayPointer);
29  for (my $i=0; $i<$length; $i++) {
30    my $xy = $xyArray->getitem($i);
31    $xy->{x} = $i*10;
32    $xy->{y} = $i*100;
33    $xyArray->setitem($i, $xy);
34  }
35  for (my $i=0; $i<$length; $i++) {
36    is($xyArray->getitem($i)->{x}, $i*10);
37    is($xyArray->getitem($i)->{y}, $i*100);
38  }
39}
40
41# array_functions
42{
43  my $length = 5;
44  my $abArray = li_carrays_cpp::new_ABArray($length);
45  for (my $i=0; $i<$length; $i++) {
46    my $ab = li_carrays_cpp::ABArray_getitem($abArray, $i);
47    $ab->{a} = $i*10;
48    $ab->{b} = $i*100;
49	li_carrays_cpp::ABArray_setitem($abArray, $i, $ab);
50  }
51  for (my $i=0; $i<$length; $i++) {
52    is(li_carrays_cpp::ABArray_getitem($abArray, $i)->{a}, $i*10);
53    is(li_carrays_cpp::ABArray_getitem($abArray, $i)->{b}, $i*100);
54  }
55  li_carrays_cpp::delete_ABArray($abArray);
56}
57
58{
59  # global array variable
60  my $length = 3;
61  my $abArray = $li_carrays_cpp::globalABArray;
62  for (my $i=0; $i<$length; $i++) {
63    my $ab = li_carrays_cpp::ABArray_getitem($abArray, $i);
64    $ab->{a} = $i*10;
65    $ab->{b} = $i*100;
66	li_carrays_cpp::ABArray_setitem($abArray, $i, $ab);
67  }
68  for (my $i=0; $i<$length; $i++) {
69    is(li_carrays_cpp::ABArray_getitem($abArray, $i)->{a}, $i*10);
70    is(li_carrays_cpp::ABArray_getitem($abArray, $i)->{b}, $i*100);
71  }
72}
73