00001
00073 #include <stdio.h>
00074 #include "ctl/dg/datagen.h"
00075 #include "ctl/algorithm.temp.h"
00076
00077
00078 #ifndef CTL_UNIT
00079
00080
00084 void spew(void);
00085 #if 1
00086
00087
00088
00089
00090
00091
00092
00093
00094
00096 int bool_compare( const bool* p1, const bool* p2 )
00097 {
00098 return (int)*p2-(int)*p1;
00099 }
00100
00102 int bool_rcompare( const bool* p1, const bool* p2 )
00103 {
00104 return (int)*p2-(int)*p1;
00105 }
00106
00108 int int8_compare( const int8* p1, const int8* p2 )
00109 {
00110 return (int)*p1-(int)*p2;
00111 }
00113 int int8_rcompare( const int8* p1, const int8* p2 )
00114 {
00115 return (int)(*p2-*p1);
00116 }
00117
00119 int uint8_compare( const uint8* p1, const uint8* p2 )
00120 {
00121 return (int)*p2-(int)*p1;
00122 }
00123
00125 int uint8_rcompare( const uint8* p1, const uint8* p2 )
00126 {
00127 return (int)*p2-(int)*p1;
00128 }
00129
00130
00132 int int16_compare( const int16* p1, const int16* p2 )
00133 {
00134 return (int)*p1-(int)*p2;
00135 }
00136
00138 int int16_rcompare( const int16* p1, const int16* p2 )
00139 {
00140 return (int)*p2-(int)*p1;
00141 }
00142
00144 int uint16_compare( const uint16* p1, const uint16* p2 )
00145 {
00146 return (int)*p1-(int)*p2;
00147 }
00148
00150 int uint16_rcompare( const uint16* p1, const uint16* p2 )
00151 {
00152 return (int)*p2-(int)*p1;
00153 }
00154
00155
00157 int int32_compare( const int32* p1, const int32* p2 )
00158 {
00159
00160 if( *p1 < *p2 )
00161 return -1;
00162 if( *p1 > *p2 )
00163 return 1;
00164 return 0;
00165 }
00166
00168 int int32_rcompare( const int32* p1, const int32* p2 )
00169 {
00170
00171 if( *p1 > *p2 )
00172 return -1;
00173 if( *p1 < *p2 )
00174 return 1;
00175 return 0;
00176 }
00177
00179 int uint32_compare( const uint32* p1, const uint32* p2 )
00180 {
00181
00182 if( *p1 < *p2 )
00183 return -1;
00184 if( *p1 > *p2 )
00185 return 1;
00186 return 0;
00187 }
00188
00190 int uint32_rcompare( const uint32* p1, const uint32* p2 )
00191 {
00192 if( *p1 > *p2 )
00193 return -1;
00194 if( *p1 < *p2 )
00195 return 1;
00196 return 0;
00197 }
00198
00199
00201 int int64_compare( const int64* p1, const int64* p2 )
00202 {
00203 if( *p1 > *p2 )
00204 return 1;
00205 if( *p1 < *p2 )
00206 return -1;
00207 return 0;
00208 }
00209
00210
00212 int int64_rcompare( const int64* p1, const int64* p2 )
00213 {
00214 if( *p1 > *p2 )
00215 return -1;
00216 if( *p1 < *p2 )
00217 return 1;
00218 return 0;
00219 }
00220
00222 int uint64_compare( const uint64* p1, const uint64* p2 )
00223 {
00224 if( *p1 > *p2 )
00225 return 1;
00226 if( *p1 < *p2 )
00227 return -1;
00228 return 0;
00229 }
00230
00232 int uint64_rcompare( const uint64* p1, const uint64* p2 )
00233 {
00234 if( *p1 > *p2 )
00235 return -1;
00236 if( *p1 < *p2 )
00237 return 1;
00238 return 0;
00239 }
00240
00245 int float32_compare(const float32* p1, const float32* p2 )
00246 {
00247 float32 diff = *p1-*p2;
00248 if( diff > float32_compare_epsilon )
00249 return 1;
00250 if( diff < -float32_compare_epsilon )
00251 return -1;
00252 return 0;
00253 }
00254
00259 int float32_rcompare(const float32* p1, const float32* p2 )
00260 {
00261 float32 diff = *p1-*p2;
00262 if( diff > float32_compare_epsilon )
00263 return -1;
00264 if( diff < -float32_compare_epsilon )
00265 return 1;
00266 return 0;
00267 }
00268
00273 int float64_compare(const float64* p1, const float64* p2 )
00274 {
00275 float64 diff = *p1-*p2;
00276 if( diff > float64_compare_epsilon )
00277 return 1;
00278 if( diff < -float64_compare_epsilon )
00279 return -1;
00280 return 0;
00281 }
00282
00287 int float64_rcompare(const float64* p1, const float64* p2 )
00288 {
00289 float64 diff = *p1-*p2;
00290 if( diff > float64_compare_epsilon )
00291 return -1;
00292 if( diff < -float64_compare_epsilon )
00293 return 1;
00294 return 0;
00295 }
00296
00297
00298 #define XSORTS(def,param) ctl_array_qsort_implement(def)
00299 DEF_ENUMTYPES(XSORTS,unused)
00300 #undef XSORTS
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00315 void char_string_swap( char* s1, char* s2, size_t count )
00316 {
00317 assertptr(s1,count);
00318 assertptr(s2,count);
00319 {
00320 uint32* p1 = (uint32*)s1;
00321 uint32* p2 = (uint32*)s2;
00322 size_t u32count = count>>2;
00323 size_t leftover = count&3;
00324 while( u32count-- )
00325 {
00326 uint32 tmp = *p1;
00327 *p1 = *p2;
00328 *p2 = tmp;
00329 p1++;
00330 p2++;
00331 }
00332 s1 = (char*)p1;
00333 s2 = (char*)p2;
00334 while( leftover-- )
00335 {
00336 char tmp = *s1;
00337 *s1 = *s2;
00338 *s2 = tmp;
00339 }
00340 }
00341 }
00346 void wchar_t_string_swap( wchar_t* s1, wchar_t* s2, size_t count )
00347 {
00348 while( count-- )
00349 {
00350 wchar_t tmp;
00351 tmp = *s1;
00352 *s1 = *s2;
00353 *s2 = tmp;
00354 }
00355 }
00356
00357
00358
00359 #define IMPL_scalar_vectors(type,unused) ctl_implement_vector(ppConcat(type,_vector),type,ctl_raw)
00360 DEF_ENUMTYPES(IMPL_scalar_vectors,unused)
00361 #undef IMPL_scalar_vectors
00362
00363 #else
00364
00365
00366 #endif
00367
00368
00371 #else
00372
00376
00377
00378
00379
00380
00381 #include "unit/unit.h"
00382
00383
00384
00385
00386 #define MAKE_RANDOMIZE
00387 #define ctl_declarations "unit/datatest.temp.h"
00388 #include "ctl/dg/patterns.h"
00389
00390
00391 #include "ctl/mmap.h"
00392 #include "ctl/profile.h"
00393 #include "ctl/algorithm.h"
00394 #include "ctl/destruct.h"
00395
00401 void Test_array(void)
00402 {
00403
00404 {
00405 int32 Test_Size = rand_between(int32,10,64);
00406 IntTest spork, foon;
00407 IntTest_init(&spork);
00408 {
00409 int curr;
00410 for( curr = 0; curr < Test_Size; ++curr )
00411 *IntTest_push_back(&spork) = rand();
00412 }
00413 Test_Error( (int32)IntTest_count(&spork) == Test_Size );
00414 Test_Error( IntTest_ismember( &spork, IntTest_front(&spork) ) );
00415 Test_Error( !IntTest_ismember( &spork, IntTest_front(&spork)-1 ) );
00416 Test_Error( IntTest_ismember( &spork, IntTest_back(&spork) ) );
00417 Test_Error( !IntTest_ismember( &spork, IntTest_back(&spork)+1 ) );
00418 Test_Error( IntTest_ismember( &spork, IntTest_at(&spork,rand()%(int)IntTest_count(&spork)) ) );
00419 Test_Error( !IntTest_ismember( &spork, &Test_Size ) );
00420
00421 IntTest_sort(&spork, int32_compare);
00422 {
00423 int32 prev = type_min(int32);
00424 ctl_array_foreach_const(IntTest, &spork, curr)
00425 {
00426 Test_Error( *curr >= prev );
00427 prev = *curr;
00428 }
00429 }
00430 IntTest_copy( &foon, &spork );
00431 Test_Error( !IntTest_compare( &foon, &spork ) );
00432 {
00433 int32* p = IntTest_insert_range(&spork, IntTest_front(&spork), 3 );
00434 *p++ = -3;
00435 *p++ = -2;
00436 *p++ = -1;
00437 }
00438 *IntTest_push_front(&spork) = -4;
00439 *IntTest_push_front(&spork) = -5;
00440 *IntTest_push_front(&spork) = -6;
00441 *IntTest_push_back(&spork) = type_max(int32)-1;
00442 *IntTest_push_back(&spork) = type_max(int32);
00443 {
00444 int32 prev = type_min(int32);
00445 ctl_array_foreach_const(IntTest, &spork, curr)
00446 {
00447 Test_Error( *curr >= prev );
00448 prev = *curr;
00449 }
00450 }
00451 {
00452 int32 prev = type_min(int32);
00453 ctl_array_foreach(IntTest, &spork, curr)
00454 {
00455 Test_Error( *curr >= prev );
00456 prev = *curr;
00457 }
00458 }
00459 {
00460 int32 prev = type_max(int32);
00461 ctl_array_foreach_const_reverse(IntTest, &spork, curr)
00462 {
00463 Test_Error( *curr <= prev );
00464 prev = *curr;
00465 }
00466 }
00467 {
00468 int32 prev = type_max(int32);
00469 ctl_array_foreach_reverse(IntTest, &spork, curr)
00470 {
00471 Test_Error( *curr <= prev );
00472 prev = *curr;
00473 }
00474 }
00475
00476 IntTest_erase_range(&spork, IntTest_front(&spork), 6 );
00477 IntTest_erase_range(&spork, IntTest_back(&spork)-1, 2 );
00478 Test_Error( !IntTest_compare( &foon, &spork ) );
00479 IntTest_destroy(&spork);
00480 IntTest_destroy(&foon);
00481 }
00482
00483
00484 {
00485 int32 Test_Size = rand_between(int32,10,64);
00486 CompoundTest_array spork, foon;
00487 CompoundTest_array_init(&spork);
00488 {
00489 int curr;
00490 for( curr = 0; curr < Test_Size; ++curr )
00491 {
00492 sXY* xy = CompoundTest_array_push_back(&spork);
00493 xy->x = type_rand(float32);
00494 xy->y = type_rand(float32);
00495 }
00496 }
00497 Test_Error( (int32)CompoundTest_array_count(&spork) == Test_Size );
00498 Test_Error( CompoundTest_array_ismember( &spork, CompoundTest_array_front(&spork) ) );
00499 Test_Error( !CompoundTest_array_ismember( &spork, CompoundTest_array_front(&spork)-1 ) );
00500 Test_Error( CompoundTest_array_ismember( &spork, CompoundTest_array_back(&spork) ) );
00501 Test_Error( !CompoundTest_array_ismember( &spork, CompoundTest_array_back(&spork)+1 ) );
00502 Test_Error( CompoundTest_array_ismember( &spork, CompoundTest_array_at(&spork,rand()%(int)CompoundTest_array_count(&spork)) ) );
00503 {
00504 sXY junk;
00505 Test_Error( !CompoundTest_array_ismember( &spork, &junk ) );
00506 }
00507
00508 CompoundTest_array_sort(&spork, sXY_compare);
00509 CompoundTest_array_copy( &foon, &spork );
00510 Test_Error( !CompoundTest_array_compare( &foon, &spork ) );
00511 CompoundTest_array_sort(&foon, sXY_rcompare);
00512 Test_Error( CompoundTest_array_compare( &foon, &spork ) );
00513 {
00514 const sXY* prev = NULL;
00515 ctl_array_foreach_const(CompoundTest_array, &spork, curr)
00516 {
00517 Test_Error( !prev || sXY_compare( prev, curr ) <= 0 );
00518 prev = curr;
00519 }
00520 }
00521 {
00522 const sXY* prev = NULL;
00523 ctl_array_foreach(CompoundTest_array, &foon, curr)
00524 {
00525 Test_Error( !prev || sXY_compare( prev, curr ) >= 0 );
00526 prev = curr;
00527 }
00528 }
00529 {
00530 const sXY* prev = NULL;
00531 ctl_array_foreach_const_reverse(CompoundTest_array, &spork, curr)
00532 {
00533 Test_Error( !prev || sXY_compare( prev, curr ) >= 0 );
00534 prev = curr;
00535 }
00536 }
00537 {
00538 const sXY* prev = NULL;
00539 ctl_array_foreach_reverse(CompoundTest_array, &spork, curr)
00540 {
00541 Test_Error( !prev || sXY_compare( prev, curr ) >= 0 );
00542 prev = curr;
00543 }
00544 }
00545
00546 CompoundTest_array_splice(&spork, &foon);
00547 Test_Error( CompoundTest_array_count(&foon) == 0);
00548 Test_Error( CompoundTest_array_count(&spork) == (size_t)Test_Size*2);
00549 CompoundTest_array_sort(&spork, sXY_compare);
00550 {
00551 const sXY* prev = NULL;
00552 ctl_array_foreach_mutable(CompoundTest_array, &spork, curr)
00553 {
00554 Test_Error( CompoundTest_array_ismember( &spork, curr ) );
00555 Test_Error( !prev || sXY_compare( prev, curr ) <= 0 );
00556 if( !(rand()&3) )
00557 CompoundTest_array_erase(&spork, curr );
00558 else
00559 prev = curr;
00560 }
00561 }
00562 {
00563 const sXY* prev = NULL;
00564 ctl_array_foreach_mutable_reverse(CompoundTest_array, &spork, curr)
00565 {
00566 Test_Error( CompoundTest_array_ismember( &spork, curr ) );
00567 Test_Error( !prev || sXY_compare( prev, curr ) >= 0 );
00568 if( curr < CompoundTest_array_back(&spork) && !(rand()&3) )
00569 CompoundTest_array_erase_range(&spork, curr, (rand()%(CompoundTest_array_back(&spork)-curr)) );
00570 else
00571 prev = curr;
00572 }
00573 }
00574 {
00575 const sXY* prev = NULL;
00576 const sXY* curr = CompoundTest_array_front(&spork);
00577 size_t count = 0;
00578 while( curr )
00579 {
00580 Test_Error( !prev || sXY_compare( prev, curr ) <= 0 );
00581 prev = curr;
00582 curr = CompoundTest_array_next(&spork,curr);
00583 count++;
00584 }
00585 Test_Error( CompoundTest_array_count(&spork) == count );
00586 }
00587 CompoundTest_array_destroy(&spork);
00588 CompoundTest_array_destroy(&foon);
00589 }
00590 }
00591
00597 void Test_vector(void)
00598 {
00599
00600 {
00601 int32 Test_Size = rand_between(int32,100,300);
00602 IntTest spork, foon;
00603 IntTest_init(&spork);
00604 {
00605 int curr;
00606 for( curr = 0; curr < Test_Size; ++curr )
00607 *IntTest_push_back(&spork) = rand();
00608 }
00609 Test_Error( (int32)IntTest_count(&spork) == Test_Size );
00610 Test_Error( IntTest_ismember( &spork, IntTest_front(&spork) ) );
00611 Test_Error( !IntTest_ismember( &spork, IntTest_front(&spork)-1 ) );
00612 Test_Error( IntTest_ismember( &spork, IntTest_back(&spork) ) );
00613 Test_Error( !IntTest_ismember( &spork, IntTest_back(&spork)+1 ) );
00614 Test_Error( IntTest_ismember( &spork, IntTest_at(&spork,rand()%(int)IntTest_count(&spork)) ) );
00615 Test_Error( !IntTest_ismember( &spork, &Test_Size ) );
00616
00617 IntTest_sort(&spork, int32_compare);
00618 {
00619 int32 prev = type_min(int32);
00620 ctl_vector_foreach_const(IntTest, &spork, curr)
00621 {
00622 Test_Error( *curr >= prev );
00623 prev = *curr;
00624 }
00625 }
00626 IntTest_copy( &foon, &spork );
00627 Test_Error( !IntTest_compare( &foon, &spork ) );
00628 {
00629 int32* p = IntTest_insert_range(&spork, IntTest_front(&spork), 3 );
00630 *p++ = -3;
00631 *p++ = -2;
00632 *p++ = -1;
00633 }
00634 *IntTest_push_front(&spork) = -4;
00635 *IntTest_push_front(&spork) = -5;
00636 *IntTest_push_front(&spork) = -6;
00637 *IntTest_push_back(&spork) = type_max(int32)-1;
00638 *IntTest_push_back(&spork) = type_max(int32);
00639 {
00640 int32 prev = type_min(int32);
00641 ctl_vector_foreach_const(IntTest, &spork, curr)
00642 {
00643 Test_Error( *curr >= prev );
00644 prev = *curr;
00645 }
00646 }
00647 {
00648 int32 prev = type_min(int32);
00649 ctl_vector_foreach(IntTest, &spork, curr)
00650 {
00651 Test_Error( *curr >= prev );
00652 prev = *curr;
00653 }
00654 }
00655 {
00656 int32 prev = type_max(int32);
00657 ctl_vector_foreach_const_reverse(IntTest, &spork, curr)
00658 {
00659 Test_Error( *curr <= prev );
00660 prev = *curr;
00661 }
00662 }
00663 {
00664 int32 prev = type_max(int32);
00665 ctl_vector_foreach_reverse(IntTest, &spork, curr)
00666 {
00667 Test_Error( *curr <= prev );
00668 prev = *curr;
00669 }
00670 }
00671
00672 IntTest_erase_range(&spork, IntTest_front(&spork), 6 );
00673 IntTest_erase_range(&spork, IntTest_back(&spork)-1, 2 );
00674 Test_Error( !IntTest_compare( &foon, &spork ) );
00675 IntTest_destroy(&spork);
00676 IntTest_destroy(&foon);
00677 }
00678
00679
00680 {
00681 int32 Test_Size = rand_between(int32,100,300);
00682 CompoundTest_vector spork, foon;
00683 CompoundTest_vector_init(&spork);
00684 {
00685 int curr;
00686 for( curr = 0; curr < Test_Size; ++curr )
00687 {
00688 sXY* xy = CompoundTest_vector_push_back(&spork);
00689 xy->x = type_rand(float32);
00690 xy->y = type_rand(float32);
00691 }
00692 }
00693 Test_Error( (int32)CompoundTest_vector_count(&spork) == Test_Size );
00694 Test_Error( CompoundTest_vector_ismember( &spork, CompoundTest_vector_front(&spork) ) );
00695 Test_Error( !CompoundTest_vector_ismember( &spork, CompoundTest_vector_front(&spork)-1 ) );
00696 Test_Error( CompoundTest_vector_ismember( &spork, CompoundTest_vector_back(&spork) ) );
00697 Test_Error( !CompoundTest_vector_ismember( &spork, CompoundTest_vector_back(&spork)+1 ) );
00698 Test_Error( CompoundTest_vector_ismember( &spork, CompoundTest_vector_at(&spork,rand()%(int)CompoundTest_vector_count(&spork)) ) );
00699 {
00700 sXY junk;
00701 Test_Error( !CompoundTest_vector_ismember( &spork, &junk ) );
00702 }
00703
00704 CompoundTest_vector_sort(&spork, sXY_compare);
00705 CompoundTest_vector_copy( &foon, &spork );
00706 Test_Error( !CompoundTest_vector_compare( &foon, &spork ) );
00707 CompoundTest_vector_sort(&foon, sXY_rcompare);
00708 Test_Error( CompoundTest_vector_compare( &foon, &spork ) );
00709 {
00710 const sXY* prev = NULL;
00711 ctl_vector_foreach_const(CompoundTest_vector, &spork, curr)
00712 {
00713 Test_Error( !prev || sXY_compare( prev, curr ) <= 0 );
00714 prev = curr;
00715 }
00716 }
00717 {
00718 const sXY* prev = NULL;
00719 ctl_vector_foreach(CompoundTest_vector, &foon, curr)
00720 {
00721 Test_Error( !prev || sXY_compare( prev, curr ) >= 0 );
00722 prev = curr;
00723 }
00724 }
00725 {
00726 const sXY* prev = NULL;
00727 ctl_vector_foreach_const_reverse(CompoundTest_vector, &spork, curr)
00728 {
00729 Test_Error( !prev || sXY_compare( prev, curr ) >= 0 );
00730 prev = curr;
00731 }
00732 }
00733 {
00734 const sXY* prev = NULL;
00735 ctl_vector_foreach_reverse(CompoundTest_vector, &spork, curr)
00736 {
00737 Test_Error( !prev || sXY_compare( prev, curr ) >= 0 );
00738 prev = curr;
00739 }
00740 }
00741
00742 CompoundTest_vector_splice(&spork, &foon);
00743 Test_Error( CompoundTest_vector_count(&foon) == 0);
00744 Test_Error( CompoundTest_vector_count(&spork) == (size_t)Test_Size*2);
00745 CompoundTest_vector_sort(&spork, sXY_compare);
00746 {
00747 const sXY* prev = NULL;
00748 ctl_vector_foreach_mutable(CompoundTest_vector, &spork, curr)
00749 {
00750 Test_Error( CompoundTest_vector_ismember( &spork, curr ) );
00751 Test_Error( !prev || sXY_compare( prev, curr ) <= 0 );
00752 if( !(rand()&3) )
00753 CompoundTest_vector_erase(&spork, curr );
00754 else
00755 prev = curr;
00756 }
00757 }
00758 {
00759 const sXY* prev = NULL;
00760 ctl_vector_foreach_mutable_reverse(CompoundTest_vector, &spork, curr)
00761 {
00762 Test_Error( CompoundTest_vector_ismember( &spork, curr ) );
00763 Test_Error( !prev || sXY_compare( prev, curr ) >= 0 );
00764 if( curr < CompoundTest_vector_back(&spork) && !(rand()&3) )
00765 CompoundTest_vector_erase_range(&spork, curr, (rand()%(CompoundTest_vector_back(&spork)-curr)) );
00766 else
00767 prev = curr;
00768 }
00769 }
00770 {
00771 const sXY* prev = NULL;
00772 const sXY* curr = CompoundTest_vector_front(&spork);
00773 size_t count = 0;
00774 while( curr )
00775 {
00776 Test_Error( !prev || sXY_compare( prev, curr ) <= 0 );
00777 prev = curr;
00778 curr = CompoundTest_vector_next(&spork,curr);
00779 count++;
00780 }
00781 Test_Error( CompoundTest_vector_count(&spork) == count );
00782 }
00783 CompoundTest_vector_destroy(&spork);
00784 CompoundTest_vector_destroy(&foon);
00785 }
00786 }
00787
00793 void Test_list(void)
00794 {
00795
00796 int32 Test_Size = rand_between(int32,100,300);
00797 CompoundTest_list spork, foon;
00798 CompoundTest_list_init(&spork);
00799 {
00800 int curr;
00801 for( curr = 0; curr < Test_Size; ++curr )
00802 {
00803 sXYZ* xyz = CompoundTest_list_push_back(&spork);
00804 xyz->x = type_rand(float32);
00805 xyz->y = type_rand(float32);
00806 xyz->z = type_rand(float32);
00807 }
00808 }
00809 Test_Error( (int32)CompoundTest_list_count(&spork) == Test_Size );
00810 Test_Error( ctl_pool_alloc_count(&CompoundTest_list_pool) == (size_t)Test_Size );
00811 Test_Error( CompoundTest_list_ismember( &spork, CompoundTest_list_front(&spork) ) );
00812 Test_Error( !CompoundTest_list_ismember( &spork, CompoundTest_list_front(&spork)-1 ) );
00813 Test_Error( CompoundTest_list_ismember( &spork, CompoundTest_list_back(&spork) ) );
00814 Test_Error( !CompoundTest_list_ismember( &spork, CompoundTest_list_back(&spork)+1 ) );
00815 {
00816 sXYZ junk;
00817 Test_Error( !CompoundTest_list_ismember( &spork, &junk ) );
00818 }
00819
00820 CompoundTest_list_sort(&spork, sXYZ_compare);
00821 {
00822 sXYZ* xyz = CompoundTest_list_push_front(&spork);
00823 xyz->x = 42;
00824 xyz = CompoundTest_list_push_back(&spork);
00825 xyz->x = 43;
00826 }
00827 Test_Error( ctl_pool_alloc_count(&CompoundTest_list_pool) == CompoundTest_list_count(&spork) );
00828 CompoundTest_list_copy( &foon, &spork );
00829 Test_Error( ctl_pool_alloc_count(&CompoundTest_list_pool) == CompoundTest_list_count(&spork) + CompoundTest_list_count(&foon) );
00830 Test_Error( !CompoundTest_list_compare( &foon, &spork ) );
00831 CompoundTest_list_pop_front(&foon);
00832 CompoundTest_list_pop_back(&foon);
00833 CompoundTest_list_pop_front(&spork);
00834 CompoundTest_list_pop_back(&spork);
00835 Test_Error( !CompoundTest_list_compare( &foon, &spork ) );
00836 Test_Error( ctl_pool_alloc_count(&CompoundTest_list_pool) == CompoundTest_list_count(&spork) + CompoundTest_list_count(&foon) );
00837 CompoundTest_list_sort(&foon, sXYZ_rcompare);
00838 Test_Error( CompoundTest_list_compare( &foon, &spork ) );
00839 {
00840 const sXYZ* prev = NULL;
00841 size_t count = 0;
00842 ctl_list_foreach_const(CompoundTest_list, &spork, curr)
00843 {
00844 Test_Error( !prev || sXYZ_compare( prev, curr ) <= 0 );
00845 prev = curr;
00846 count++;
00847 }
00848 Test_Error( CompoundTest_list_count(&spork) == count );
00849 }
00850 {
00851 const sXYZ* prev = NULL;
00852 size_t count = 0;
00853 ctl_list_foreach(CompoundTest_list, &foon, curr)
00854 {
00855 Test_Error( !prev || sXYZ_compare( prev, curr ) >= 0 );
00856 prev = curr;
00857 count++;
00858 }
00859 Test_Error( CompoundTest_list_count(&foon) == count );
00860 }
00861 {
00862 const sXYZ* prev = NULL;
00863 ctl_list_foreach_const_reverse(CompoundTest_list, &spork, curr)
00864 {
00865 Test_Error( !prev || sXYZ_compare( prev, curr ) >= 0 );
00866 prev = curr;
00867 }
00868 }
00869 {
00870 const sXYZ* prev = NULL;
00871 ctl_list_foreach_reverse(CompoundTest_list, &spork, curr)
00872 {
00873 Test_Error( !prev || sXYZ_compare( prev, curr ) >= 0 );
00874 prev = curr;
00875 }
00876 }
00877
00878 CompoundTest_list_splice(&spork, &foon);
00879 Test_Error( CompoundTest_list_count(&foon) == 0);
00880 Test_Error( CompoundTest_list_count(&spork) == (size_t)Test_Size*2);
00881 CompoundTest_list_sort(&spork, sXYZ_compare);
00882 {
00883 const sXYZ* prev = NULL;
00884 ctl_list_foreach_mutable(CompoundTest_list, &spork, curr)
00885 {
00886 Test_Error( CompoundTest_list_ismember( &spork, curr ) );
00887 Test_Error( !prev || sXYZ_compare( prev, curr ) <= 0 );
00888 if( !(rand()&3) )
00889 CompoundTest_list_erase(&spork, curr );
00890 else
00891 prev = curr;
00892 }
00893 }
00894 {
00895 const sXYZ* prev = NULL;
00896 ctl_list_foreach_mutable_reverse(CompoundTest_list, &spork, curr)
00897 {
00898 Test_Error( CompoundTest_list_ismember( &spork, curr ) );
00899 Test_Error( !prev || sXYZ_compare( prev, curr ) >= 0 );
00900 if( !(rand()&3) )
00901 CompoundTest_list_erase(&spork, curr );
00902 else
00903 prev = curr;
00904 }
00905 }
00906 {
00907 const sXYZ* prev = NULL;
00908 const sXYZ* curr = CompoundTest_list_front(&spork);
00909 size_t count = 0;
00910 while( curr )
00911 {
00912 Test_Error( !prev || sXYZ_compare( prev, curr ) <= 0 );
00913 prev = curr;
00914 curr = CompoundTest_list_next(&spork,curr);
00915 count++;
00916 }
00917 Test_Error( CompoundTest_list_count(&spork) == count );
00918 }
00919
00920
00921 Test_Error( ctl_pool_alloc_count(&CompoundTest_list_pool) == CompoundTest_list_count(&spork) );
00922 CompoundTest_list_destroy(&spork);
00923 CompoundTest_list_destroy(&foon);
00924 Test_Error( !ctl_pool_alloc_count(&CompoundTest_list_pool) );
00925 }
00926
00932 void Test_map(void)
00933 {
00934
00935 const size_t Test_Size = 1117;
00936 uint32 keylow = ~0u;
00937 uint32 keyhigh = 0;
00938 CompoundTest_map spork, foon;
00939 CompoundTest_map_init(&spork);
00940 {
00941 size_t curr;
00942 uint32 keyval = (uint32)rand();
00943 for( curr = 0; curr < Test_Size; ++curr )
00944 {
00945 sXYZ* xyz = CompoundTest_map_insert(&spork,&keyval);
00946 xyz->x = type_rand(float32);
00947 xyz->y = type_rand(float32);
00948 xyz->z = type_rand(float32);
00949 if( keyval > keyhigh )
00950 keyhigh = keyval;
00951 if( keyval < keylow )
00952 keylow = keyval;
00953 keyval += 1+(rand()%3);
00954 }
00955 }
00956 Test_Error( CompoundTest_map_count(&spork) == Test_Size );
00957 Test_Error( ctl_pool_alloc_count(&CompoundTest_map_pool) == CompoundTest_map_count(&spork) );
00958 Test_Error( CompoundTest_map_ismember( &spork, CompoundTest_map_front(&spork) ) );
00959 Test_Error( !CompoundTest_map_ismember( &spork, CompoundTest_map_front(&spork)-1 ) );
00960 Test_Error( CompoundTest_map_ismember( &spork, CompoundTest_map_back(&spork) ) );
00961 Test_Error( !CompoundTest_map_ismember( &spork, CompoundTest_map_back(&spork)+1 ) );
00962 {
00963 sXYZ junk;
00964 Test_Error( !CompoundTest_map_ismember( &spork, &junk ) );
00965 }
00966
00967 CompoundTest_map_sort(&spork, uint32_rcompare);
00968 CompoundTest_map_copy( &foon, &spork );
00969 Test_Error( ctl_pool_alloc_count(&CompoundTest_map_pool) == CompoundTest_map_count(&spork) + CompoundTest_map_count(&foon) );
00970 Test_Error( 0 == CompoundTest_map_compare( &foon, &spork ) );
00971 CompoundTest_map_sort(&spork, uint32_compare);
00972 Test_Error( CompoundTest_map_compare( &foon, &spork ) );
00973 {
00974 const uint32* prev = NULL;
00975 size_t count = 0;
00976 ctl_map_foreach_const(CompoundTest_map, &spork, curr)
00977 {
00978 Test_Error( !prev || uint32_compare( prev, curr_key ) < 0 );
00979 prev = curr_key;
00980 count++;
00981 }
00982 Test_Error( count == CompoundTest_map_count(&spork) );
00983 }
00984 {
00985 const uint32* prev = NULL;
00986 size_t count = 0;
00987 ctl_map_foreach(CompoundTest_map, &foon, curr)
00988 {
00989 Test_Error( !prev || uint32_compare( prev, curr_key ) > 0 );
00990 prev = curr_key;
00991 count++;
00992 }
00993 Test_Error( count == CompoundTest_map_count(&foon) );
00994 }
00995 {
00996 const uint32* prev = NULL;
00997 ctl_map_foreach_const_reverse(CompoundTest_map, &foon, curr)
00998 {
00999 Test_Error( !prev || uint32_compare( prev, curr_key ) < 0 );
01000 prev = curr_key;
01001 }
01002 }
01003 {
01004 const uint32* prev = NULL;
01005 ctl_map_foreach_reverse(CompoundTest_map, &spork, curr)
01006 {
01007 Test_Error( !prev || uint32_compare( prev, curr_key ) > 0 );
01008 prev = curr_key;
01009 }
01010 }
01011 {
01012 const uint32* prev = NULL;
01013 uint32 key = rand();
01014 ctl_map_from(CompoundTest_map, &spork, &key, curr )
01015 {
01016 Test_Error( !prev || uint32_compare( prev, curr_key ) < 0 );
01017 prev = curr_key;
01018 }
01019 }
01020 {
01021 const uint32* prev = NULL;
01022 uint32 key = rand();
01023 ctl_map_from_const(CompoundTest_map, &spork, &key, curr )
01024 {
01025 Test_Error( !prev || uint32_compare( prev, curr_key ) < 0 );
01026 prev = curr_key;
01027 }
01028 }
01029 {
01030 const uint32* prev = NULL;
01031 uint32 key = rand();
01032 ctl_map_from_reverse(CompoundTest_map, &spork, &key, curr )
01033 {
01034 Test_Error( !prev || uint32_compare( prev, curr_key ) > 0 );
01035 prev = curr_key;
01036 }
01037 }
01038 {
01039 const uint32* prev = NULL;
01040 uint32 key = rand();
01041 ctl_map_from_const_reverse(CompoundTest_map, &spork, &key, curr )
01042 {
01043 Test_Error( !prev || uint32_compare( prev, curr_key ) > 0 );
01044 prev = curr_key;
01045 }
01046 }
01047 {
01048 const uint32* prev = NULL;
01049 uint32 keyfrom = rand();
01050 uint32 keyto = keyfrom + rand();
01051 ctl_map_from_to(CompoundTest_map, &spork, &keyfrom, &keyto, curr )
01052 {
01053 Test_Error( !prev || uint32_compare( prev, curr_key ) < 0 );
01054 prev = curr_key;
01055 }
01056 }
01057 {
01058 const uint32* prev = NULL;
01059 uint32 keyfrom = rand();
01060 uint32 keyto = keyfrom + rand();
01061 ctl_map_from_to_const(CompoundTest_map, &spork, &keyfrom, &keyto, curr )
01062 {
01063 Test_Error( !prev || uint32_compare( prev, curr_key ) < 0 );
01064 prev = curr_key;
01065 }
01066 }
01067 {
01068 uint32 keyto = rand();
01069 uint32 keyfrom = keyto + rand();
01070 const uint32* prev = NULL;
01071 ctl_map_from_to_reverse(CompoundTest_map, &spork, &keyfrom, &keyto, curr )
01072 {
01073 Test_Error( !prev || uint32_compare( prev, curr_key ) > 0 );
01074 prev = curr_key;
01075 }
01076 }
01077 {
01078 uint32 keyto = rand();
01079 uint32 keyfrom = keyto + rand();
01080 const uint32* prev = NULL;
01081 ctl_map_from_to_const_reverse(CompoundTest_map, &spork, &keyfrom, &keyto, curr )
01082 {
01083 Test_Error( !prev || uint32_compare( prev, curr_key ) > 0 );
01084 prev = curr_key;
01085 }
01086 }
01087 CompoundTest_map_splice(&spork, &foon);
01088 Test_Error( CompoundTest_map_count(&foon) == 0);
01089 Test_Error( CompoundTest_map_count(&spork) == (size_t)Test_Size);
01090 {
01091 int tries;
01092 for( tries = 0; tries < 10; ++tries )
01093 {
01094 ctl_map_foreach(CompoundTest_map, &spork, curr)
01095 {
01096 if( !(rand() & 3) )
01097 break;
01098 }
01099 CompoundTest_map_erase(&spork, curr );
01100 }
01101 for( tries = 0; tries < 10; ++tries )
01102 {
01103 uint32 key;
01104 ctl_map_foreach(CompoundTest_map, &spork, curr)
01105 {
01106 if( !(rand() & 3) )
01107 {
01108 key = *curr_key;
01109 break;
01110 }
01111 }
01112 CompoundTest_map_erase_key( &spork, &key );
01113 }
01114 }
01115 {
01116 const uint32* prev = NULL;
01117 size_t count = 0;
01118 ctl_map_foreach(CompoundTest_map, &spork, curr)
01119 {
01120 Test_Error( !prev || uint32_compare( prev, curr_key ) < 0 );
01121 prev = curr_key;
01122 count++;
01123 }
01124 Test_Error( CompoundTest_map_count(&spork) == count );
01125 }
01126
01127
01128 Test_Error( ctl_pool_alloc_count(&CompoundTest_map_pool) == CompoundTest_map_count(&spork) );
01129 CompoundTest_map_destroy(&spork);
01130 CompoundTest_map_destroy(&foon);
01131 Test_Error( 0 == ctl_pool_alloc_count(&CompoundTest_map_pool) );
01132 }
01133
01139 void Test_multimap(void)
01140 {
01141
01142 const size_t Test_Size = 1117;
01143 uint32 keylow = ~0u;
01144 uint32 keyhigh = 0;
01145 CompoundTest_multimap spork, foon;
01146 CompoundTest_multimap_init(&spork);
01147 {
01148 size_t curr;
01149 for( curr = 0; curr < Test_Size; ++curr )
01150 {
01151 uint32 keyval = (uint32)rand();
01152 sXYZ* xyz = CompoundTest_multimap_insert(&spork,&keyval);
01153 xyz->x = type_rand(float32);
01154 xyz->y = type_rand(float32);
01155 xyz->z = type_rand(float32);
01156 if( keyval > keyhigh )
01157 keyhigh = keyval;
01158 if( keyval < keylow )
01159 keylow = keyval;
01160 }
01161 }
01162 Test_Error( CompoundTest_multimap_count(&spork) == Test_Size );
01163 Test_Error( CompoundTest_multimap_ismember( &spork, CompoundTest_multimap_front(&spork) ) );
01164 Test_Error( !CompoundTest_multimap_ismember( &spork, CompoundTest_multimap_front(&spork)-1 ) );
01165 Test_Error( CompoundTest_multimap_ismember( &spork, CompoundTest_multimap_back(&spork) ) );
01166 Test_Error( !CompoundTest_multimap_ismember( &spork, CompoundTest_multimap_back(&spork)+1 ) );
01167 {
01168 sXYZ junk;
01169 Test_Error( !CompoundTest_multimap_ismember( &spork, &junk ) );
01170 }
01171
01172 CompoundTest_multimap_sort(&spork, uint32_rcompare);
01173 CompoundTest_multimap_copy( &foon, &spork );
01174 Test_Error( 0 == CompoundTest_multimap_compare( &foon, &spork ) );
01175 CompoundTest_multimap_sort(&spork, uint32_compare);
01176 Test_Error( CompoundTest_multimap_compare( &foon, &spork ) );
01177 {
01178 const uint32* prev = NULL;
01179 size_t count = 0;
01180 ctl_multimap_foreach_const(CompoundTest_multimap, &spork, curr)
01181 {
01182 Test_Error( !prev || uint32_compare( prev, curr_key ) <= 0 );
01183 prev = curr_key;
01184 count++;
01185 }
01186 Test_Error( count == CompoundTest_multimap_count(&spork) );
01187 }
01188 {
01189 const uint32* prev = NULL;
01190 size_t count = 0;
01191 ctl_multimap_foreach(CompoundTest_multimap, &foon, curr)
01192 {
01193 Test_Error( !prev || uint32_compare( prev, curr_key ) >= 0 );
01194 prev = curr_key;
01195 count++;
01196 }
01197 Test_Error( count == CompoundTest_multimap_count(&foon) );
01198 }
01199 {
01200 const uint32* prev = NULL;
01201 ctl_multimap_foreach_const_reverse(CompoundTest_multimap, &foon, curr)
01202 {
01203 Test_Error( !prev || uint32_compare( prev, curr_key ) <= 0 );
01204 prev = curr_key;
01205 }
01206 }
01207 {
01208 const uint32* prev = NULL;
01209 ctl_multimap_foreach_reverse(CompoundTest_multimap, &spork, curr)
01210 {
01211 Test_Error( !prev || uint32_compare( prev, curr_key ) >= 0 );
01212 prev = curr_key;
01213 }
01214 }
01215 {
01216 const uint32* prev = NULL;
01217 uint32 key = rand();
01218 ctl_multimap_from(CompoundTest_multimap, &spork, &key, curr )
01219 {
01220 Test_Error( !prev || uint32_compare( prev, curr_key ) <= 0 );
01221 prev = curr_key;
01222 }
01223 }
01224 {
01225 const uint32* prev = NULL;
01226 uint32 key = rand();
01227 ctl_multimap_from_const(CompoundTest_multimap, &spork, &key, curr )
01228 {
01229 Test_Error( !prev || uint32_compare( prev, curr_key ) <= 0 );
01230 prev = curr_key;
01231 }
01232 }
01233 {
01234 const uint32* prev = NULL;
01235 uint32 key = rand();
01236 ctl_multimap_from_reverse(CompoundTest_multimap, &spork, &key, curr )
01237 {
01238 Test_Error( !prev || uint32_compare( prev, curr_key ) >= 0 );
01239 prev = curr_key;
01240 }
01241 }
01242 {
01243 const uint32* prev = NULL;
01244 uint32 key = rand();
01245 ctl_multimap_from_const_reverse(CompoundTest_multimap, &spork, &key, curr )
01246 {
01247 Test_Error( !prev || uint32_compare( prev, curr_key ) >= 0 );
01248 prev = curr_key;
01249 }
01250 }
01251 {
01252 const uint32* prev = NULL;
01253 uint32 keyfrom = rand();
01254 uint32 keyto = keyfrom + rand();
01255 ctl_multimap_from_to(CompoundTest_multimap, &spork, &keyfrom, &keyto, curr )
01256 {
01257 Test_Error( !prev || uint32_compare( prev, curr_key ) <= 0 );
01258 prev = curr_key;
01259 }
01260 }
01261 {
01262 const uint32* prev = NULL;
01263 uint32 keyfrom = rand();
01264 uint32 keyto = keyfrom + rand();
01265 ctl_multimap_from_to_const(CompoundTest_multimap, &spork, &keyfrom, &keyto, curr )
01266 {
01267 Test_Error( !prev || uint32_compare( prev, curr_key ) <= 0 );
01268 prev = curr_key;
01269 }
01270 }
01271 {
01272 uint32 keyto = rand();
01273 uint32 keyfrom = keyto + rand();
01274 const uint32* prev = NULL;
01275 ctl_multimap_from_to_reverse(CompoundTest_multimap, &spork, &keyfrom, &keyto, curr )
01276 {
01277 Test_Error( !prev || uint32_compare( prev, curr_key ) >= 0 );
01278 prev = curr_key;
01279 }
01280 }
01281 {
01282 uint32 keyto = rand();
01283 uint32 keyfrom = keyto + rand();
01284 const uint32* prev = NULL;
01285 ctl_multimap_from_to_const_reverse(CompoundTest_multimap, &spork, &keyfrom, &keyto, curr )
01286 {
01287 Test_Error( !prev || uint32_compare( prev, curr_key ) >= 0 );
01288 prev = curr_key;
01289 }
01290 }
01291 CompoundTest_multimap_splice(&spork, &foon);
01292 Test_Error( CompoundTest_multimap_count(&foon) == 0);
01293 Test_Error( CompoundTest_multimap_count(&spork) == (size_t)Test_Size*2);
01294 {
01295 int tries;
01296 for( tries = 0; tries < 10; ++tries )
01297 {
01298 ctl_multimap_foreach(CompoundTest_multimap, &spork, curr)
01299 {
01300 if( !(rand() & 3) )
01301 break;
01302 }
01303 CompoundTest_multimap_erase(&spork, curr );
01304 }
01305 for( tries = 0; tries < 10; ++tries )
01306 {
01307 uint32 key;
01308 ctl_multimap_foreach(CompoundTest_multimap, &spork, curr)
01309 {
01310 if( !(rand() & 3) )
01311 {
01312 key = *curr_key;
01313 break;
01314 }
01315 }
01316 CompoundTest_multimap_erase_key( &spork, &key );
01317 }
01318 }
01319 {
01320 const uint32* prev = NULL;
01321 size_t count = 0;
01322 ctl_multimap_foreach(CompoundTest_multimap, &spork, curr)
01323 {
01324 Test_Error( !prev || uint32_compare( prev, curr_key ) <= 0 );
01325 prev = curr_key;
01326 count++;
01327 }
01328 Test_Error( CompoundTest_multimap_count(&spork) == count );
01329 }
01330
01331
01332 Test_Error( ctl_pool_alloc_count(&CompoundTest_multimap_pool) == CompoundTest_multimap_count(&spork) );
01333 CompoundTest_multimap_destroy(&spork);
01334 CompoundTest_multimap_destroy(&foon);
01335 Test_Error( 0 == ctl_pool_alloc_count(&CompoundTest_multimap_pool) );
01336 }
01337
01343 void Test_set(void)
01344 {
01345
01346 int32 Test_Size = rand_between(int32,100,300);
01347 int32 keylow = int32_max;
01348 int32 keyhigh = int32_min;
01349 IntTest_set spork, foon;
01350 IntTest_set_init(&spork);
01351 {
01352 int curr;
01353 int32 val = rand();
01354 for( curr = 0; curr < Test_Size; ++curr )
01355 {
01356 IntTest_set_insert(&spork,&val);
01357 val += 1+(rand()&7);
01358 if( val > keyhigh )
01359 keyhigh = val;
01360 if( val < keylow )
01361 keylow = val;
01362 }
01363 }
01364 Test_Error( (int32)IntTest_set_count(&spork) == Test_Size );
01365 Test_Error( IntTest_set_ismember( &spork, IntTest_set_front(&spork) ) );
01366 Test_Error( !IntTest_set_ismember( &spork, IntTest_set_front(&spork)-1 ) );
01367 Test_Error( IntTest_set_ismember( &spork, IntTest_set_back(&spork) ) );
01368 Test_Error( !IntTest_set_ismember( &spork, IntTest_set_back(&spork)+1 ) );
01369 Test_Error( !IntTest_set_ismember( &spork, &Test_Size ) );
01370 {
01371 int32 prev = type_min(int32);
01372 ctl_set_foreach_const(IntTest_set, &spork, curr)
01373 {
01374 Test_Error( *curr >= prev );
01375 prev = *curr;
01376 }
01377 }
01378
01379 IntTest_set_sort(&spork, int32_rcompare);
01380 IntTest_set_copy( &foon, &spork );
01381 Test_Error( !IntTest_set_compare( &foon, &spork ) );
01382 IntTest_set_sort(&spork, int32_compare);
01383 Test_Error( IntTest_set_compare( &foon, &spork ) );
01384 {
01385 const int32* prev = NULL;
01386 size_t count = 0;
01387 ctl_set_foreach_const(IntTest_set, &spork, curr)
01388 {
01389 Test_Error( !prev || int32_compare( prev, curr ) < 0 );
01390 prev = curr;
01391 count++;
01392 }
01393 Test_Error( count == IntTest_set_count(&spork) );
01394 }
01395 {
01396 const int32* prev = NULL;
01397 size_t count = 0;
01398 ctl_set_foreach(IntTest_set, &foon, curr)
01399 {
01400 Test_Error( !prev || int32_compare( prev, curr ) > 0 );
01401 prev = curr;
01402 count++;
01403 }
01404 Test_Error( count == IntTest_set_count(&foon) );
01405 }
01406 {
01407 const int32* prev = NULL;
01408 ctl_set_foreach_const_reverse(IntTest_set, &foon, curr)
01409 {
01410 Test_Error( !prev || int32_compare( prev, curr ) < 0 );
01411 prev = curr;
01412 }
01413 }
01414 {
01415 const int32* prev = NULL;
01416 ctl_set_foreach_reverse(IntTest_set, &spork, curr)
01417 {
01418 Test_Error( !prev || int32_compare( prev, curr ) > 0 );
01419 prev = curr;
01420 }
01421 }
01422 {
01423 const int32* prev = NULL;
01424 int32 key = rand();
01425 ctl_set_from(IntTest_set, &spork, &key, curr )
01426 {
01427 Test_Error( !prev || int32_compare( prev, curr ) < 0 );
01428 prev = curr;
01429 }
01430 }
01431 {
01432 const int32* prev = NULL;
01433 int32 key = rand();
01434 ctl_set_from_const(IntTest_set, &spork, &key, curr )
01435 {
01436 Test_Error( !prev || int32_compare( prev, curr ) < 0 );
01437 prev = curr;
01438 }
01439 }
01440 {
01441 const int32* prev = NULL;
01442 int32 key = rand();
01443 ctl_set_from_reverse(IntTest_set, &spork, &key, curr )
01444 {
01445 Test_Error( !prev || int32_compare( prev, curr ) > 0 );
01446 prev = curr;
01447 }
01448 }
01449 {
01450 const int32* prev = NULL;
01451 int32 key = rand();
01452 ctl_set_from_const_reverse(IntTest_set, &spork, &key, curr )
01453 {
01454 Test_Error( !prev || int32_compare( prev, curr ) > 0 );
01455 prev = curr;
01456 }
01457 }
01458 {
01459 const int32* prev = NULL;
01460 int32 keyfrom = rand();
01461 int32 keyto = keyfrom + rand();
01462 ctl_set_from_to(IntTest_set, &spork, &keyfrom, &keyto, curr )
01463 {
01464 Test_Error( !prev || int32_compare( prev, curr ) < 0 );
01465 prev = curr;
01466 }
01467 }
01468 {
01469 const int32* prev = NULL;
01470 int32 keyfrom = rand();
01471 int32 keyto = keyfrom + rand();
01472 ctl_set_from_to_const(IntTest_set, &spork, &keyfrom, &keyto, curr )
01473 {
01474 Test_Error( !prev || int32_compare( prev, curr ) < 0 );
01475 prev = curr;
01476 }
01477 }
01478 {
01479 int32 keyto = rand();
01480 int32 keyfrom = keyto + rand();
01481 const int32* prev = NULL;
01482 ctl_set_from_to_reverse(IntTest_set, &spork, &keyfrom, &keyto, curr )
01483 {
01484 Test_Error( !prev || int32_compare( prev, curr ) > 0 );
01485 prev = curr;
01486 }
01487 }
01488 {
01489 int32 keyto = rand();
01490 int32 keyfrom = keyto + rand();
01491 const int32* prev = NULL;
01492 ctl_set_from_to_const_reverse(IntTest_set, &spork, &keyfrom, &keyto, curr )
01493 {
01494 Test_Error( !prev || int32_compare( prev, curr ) > 0 );
01495 prev = curr;
01496 }
01497 }
01498 IntTest_set_splice(&spork, &foon);
01499 Test_Error( IntTest_set_count(&foon) == 0);
01500 Test_Error( IntTest_set_count(&spork) == (size_t)Test_Size);
01501 {
01502 int tries;
01503 for( tries = 0; tries < 10; ++tries )
01504 {
01505 ctl_set_foreach(IntTest_set, &spork, curr)
01506 {
01507 if( !(rand() & 3) )
01508 break;
01509 }
01510 IntTest_set_erase(&spork, curr );
01511 }
01512 for( tries = 0; tries < 10; ++tries )
01513 {
01514 int32 key;
01515 ctl_set_foreach(IntTest_set, &spork, curr)
01516 {
01517 if( !(rand() & 3) )
01518 {
01519 key = *curr;
01520 break;
01521 }
01522 }
01523 IntTest_set_erase_key( &spork, &key );
01524 }
01525 }
01526 {
01527 const int32* prev = NULL;
01528 size_t count = 0;
01529 ctl_set_foreach(IntTest_set, &spork, curr)
01530 {
01531 Test_Error( !prev || int32_compare( prev, curr ) < 0 );
01532 prev = curr;
01533 count++;
01534 }
01535 Test_Error( IntTest_set_count(&spork) == count );
01536 }
01537
01538
01539 Test_Error( ctl_pool_alloc_count(&IntTest_set_pool) == IntTest_set_count(&spork) );
01540 IntTest_set_destroy(&spork);
01541 IntTest_set_destroy(&foon);
01542 Test_Error( 0 == ctl_pool_alloc_count(&IntTest_set_pool) );
01543 }
01544
01550 void Test_multiset(void)
01551 {
01552
01553 int32 Test_Size = rand_between(int32,100,300);
01554 int32 keylow = int32_max;
01555 int32 keyhigh = int32_min;
01556 IntTest_multiset spork, foon;
01557 IntTest_multiset_init(&spork);
01558 {
01559 int curr;
01560 for( curr = 0; curr < Test_Size; ++curr )
01561 {
01562 int32 val = rand();
01563 IntTest_multiset_insert(&spork,&val);
01564 if( val > keyhigh )
01565 keyhigh = val;
01566 if( val < keylow )
01567 keylow = val;
01568 }
01569 }
01570 Test_Error( (int32)IntTest_multiset_count(&spork) == Test_Size );
01571 Test_Error( IntTest_multiset_ismember( &spork, IntTest_multiset_front(&spork) ) );
01572 Test_Error( !IntTest_multiset_ismember( &spork, IntTest_multiset_front(&spork)-1 ) );
01573 Test_Error( IntTest_multiset_ismember( &spork, IntTest_multiset_back(&spork) ) );
01574 Test_Error( !IntTest_multiset_ismember( &spork, IntTest_multiset_back(&spork)+1 ) );
01575 Test_Error( !IntTest_multiset_ismember( &spork, &Test_Size ) );
01576 {
01577 int32 prev = type_min(int32);
01578 ctl_multiset_foreach_const(IntTest_multiset, &spork, curr)
01579 {
01580 Test_Error( *curr >= prev );
01581 prev = *curr;
01582 }
01583 }
01584
01585 IntTest_multiset_sort(&spork, int32_rcompare);
01586 IntTest_multiset_copy( &foon, &spork );
01587 Test_Error( !IntTest_multiset_compare( &foon, &spork ) );
01588 IntTest_multiset_sort(&spork, int32_compare);
01589 Test_Error( IntTest_multiset_compare( &foon, &spork ) );
01590 {
01591 const int32* prev = NULL;
01592 size_t count = 0;
01593 ctl_multiset_foreach_const(IntTest_multiset, &spork, curr)
01594 {
01595 Test_Error( !prev || int32_compare( prev, curr ) <= 0 );
01596 prev = curr;
01597 count++;
01598 }
01599 Test_Error( count == IntTest_multiset_count(&spork) );
01600 }
01601 {
01602 const int32* prev = NULL;
01603 size_t count = 0;
01604 ctl_multiset_foreach(IntTest_multiset, &foon, curr)
01605 {
01606 Test_Error( !prev || int32_compare( prev, curr ) >= 0 );
01607 prev = curr;
01608 count++;
01609 }
01610 Test_Error( count == IntTest_multiset_count(&foon) );
01611 }
01612 {
01613 const int32* prev = NULL;
01614 ctl_multiset_foreach_const_reverse(IntTest_multiset, &foon, curr)
01615 {
01616 Test_Error( !prev || int32_compare( prev, curr ) <= 0 );
01617 prev = curr;
01618 }
01619 }
01620 {
01621 const int32* prev = NULL;
01622 ctl_multiset_foreach_reverse(IntTest_multiset, &spork, curr)
01623 {
01624 Test_Error( !prev || int32_compare( prev, curr ) >= 0 );
01625 prev = curr;
01626 }
01627 }
01628 {
01629 const int32* prev = NULL;
01630 int32 key = rand();
01631 ctl_multiset_from(IntTest_multiset, &spork, &key, curr )
01632 {
01633 Test_Error( !prev || int32_compare( prev, curr ) <= 0 );
01634 prev = curr;
01635 }
01636 }
01637 {
01638 const int32* prev = NULL;
01639 int32 key = rand();
01640 ctl_multiset_from_const(IntTest_multiset, &spork, &key, curr )
01641 {
01642 Test_Error( !prev || int32_compare( prev, curr ) <= 0 );
01643 prev = curr;
01644 }
01645 }
01646 {
01647 const int32* prev = NULL;
01648 int32 key = rand();
01649 ctl_multiset_from_reverse(IntTest_multiset, &spork, &key, curr )
01650 {
01651 Test_Error( !prev || int32_compare( prev, curr ) >= 0 );
01652 prev = curr;
01653 }
01654 }
01655 {
01656 const int32* prev = NULL;
01657 int32 key = rand();
01658 ctl_multiset_from_const_reverse(IntTest_multiset, &spork, &key, curr )
01659 {
01660 Test_Error( !prev || int32_compare( prev, curr ) >= 0 );
01661 prev = curr;
01662 }
01663 }
01664 {
01665 const int32* prev = NULL;
01666 int32 keyfrom = rand();
01667 int32 keyto = keyfrom + rand();
01668 ctl_multiset_from_to(IntTest_multiset, &spork, &keyfrom, &keyto, curr )
01669 {
01670 Test_Error( !prev || int32_compare( prev, curr ) <= 0 );
01671 prev = curr;
01672 }
01673 }
01674 {
01675 const int32* prev = NULL;
01676 int32 keyfrom = rand();
01677 int32 keyto = keyfrom + rand();
01678 ctl_multiset_from_to_const(IntTest_multiset, &spork, &keyfrom, &keyto, curr )
01679 {
01680 Test_Error( !prev || int32_compare( prev, curr ) <= 0 );
01681 prev = curr;
01682 }
01683 }
01684 {
01685 int32 keyto = rand();
01686 int32 keyfrom = keyto + rand();
01687 const int32* prev = NULL;
01688 ctl_multiset_from_to_reverse(IntTest_multiset, &spork, &keyfrom, &keyto, curr )
01689 {
01690 Test_Error( !prev || int32_compare( prev, curr ) >= 0 );
01691 prev = curr;
01692 }
01693 }
01694 {
01695 int32 keyto = rand();
01696 int32 keyfrom = keyto + rand();
01697 const int32* prev = NULL;
01698 ctl_multiset_from_to_const_reverse(IntTest_multiset, &spork, &keyfrom, &keyto, curr )
01699 {
01700 Test_Error( !prev || int32_compare( prev, curr ) >= 0 );
01701 prev = curr;
01702 }
01703 }
01704 IntTest_multiset_splice(&spork, &foon);
01705 Test_Error( IntTest_multiset_count(&foon) == 0);
01706 Test_Error( IntTest_multiset_count(&spork) == (size_t)Test_Size*2);
01707 {
01708 int tries;
01709 for( tries = 0; tries < 10; ++tries )
01710 {
01711 ctl_multiset_foreach(IntTest_multiset, &spork, curr)
01712 {
01713 if( !(rand() & 3) )
01714 break;
01715 }
01716 IntTest_multiset_erase(&spork, curr );
01717 }
01718 for( tries = 0; tries < 10; ++tries )
01719 {
01720 int32 key;
01721 ctl_multiset_foreach(IntTest_multiset, &spork, curr)
01722 {
01723 if( !(rand() & 3) )
01724 {
01725 key = *curr;
01726 break;
01727 }
01728 }
01729 IntTest_multiset_erase_key( &spork, &key );
01730 }
01731 }
01732 {
01733 const int32* prev = NULL;
01734 size_t count = 0;
01735 ctl_multiset_foreach(IntTest_multiset, &spork, curr)
01736 {
01737 Test_Error( !prev || int32_compare( prev, curr ) <= 0 );
01738 prev = curr;
01739 count++;
01740 }
01741 Test_Error( IntTest_multiset_count(&spork) == count );
01742 }
01743
01744
01745 Test_Error( ctl_pool_alloc_count(&IntTest_multiset_pool) == IntTest_multiset_count(&spork) );
01746 IntTest_multiset_destroy(&spork);
01747 IntTest_multiset_destroy(&foon);
01748 Test_Error( 0 == ctl_pool_alloc_count(&IntTest_multiset_pool) );
01749 }
01750
01756 void Test_DatagenContainers(void)
01757 {
01758 UNIT_TEST(Test_array);
01759 UNIT_TEST(Test_vector);
01760 UNIT_TEST(Test_list);
01761 UNIT_TEST(Test_map);
01762 UNIT_TEST(Test_multimap);
01763 UNIT_TEST(Test_set);
01764 UNIT_TEST(Test_multiset);
01765 }
01766
01772 void Test_DatagenCopy(void)
01773 {
01774
01775 MyClass out, in;
01776 MyClass_init( &out );
01777 MyClass_copy( &in, &out );
01778
01779
01780 Test_Error( !MyClass_compare( &out, &in ) );
01781
01782
01783 MyClass_randomize( &out );
01784 MyClass_destroy( &in );
01785 MyClass_copy( &in, &out );
01786
01787
01788 Test_Error( !MyClass_compare( &out, &in ) );
01789 MyClass_destroy( &out );
01790 MyClass_destroy( &in );
01791
01792
01793 MyClass_init( &out );
01794 MyClass_randomize( &out );
01795 MyClass_move( &in, &out );
01796
01797 MyClass_destroy( &in );
01798 }
01799
01805 void Test_DatagenSerial(void)
01806 {
01807 MyClass out, in;
01808 MyClass_init( &out );
01809 MyClass_init( &in );
01810 Test_Error( !MyClass_compare( &out, &in ) );
01811
01812 MyClass_randomize( &out );
01813 {
01814 size_t calcsize = MyClass_serial_size(&out);
01815 uint8_vector vec;
01816 uint8_vector_init( &vec );
01817 uint8_vector_resize( &vec, calcsize );
01818 {
01819 {
01820 ctl_serial_auto_vector( write, &vec );
01821 MyClass_serial_write( &out, &write );
01822
01823 Test_Error( write.curr == write.end );
01824 }
01825 {
01826 ctl_serial_auto_vector( read, &vec );
01827 MyClass_serial_read( &in, &read );
01828
01829 Test_Error( read.curr == read.end );
01830 }
01831 }
01832 uint8_vector_destroy( &vec );
01833 }
01834 Test_Error( !MyClass_compare( &out, &in ) );
01835 MyClass_destroy( &out );
01836 MyClass_destroy( &in );
01837 }
01838
01844 void Test_DatagenRecord(void)
01845 {
01846 MyClass out, in;
01847 MyClass_init( &out );
01848 MyClass_init( &in );
01849 Test_Error( !MyClass_compare( &out, &in ) );
01850
01851 MyClass_randomize( &out );
01852 {
01853 size_t calcsize = MyClass_record_size(&out,"Top");
01854 uint8_vector vec;
01855 uint8_vector_init( &vec );
01856 uint8_vector_resize( &vec, calcsize );
01857 {
01858 ctl_serial_auto_vector( write, &vec );
01859 MyClass_record_write( &out, &write, "Top" );
01860
01861 Test_Error( write.curr == write.end );
01862 }
01863 {
01864 ctl_serial_auto_vector( read, &vec );
01865 MyClass_record_read( &in, &read, "Top" );
01866 }
01867 uint8_vector_destroy( &vec );
01868 }
01869 Test_Error( !MyClass_compare( &out, &in ) );
01870 MyClass_destroy( &out );
01871 MyClass_destroy( &in );
01872 }
01873
01879 void Test_DatagenXML(void)
01880 {
01881
01882 ctl_gstring_auto(char, xmlbuff );
01883 MyClass out, in;
01884 MyClass_init( &out );
01885 MyClass_init( &in );
01886 Test_Error( !MyClass_compare( &out, &in ) );
01887
01888 MyClass_randomize( &out );
01889 #define USE_FILE_MMAP 0
01890 #define USE_FILE_STDIO 0
01891 {
01892 ctl_xmlwrite write;
01893 ctl_profile_average_begin(XMLFileWriting,"XML Writing");
01894 #if USE_FILE_MMAP || USE_FILE_STDIO
01895 if( ctl_xmlwrite_create( &write, "./blah.xml" ) )
01896 {
01897 write.pretty = true;
01898 MyClass_xml_write( &out, &write, "Test" );
01899 }
01900 #else
01901 if( ctl_xmlwrite_begin( &write, &xmlbuff ) )
01902 {
01903 write.pretty = false;
01904 MyClass_xml_write( &out, &write, "Test" );
01905 }
01906 #endif
01907 ctl_xmlwrite_close( &write );
01908 ctl_profile_average_end(XMLFileWriting);
01909 }
01910
01911 #if USE_FILE_MMAP
01912 {
01913 ctl_mmap map;
01914 ctl_profile_average_begin(XMLFileReading,"XML Reading");
01915 if( ctl_mmap_open( &map, "./blah.xml" ) )
01916 {
01917 ctl_xmlread read;
01918 ctl_xmlread_init( &read, (char*)map.base, (char*)map.base + map.size, NULL, NULL );
01919 MyClass_xml_read( &in, &read, "Test" );
01920 ctl_mmap_close( &map );
01921 }
01922 ctl_profile_average_end(XMLFileReading);
01923 }
01924 #elif USE_FILE_STDIO
01925 {
01926 ctl_xmlread read;
01927 long len;
01928 char* buff;
01929 FILE* fp = fopen("./blah.xml","r");
01930 fseek(fp, 0, SEEK_END);
01931 len = ftell(fp);
01932 ctl_malloc(buff,len);
01933 fseek(fp, 0, SEEK_SET);
01934 fread(buff,len, 1, fp );
01935 ctl_xmlread_init( &read, buff, buff + len, NULL, NULL );
01936 MyClass_xml_read( &in, &read, "Test" );
01937 }
01938 #else
01939 {
01940 ctl_xmlread read;
01941 ctl_xmlread_init( &read, (char*)xmlbuff.begin, (char*)xmlbuff.end, NULL, NULL );
01942 MyClass_xml_read( &in, &read, "Test" );
01943 }
01944 #endif
01945
01946 Test_Error( !MyClass_compare( &out, &in ) );
01947 ctl_gstring_destroy( char, &xmlbuff );
01948 MyClass_destroy( &out );
01949 MyClass_destroy( &in );
01950 }
01951
01952
01953
01954
01955 void DieHorribly( jmp_buf* except )
01956 {
01957
01958 longjmp(*except,1);
01959 }
01960
01964 void Test_Except(void)
01965 {
01966 jmp_buf exception_handler;
01967 Destruction_auto(destructhead);
01968
01969
01970
01971
01972 MyClass demo;
01973 MyClass_init( &demo );
01974 Destruction_add(destructhead,MyClass_destroy,&demo);
01975
01976
01977
01978 if( 0 != setjmp(exception_handler) )
01979 {
01980
01981 Destruction_destroy(destructhead);
01982 return;
01983 }
01984
01985 DieHorribly(&exception_handler);
01986
01987 Test_Error( false );
01988
01989
01990
01991 Destruction_destroy(destructhead);
01992 }
01993
01994
01995 #if 1
01996
01997
01998 void spewu();
01999
02000
02001 #define ctl_declarations "unit/datatest.temp.h"
02002 #include "ctl/dg/patterns.temp.h"
02003
02004
02005 #else
02006
02007
02008 #endif
02009
02010 #endif