3 /* dynar_double: A test case for the dynar using doubles as content */
5 /* Authors: Martin Quinson */
6 /* Copyright (C) 2003 the OURAGAN project. */
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. */
14 int main(int argc,char *argv[]) {
20 gras_init_defaultlog(&argc,argv,"dynar.thresh=debug");
22 fprintf(stderr,"==== Traverse the empty dynar\n");
23 TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL));
24 gras_dynar_foreach(d,cursor,cpt){
26 "Damnit, there is something in the empty dynar\n");
31 fprintf(stderr,"==== Push/shift 5000 doubles\n");
32 TRYFAIL(gras_dynar_new(&d,sizeof(double),NULL));
33 for (cpt=0; cpt< 5000; cpt++) {
35 TRYFAIL(gras_dynar_push(d,&d1));
37 gras_dynar_foreach(d,cursor,d2){
41 "The retrieved value is not the same than the injected one (%f!=%f)\n",
46 for (cpt=0; cpt< 5000; cpt++) {
48 gras_dynar_shift(d,&d2);
51 "The retrieved value is not the same than the injected one (%f!=%f)\n",
59 fprintf(stderr,"==== Unshift/pop 5000 doubles\n");
60 TRYFAIL(gras_dynar_new(&d,sizeof(double),NULL));
61 for (cpt=0; cpt< 5000; cpt++) {
63 TRYFAIL(gras_dynar_unshift(d,&d1));
65 for (cpt=0; cpt< 5000; cpt++) {
67 gras_dynar_pop(d,&d2);
70 "The retrieved value is not the same than the injected one (%f!=%f)\n",
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++) {
83 TRYFAIL(gras_dynar_push(d,&d1));
85 for (cpt=0; cpt< 1000; cpt++) {
87 TRYFAIL(gras_dynar_insert_at(d,2500,&d1));
90 for (cpt=0; cpt< 2500; cpt++) {
92 gras_dynar_shift(d,&d2);
95 "The retrieved value is not the same than the injected one at the begining (%f!=%f)\n",
99 // fprintf (stderr,"Pop %d, length=%d \n",cpt, gras_dynar_length(d));
101 for (cpt=999; cpt>=0; cpt--) {
103 gras_dynar_shift(d,&d2);
106 "The retrieved value is not the same than the injected one in the middle (%f!=%f)\n",
111 for (cpt=2500; cpt< 5000; cpt++) {
113 gras_dynar_shift(d,&d2);
116 "The retrieved value is not the same than the injected one at the end (%f!=%f)\n",
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++) {
128 TRYFAIL(gras_dynar_push(d,&d1));
130 for (cpt=2000; cpt< 4000; cpt++) {
132 gras_dynar_remove_at(d,2000,&d2);
135 "Remove a bad value. Got %f, expected %f\n",