Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
use iterators
[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 int main(int argc,char *argv[]) {
15    gras_dynar_t *d;
16    gras_error_t errcode;
17    int cpt,cursor;
18    double d1,d2;
19    
20    fprintf(stderr,"==== Traverse the empty dynar\n");
21    TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL));
22    gras_dynar_foreach(d,cursor,cpt){
23      fprintf(stderr,
24              "Damnit, there is something in the empty dynar\n");
25      abort();
26    }
27    gras_dynar_free(d);
28
29    fprintf(stderr,"==== Push/shift 5000 doubles\n");
30    TRYFAIL(gras_dynar_new(&d,sizeof(double),NULL));
31    for (cpt=0; cpt< 5000; cpt++) {
32      d1=(double)cpt;
33      TRYFAIL(gras_dynar_push(d,&d1));
34    }
35    gras_dynar_foreach(d,cursor,d2){
36      d1=(double)cursor;
37      if (d1 != d2) {
38        fprintf(stderr,
39            "The retrieved value is not the same than the injected one (%f!=%f)\n",
40                d1,d2);
41        abort();
42      }
43    }
44    for (cpt=0; cpt< 5000; cpt++) {
45      d1=(double)cpt;
46      gras_dynar_shift(d,&d2);
47      if (d1 != d2) {
48        fprintf(stderr,
49            "The retrieved value is not the same than the injected one (%f!=%f)\n",
50                d1,d2);
51        abort();
52      }
53    }
54    gras_dynar_free(d);
55
56
57    fprintf(stderr,"==== Unshift/pop 5000 doubles\n");
58    TRYFAIL(gras_dynar_new(&d,sizeof(double),NULL));
59    for (cpt=0; cpt< 5000; cpt++) {
60      d1=(double)cpt;
61      TRYFAIL(gras_dynar_unshift(d,&d1));
62    }
63    for (cpt=0; cpt< 5000; cpt++) {
64      d1=(double)cpt;
65      gras_dynar_pop(d,&d2);
66      if (d1 != d2) {
67        fprintf(stderr,
68            "The retrieved value is not the same than the injected one (%f!=%f)\n",
69                d1,d2);
70        abort();
71      }
72    }
73    gras_dynar_free(d);
74
75
76
77    fprintf(stderr,"==== Push 5000 doubles, insert 1000 doubles in the middle, shift everything\n");
78    TRYFAIL(gras_dynar_new(&d,sizeof(double),NULL));
79    for (cpt=0; cpt< 5000; cpt++) {
80      d1=(double)cpt;
81      TRYFAIL(gras_dynar_push(d,&d1));
82    }
83    for (cpt=0; cpt< 1000; cpt++) {
84      d1=(double)cpt;
85      TRYFAIL(gras_dynar_insert_at(d,2500,&d1));
86    }
87
88    for (cpt=0; cpt< 2500; cpt++) {
89      d1=(double)cpt;
90      gras_dynar_shift(d,&d2);
91      if (d1 != d2) {
92        fprintf(stderr,
93            "The retrieved value is not the same than the injected one at the begining (%f!=%f)\n",
94                d1,d2);
95        abort();
96      }
97      //     fprintf (stderr,"Pop %d, length=%d \n",cpt, gras_dynar_length(d));
98    }
99    for (cpt=999; cpt>=0; cpt--) {
100      d1=(double)cpt;
101      gras_dynar_shift(d,&d2);
102      if (d1 != d2) {
103        fprintf(stderr,
104            "The retrieved value is not the same than the injected one in the middle (%f!=%f)\n",
105                d1,d2);
106        abort();
107      }
108    }
109    for (cpt=2500; cpt< 5000; cpt++) {
110      d1=(double)cpt;
111      gras_dynar_shift(d,&d2);
112      if (d1 != d2) {
113        fprintf(stderr,
114            "The retrieved value is not the same than the injected one at the end (%f!=%f)\n",
115                d1,d2);
116        abort();
117      }
118    }
119    gras_dynar_free(d);
120
121
122    fprintf(stderr,"==== Push 5000 double, remove 2000-4000. free the rest\n");
123    TRYFAIL(gras_dynar_new(&d,sizeof(double),NULL));
124    for (cpt=0; cpt< 5000; cpt++) {
125      d1=(double)cpt;
126      TRYFAIL(gras_dynar_push(d,&d1));
127    }
128    for (cpt=2000; cpt< 4000; cpt++) {
129      d1=(double)cpt;
130      gras_dynar_remove_at(d,2000,&d2);
131      if (d1 != d2) {
132        fprintf(stderr,
133            "Remove a bad value. Got %f, expected %f\n",
134                d2,d1);
135        abort();
136      }
137    }
138    gras_dynar_free(d);
139
140    return 0;
141 }