1 /* -*- mode: C -*-  */
2 /*
3    IGraph library.
4    Copyright (C) 2006-2012  Gabor Csardi <csardi.gabor@gmail.com>
5    334 Harvard street, Cambridge, MA 02139 USA
6 
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11 
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20    02110-1301 USA
21 
22 */
23 
24 #include <igraph.h>
25 #include <stdio.h>
26 
27 #include "test_utilities.inc"
28 
print_array(const igraph_array3_t * a)29 void print_array(const igraph_array3_t *a) {
30     long int i, j, k;
31     for (k = 0; k < igraph_array3_n(a, 3); k++) {
32         for (i = 0; i < igraph_array3_n(a, 1); i++) {
33             for (j = 0; j < igraph_array3_n(a, 2); j++) {
34                 printf(" %g", (double) ARRAY3(*a, i, j, k));
35             }
36             printf("\n");
37         }
38             printf("\n");
39     }
40 }
41 
main()42 int main() {
43     igraph_array3_t a;
44     long int i, j, k;
45     long int s = 1;
46 
47     igraph_array3_init(&a, 5, 4, 3);
48     igraph_array3_destroy(&a);
49 
50     igraph_array3_init(&a, 5, 4, 3);
51     print_array(&a);
52     IGRAPH_ASSERT(igraph_array3_n(&a, 1) == 5);
53     IGRAPH_ASSERT(igraph_array3_n(&a, 2) == 4);
54     IGRAPH_ASSERT(igraph_array3_n(&a, 3) == 3);
55     igraph_array3_destroy(&a);
56 
57     igraph_array3_init(&a, 5, 4, 3);
58     for (k = 0; k < igraph_array3_n(&a, 3); k++) {
59         for (j = 0; j < igraph_array3_n(&a, 2); j++) {
60             for (i = 0; i < igraph_array3_n(&a, 1); i++) {
61                 ARRAY3(a, i, j, k) = s++;
62             }
63         }
64     }
65     print_array(&a);
66     print_vector_format(&a.data, stdout, "%g");
67     igraph_array3_destroy(&a);
68 
69     VERIFY_FINALLY_STACK();
70 
71     return 0;
72 }
73