Logo AND Algorithmique Numérique Distribuée

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