int main() { std::srand( std::time(nullptr) ) ; for( int i = 3 ; i < 10 ; ++i ) { for( int r : unique_rand( 3, i, i*i ) ) std::cout << r << ' ' ; std::cout << '\n' ; } }
int main(void) { int c; intptr_t keys[NUM]; intptr_t vals[NUM]; intptr_t tmp; a_bintree_t tree; srand(time(NULL)); for(c=0;c<NUM;c++) { keys[c] = unique_rand(keys,c); vals[c] = nonzero_rand(); } a_bintree_init(&tree, a_collect_cmp_intptr, NULL, NULL); for(c=0;c<NUM/2;c++) { if(a_bintree_put(&tree, (void *)keys[c], (void *)vals[c])) { a_warn(stack, "failed to put key %d and value %d into tree", keys[c], vals[c]); test_fail(); } } for(c=0;c<NUM/2;c++) { if((tmp = (intptr_t)a_bintree_get(&tree, (void *)keys[c]))!=vals[c]) { a_warn(stack, "expected %d for key %d but got %d", vals[c], keys[c], tmp); test_fail(); } } for(c=NUM/2;c<NUM;c++) { if((tmp = (intptr_t)a_bintree_get(&tree, (void *)keys[c]))!=0) { a_warn(stack, "expected no value for key %d but got %d", keys[c], tmp); test_fail(); } } for(c=NUM/2;c<NUM;c++) { if(a_bintree_put(&tree, (void *)keys[c], (void *)vals[c])) { a_warn(stack, "failed to put key %d and value %d into tree", keys[c], vals[c]); test_fail(); } } for(c=0;c<NUM;c++) { if((tmp = (intptr_t)a_bintree_get(&tree, (void *)keys[c]))!=vals[c]) { a_warn(stack, "expected %d for key %d but got %d", vals[c], keys[c], tmp); test_fail(); } } for(c=0;c<NUM/2;c++) a_bintree_delete(&tree, (void *)keys[c]); for(c=0;c<NUM/2;c++) { if((tmp = (intptr_t)a_bintree_get(&tree, (void *)keys[c]))!=0) { a_warn(stack, "expected no value for key %d but got %d", keys[c], tmp); test_fail(); } } for(c=NUM/2;c<NUM;c++) { if((tmp = (intptr_t)a_bintree_get(&tree, (void *)keys[c]))!=vals[c]) { a_warn(stack, "expected %d for key %d but got %d", vals[c], keys[c], tmp); test_fail(); } } for(c=NUM/2;c<NUM;c++) a_bintree_delete(&tree, (void *)keys[c]); for(c=0;c<NUM;c++) { if((tmp = (intptr_t)a_bintree_get(&tree, (void *)keys[c]))!=0) { a_warn(stack, "expected no value for key %d but got %d", keys[c], tmp); test_fail(); } } a_bintree_cleanup(&tree); test_pass(); }