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 GRAS_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test");
16 int main(int argc,char *argv[]) {
22 gras_init_defaultlog(&argc,argv,"dynar.thresh=debug");
24 INFO0("==== Traverse the empty dynar");
25 d=gras_dynar_new(sizeof(int),NULL);
26 gras_dynar_foreach(d,cursor,cpt){
28 "Damnit, there is something in the empty dynar");
33 INFO0("==== Push/shift 5000 doubles");
34 d=gras_dynar_new(sizeof(double),NULL);
35 for (cpt=0; cpt< 5000; cpt++) {
37 gras_dynar_push(d,&d1);
39 gras_dynar_foreach(d,cursor,d2){
41 gras_assert2(d1 == d2,
42 "The retrieved value is not the same than the injected one (%f!=%f)",
45 for (cpt=0; cpt< 5000; cpt++) {
47 gras_dynar_shift(d,&d2);
48 gras_assert2(d1 == d2,
49 "The retrieved value is not the same than the injected one (%f!=%f)",
56 INFO0("==== Unshift/pop 5000 doubles");
57 d=gras_dynar_new(sizeof(double),NULL);
58 for (cpt=0; cpt< 5000; cpt++) {
60 gras_dynar_unshift(d,&d1);
62 for (cpt=0; cpt< 5000; cpt++) {
64 gras_dynar_pop(d,&d2);
65 gras_assert2 (d1 == d2,
66 "The retrieved value is not the same than the injected one (%f!=%f)",
74 INFO0("==== Push 5000 doubles, insert 1000 doubles in the middle, shift everything");
75 d=gras_dynar_new(sizeof(double),NULL);
76 for (cpt=0; cpt< 5000; cpt++) {
78 gras_dynar_push(d,&d1);
80 for (cpt=0; cpt< 1000; cpt++) {
82 gras_dynar_insert_at(d,2500,&d1);
85 for (cpt=0; cpt< 2500; cpt++) {
87 gras_dynar_shift(d,&d2);
88 gras_assert2(d1 == d2,
89 "The retrieved value is not the same than the injected one at the begining (%f!=%f)",
91 DEBUG2("Pop %d, length=%lu",cpt, gras_dynar_length(d));
93 for (cpt=999; cpt>=0; cpt--) {
95 gras_dynar_shift(d,&d2);
96 gras_assert2 (d1 == d2,
97 "The retrieved value is not the same than the injected one in the middle (%f!=%f)",
100 for (cpt=2500; cpt< 5000; cpt++) {
102 gras_dynar_shift(d,&d2);
103 gras_assert2 (d1 == d2,
104 "The retrieved value is not the same than the injected one at the end (%f!=%f)",
111 INFO0("==== Push 5000 double, remove 2000-4000. free the rest");
112 d=gras_dynar_new(sizeof(double),NULL);
113 for (cpt=0; cpt< 5000; cpt++) {
115 gras_dynar_push(d,&d1);
117 for (cpt=2000; cpt< 4000; cpt++) {
119 gras_dynar_remove_at(d,2000,&d2);
120 gras_assert2 (d1 == d2,
121 "Remove a bad value. Got %f, expected %f",