Logo AND Algorithmique Numérique Distribuée

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