Logo AND Algorithmique Numérique Distribuée

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