Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
First try of a dataset for AIX, but seems to be broken
[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 /* Copyright (c) 2003,2004 Martin Quinson. All rights reserved.             */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 #include "gras.h"
11
12 XBT_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test");
13
14 int main(int argc,char *argv[]) {
15    xbt_dynar_t d;
16    xbt_error_t errcode;
17    int cpt,cursor;
18    double d1,d2;
19    
20    xbt_init_defaultlog(&argc,argv,"dynar.thresh=debug");
21
22    INFO0("==== Traverse the empty dynar");
23    d=xbt_dynar_new(sizeof(int),NULL);
24    xbt_dynar_foreach(d,cursor,cpt){
25      xbt_assert0(FALSE,
26              "Damnit, there is something in the empty dynar");
27    }
28    xbt_dynar_free(&d);
29    xbt_dynar_free(&d);
30
31    INFO0("==== Push/shift 5000 doubles");
32    d=xbt_dynar_new(sizeof(double),NULL);
33    for (cpt=0; cpt< 5000; cpt++) {
34      d1=(double)cpt;
35      xbt_dynar_push(d,&d1);
36    }
37    xbt_dynar_foreach(d,cursor,d2){
38      d1=(double)cursor;
39      xbt_assert2(d1 == d2,
40            "The retrieved value is not the same than the injected one (%f!=%f)",
41                   d1,d2);
42    }
43    for (cpt=0; cpt< 5000; cpt++) {
44      d1=(double)cpt;
45      xbt_dynar_shift(d,&d2);
46      xbt_assert2(d1 == d2,
47            "The retrieved value is not the same than the injected one (%f!=%f)",
48                   d1,d2);
49    }
50    xbt_dynar_free(&d);
51    xbt_dynar_free(&d);
52
53
54    INFO0("==== Unshift/pop 5000 doubles");
55    d=xbt_dynar_new(sizeof(double),NULL);
56    for (cpt=0; cpt< 5000; cpt++) {
57      d1=(double)cpt;
58      xbt_dynar_unshift(d,&d1);
59    }
60    for (cpt=0; cpt< 5000; cpt++) {
61      d1=(double)cpt;
62      xbt_dynar_pop(d,&d2);
63      xbt_assert2 (d1 == d2,
64            "The retrieved value is not the same than the injected one (%f!=%f)",
65                    d1,d2);
66    }
67    xbt_dynar_free(&d);
68    xbt_dynar_free(&d);
69
70
71
72    INFO0("==== Push 5000 doubles, insert 1000 doubles in the middle, shift everything");
73    d=xbt_dynar_new(sizeof(double),NULL);
74    for (cpt=0; cpt< 5000; cpt++) {
75      d1=(double)cpt;
76      xbt_dynar_push(d,&d1);
77    }
78    for (cpt=0; cpt< 1000; cpt++) {
79      d1=(double)cpt;
80      xbt_dynar_insert_at(d,2500,&d1);
81    }
82
83    for (cpt=0; cpt< 2500; cpt++) {
84      d1=(double)cpt;
85      xbt_dynar_shift(d,&d2);
86      xbt_assert2(d1 == d2,
87            "The retrieved value is not the same than the injected one at the begining (%f!=%f)",
88                   d1,d2);
89      DEBUG2("Pop %d, length=%lu",cpt, xbt_dynar_length(d));
90    }
91    for (cpt=999; cpt>=0; cpt--) {
92      d1=(double)cpt;
93      xbt_dynar_shift(d,&d2);
94      xbt_assert2 (d1 == d2,
95            "The retrieved value is not the same than the injected one in the middle (%f!=%f)",
96                    d1,d2);
97    }
98    for (cpt=2500; cpt< 5000; cpt++) {
99      d1=(double)cpt;
100      xbt_dynar_shift(d,&d2);
101      xbt_assert2 (d1 == d2,
102            "The retrieved value is not the same than the injected one at the end (%f!=%f)",
103                    d1,d2);
104    }
105    xbt_dynar_free(&d);
106    xbt_dynar_free(&d);
107
108
109    INFO0("==== Push 5000 double, remove 2000-4000. free the rest");
110    d=xbt_dynar_new(sizeof(double),NULL);
111    for (cpt=0; cpt< 5000; cpt++) {
112      d1=(double)cpt;
113      xbt_dynar_push(d,&d1);
114    }
115    for (cpt=2000; cpt< 4000; cpt++) {
116      d1=(double)cpt;
117      xbt_dynar_remove_at(d,2000,&d2);
118      xbt_assert2 (d1 == d2,
119            "Remove a bad value. Got %f, expected %f",
120                d2,d1);
121    }
122    xbt_dynar_free(&d);
123    xbt_dynar_free(&d);
124
125    xbt_exit();
126    return 0;
127 }