Logo AND Algorithmique Numérique Distribuée

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