3 /* dynar_double: A test case for the dynar using doubles as content */
5 /* Copyright (c) 2004 Martin Quinson. All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
13 XBT_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test");
15 int main(int argc,char *argv[]) {
21 xbt_init_defaultlog(&argc,argv,"dynar.thresh=debug");
23 INFO0("==== Traverse the empty dynar");
24 d=xbt_dynar_new(sizeof(int),NULL);
25 xbt_dynar_foreach(d,cursor,cpt){
27 "Damnit, there is something in the empty dynar");
32 INFO0("==== Push/shift 5000 doubles");
33 d=xbt_dynar_new(sizeof(double),NULL);
34 for (cpt=0; cpt< 5000; cpt++) {
36 xbt_dynar_push(d,&d1);
38 xbt_dynar_foreach(d,cursor,d2){
41 "The retrieved value is not the same than the injected one (%f!=%f)",
44 for (cpt=0; cpt< 5000; cpt++) {
46 xbt_dynar_shift(d,&d2);
48 "The retrieved value is not the same than the injected one (%f!=%f)",
55 INFO0("==== Unshift/pop 5000 doubles");
56 d=xbt_dynar_new(sizeof(double),NULL);
57 for (cpt=0; cpt< 5000; cpt++) {
59 xbt_dynar_unshift(d,&d1);
61 for (cpt=0; cpt< 5000; cpt++) {
64 xbt_assert2 (d1 == d2,
65 "The retrieved value is not the same than the injected one (%f!=%f)",
73 INFO0("==== Push 5000 doubles, insert 1000 doubles in the middle, shift everything");
74 d=xbt_dynar_new(sizeof(double),NULL);
75 for (cpt=0; cpt< 5000; cpt++) {
77 xbt_dynar_push(d,&d1);
79 for (cpt=0; cpt< 1000; cpt++) {
81 xbt_dynar_insert_at(d,2500,&d1);
84 for (cpt=0; cpt< 2500; cpt++) {
86 xbt_dynar_shift(d,&d2);
88 "The retrieved value is not the same than the injected one at the begining (%f!=%f)",
90 DEBUG2("Pop %d, length=%lu",cpt, xbt_dynar_length(d));
92 for (cpt=999; cpt>=0; cpt--) {
94 xbt_dynar_shift(d,&d2);
95 xbt_assert2 (d1 == d2,
96 "The retrieved value is not the same than the injected one in the middle (%f!=%f)",
99 for (cpt=2500; cpt< 5000; cpt++) {
101 xbt_dynar_shift(d,&d2);
102 xbt_assert2 (d1 == d2,
103 "The retrieved value is not the same than the injected one at the end (%f!=%f)",
110 INFO0("==== Push 5000 double, remove 2000-4000. free the rest");
111 d=xbt_dynar_new(sizeof(double),NULL);
112 for (cpt=0; cpt< 5000; cpt++) {
114 xbt_dynar_push(d,&d1);
116 for (cpt=2000; cpt< 4000; cpt++) {
118 xbt_dynar_remove_at(d,2000,&d2);
119 xbt_assert2 (d1 == d2,
120 "Remove a bad value. Got %f, expected %f",