Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Current state. See changelog, sorry, I'm out of time
[simgrid.git] / testsuite / xbt / dynar_double.c
1 /* $Id$ */
2
3 /* dynar_double: A test case for the dynar using doubles as content         */
4
5 /* Authors: Martin Quinson                                                  */
6 /* Copyright (C) 2003 the OURAGAN project.                                  */
7
8 /* This program is free software; you can redistribute it and/or modify it
9    under the terms of the license (GNU LGPL) which comes with this package. */
10
11 #include <stdio.h>
12 #include <gras.h>
13
14 GRAS_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test");
15
16 int main(int argc,char *argv[]) {
17    gras_dynar_t *d;
18    gras_error_t errcode;
19    int cpt,cursor;
20    double d1,d2;
21    
22    gras_init_defaultlog(&argc,argv,"dynar.thresh=debug");
23
24    INFO0("==== Traverse the empty dynar");
25    d=gras_dynar_new(sizeof(int),NULL);
26    gras_dynar_foreach(d,cursor,cpt){
27      gras_assert0(FALSE,
28              "Damnit, there is something in the empty dynar");
29    }
30    gras_dynar_free(d);
31
32    INFO0("==== Push/shift 5000 doubles");
33    d=gras_dynar_new(sizeof(double),NULL);
34    for (cpt=0; cpt< 5000; cpt++) {
35      d1=(double)cpt;
36      gras_dynar_push(d,&d1);
37    }
38    gras_dynar_foreach(d,cursor,d2){
39      d1=(double)cursor;
40      gras_assert2(d1 == d2,
41            "The retrieved value is not the same than the injected one (%f!=%f)",
42                   d1,d2);
43    }
44    for (cpt=0; cpt< 5000; cpt++) {
45      d1=(double)cpt;
46      gras_dynar_shift(d,&d2);
47      gras_assert2(d1 == d2,
48            "The retrieved value is not the same than the injected one (%f!=%f)",
49                   d1,d2);
50    }
51    gras_dynar_free(d);
52
53
54    INFO0("==== Unshift/pop 5000 doubles");
55    d=gras_dynar_new(sizeof(double),NULL);
56    for (cpt=0; cpt< 5000; cpt++) {
57      d1=(double)cpt;
58      gras_dynar_unshift(d,&d1);
59    }
60    for (cpt=0; cpt< 5000; cpt++) {
61      d1=(double)cpt;
62      gras_dynar_pop(d,&d2);
63      gras_assert2 (d1 == d2,
64            "The retrieved value is not the same than the injected one (%f!=%f)",
65                    d1,d2);
66    }
67    gras_dynar_free(d);
68
69
70
71    INFO0("==== Push 5000 doubles, insert 1000 doubles in the middle, shift everything");
72    d=gras_dynar_new(sizeof(double),NULL);
73    for (cpt=0; cpt< 5000; cpt++) {
74      d1=(double)cpt;
75      gras_dynar_push(d,&d1);
76    }
77    for (cpt=0; cpt< 1000; cpt++) {
78      d1=(double)cpt;
79      gras_dynar_insert_at(d,2500,&d1);
80    }
81
82    for (cpt=0; cpt< 2500; cpt++) {
83      d1=(double)cpt;
84      gras_dynar_shift(d,&d2);
85      gras_assert2(d1 == d2,
86            "The retrieved value is not the same than the injected one at the begining (%f!=%f)",
87                   d1,d2);
88      DEBUG2("Pop %d, length=%lu",cpt, gras_dynar_length(d));
89    }
90    for (cpt=999; cpt>=0; cpt--) {
91      d1=(double)cpt;
92      gras_dynar_shift(d,&d2);
93      gras_assert2 (d1 == d2,
94            "The retrieved value is not the same than the injected one in the middle (%f!=%f)",
95                    d1,d2);
96    }
97    for (cpt=2500; cpt< 5000; cpt++) {
98      d1=(double)cpt;
99      gras_dynar_shift(d,&d2);
100      gras_assert2 (d1 == d2,
101            "The retrieved value is not the same than the injected one at the end (%f!=%f)",
102                    d1,d2);
103    }
104    gras_dynar_free(d);
105
106
107    INFO0("==== Push 5000 double, remove 2000-4000. free the rest");
108    d=gras_dynar_new(sizeof(double),NULL);
109    for (cpt=0; cpt< 5000; cpt++) {
110      d1=(double)cpt;
111      gras_dynar_push(d,&d1);
112    }
113    for (cpt=2000; cpt< 4000; cpt++) {
114      d1=(double)cpt;
115      gras_dynar_remove_at(d,2000,&d2);
116      gras_assert2 (d1 == d2,
117            "Remove a bad value. Got %f, expected %f",
118                d2,d1);
119    }
120    gras_dynar_free(d);
121
122    gras_exit();
123    return 0;
124 }