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 void parse_log_opt(int argc, char **argv,const char *deft);
16 int main(int argc,char *argv[]) {
22 parse_log_opt(argc,argv,"dynar.thresh=debug");
24 fprintf(stderr,"==== Traverse the empty dynar\n");
25 TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL));
26 gras_dynar_foreach(d,cursor,cpt){
28 "Damnit, there is something in the empty dynar\n");
33 fprintf(stderr,"==== Push/shift 5000 doubles\n");
34 TRYFAIL(gras_dynar_new(&d,sizeof(double),NULL));
35 for (cpt=0; cpt< 5000; cpt++) {
37 TRYFAIL(gras_dynar_push(d,&d1));
39 gras_dynar_foreach(d,cursor,d2){
43 "The retrieved value is not the same than the injected one (%f!=%f)\n",
48 for (cpt=0; cpt< 5000; cpt++) {
50 gras_dynar_shift(d,&d2);
53 "The retrieved value is not the same than the injected one (%f!=%f)\n",
61 fprintf(stderr,"==== Unshift/pop 5000 doubles\n");
62 TRYFAIL(gras_dynar_new(&d,sizeof(double),NULL));
63 for (cpt=0; cpt< 5000; cpt++) {
65 TRYFAIL(gras_dynar_unshift(d,&d1));
67 for (cpt=0; cpt< 5000; cpt++) {
69 gras_dynar_pop(d,&d2);
72 "The retrieved value is not the same than the injected one (%f!=%f)\n",
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++) {
85 TRYFAIL(gras_dynar_push(d,&d1));
87 for (cpt=0; cpt< 1000; cpt++) {
89 TRYFAIL(gras_dynar_insert_at(d,2500,&d1));
92 for (cpt=0; cpt< 2500; cpt++) {
94 gras_dynar_shift(d,&d2);
97 "The retrieved value is not the same than the injected one at the begining (%f!=%f)\n",
101 // fprintf (stderr,"Pop %d, length=%d \n",cpt, gras_dynar_length(d));
103 for (cpt=999; cpt>=0; cpt--) {
105 gras_dynar_shift(d,&d2);
108 "The retrieved value is not the same than the injected one in the middle (%f!=%f)\n",
113 for (cpt=2500; cpt< 5000; cpt++) {
115 gras_dynar_shift(d,&d2);
118 "The retrieved value is not the same than the injected one at the end (%f!=%f)\n",
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++) {
130 TRYFAIL(gras_dynar_push(d,&d1));
132 for (cpt=2000; cpt< 4000; cpt++) {
134 gras_dynar_remove_at(d,2000,&d2);
137 "Remove a bad value. Got %f, expected %f\n",