| 394 | |
| 395 | #define UNUSED(x) (void)(x) |
| 396 | int intsetTest(int argc, char **argv, int accurate) { |
| 397 | uint8_t success; |
| 398 | int i; |
| 399 | intset *is; |
| 400 | srand(time(NULL)); |
| 401 | |
| 402 | UNUSED(argc); |
| 403 | UNUSED(argv); |
| 404 | UNUSED(accurate); |
| 405 | |
| 406 | printf("Value encodings: "); { |
| 407 | assert(_intsetValueEncoding(-32768) == INTSET_ENC_INT16); |
| 408 | assert(_intsetValueEncoding(+32767) == INTSET_ENC_INT16); |
| 409 | assert(_intsetValueEncoding(-32769) == INTSET_ENC_INT32); |
| 410 | assert(_intsetValueEncoding(+32768) == INTSET_ENC_INT32); |
| 411 | assert(_intsetValueEncoding(-2147483648) == INTSET_ENC_INT32); |
| 412 | assert(_intsetValueEncoding(+2147483647) == INTSET_ENC_INT32); |
| 413 | assert(_intsetValueEncoding(-2147483649) == INTSET_ENC_INT64); |
| 414 | assert(_intsetValueEncoding(+2147483648) == INTSET_ENC_INT64); |
| 415 | assert(_intsetValueEncoding(-9223372036854775808ull) == |
| 416 | INTSET_ENC_INT64); |
| 417 | assert(_intsetValueEncoding(+9223372036854775807ull) == |
| 418 | INTSET_ENC_INT64); |
| 419 | ok(); |
| 420 | } |
| 421 | |
| 422 | printf("Basic adding: "); { |
| 423 | is = intsetNew(); |
| 424 | is = intsetAdd(is,5,&success); assert(success); |
| 425 | is = intsetAdd(is,6,&success); assert(success); |
| 426 | is = intsetAdd(is,4,&success); assert(success); |
| 427 | is = intsetAdd(is,4,&success); assert(!success); |
| 428 | ok(); |
| 429 | zfree(is); |
| 430 | } |
| 431 | |
| 432 | printf("Large number of random adds: "); { |
| 433 | uint32_t inserts = 0; |
| 434 | is = intsetNew(); |
| 435 | for (i = 0; i < 1024; i++) { |
| 436 | is = intsetAdd(is,rand()%0x800,&success); |
| 437 | if (success) inserts++; |
| 438 | } |
| 439 | assert(intrev32ifbe(is->length) == inserts); |
| 440 | checkConsistency(is); |
| 441 | ok(); |
| 442 | zfree(is); |
| 443 | } |
| 444 | |
| 445 | printf("Upgrade from int16 to int32: "); { |
| 446 | is = intsetNew(); |
| 447 | is = intsetAdd(is,32,NULL); |
| 448 | assert(intrev32ifbe(is->encoding) == INTSET_ENC_INT16); |
| 449 | is = intsetAdd(is,65535,NULL); |
| 450 | assert(intrev32ifbe(is->encoding) == INTSET_ENC_INT32); |
| 451 | assert(intsetFind(is,32)); |
| 452 | assert(intsetFind(is,65535)); |
| 453 | checkConsistency(is); |
nothing calls this directly
no test coverage detected