Logo AND Algorithmique Numérique Distribuée

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