Changeset cf8e43eb3296c5f2e2681f89658e5b9b3c0dd263
- Timestamp:
- 04/27/08 17:17:43 (8 months ago)
- Parents:
- 88f53b244ed21fc4833bef05fb376eb4497a2740
- Children:
- 2142bb1f97bcd9f2283306e84852774fef71d55e
- git-committer:
- David Balmain <dbalmain@gmail.com> / 2008-04-27T17:17:43Z+1000
- Location:
- c
- Files:
-
- 2 modified
-
.rake/gcov.history (modified) (previous)
-
test/test_bitvector.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
c/test/test_bitvector.c
r48290f rcf8e43 147 147 } 148 148 149 #define test_bveq(_bv1, _bv2) \ 150 do { \ 151 BitVector *_not_bv1, *_not_bv2; \ 152 Assert(bv_eq(_bv1, _bv2), "BitVectors are equal"); \ 153 Assert(bv_eq(_bv2, _bv1), "BitVectors are equal"); \ 154 Assert(bv_eq(_bv1, _bv1), "bv_eq on self should work"); \ 155 Aiequal(bv_hash(_bv1), bv_hash(_bv2)); \ 156 /* test flipped bitvectors */ \ 157 _not_bv1 = bv_not(_bv1); _not_bv2 = bv_not(_bv2); \ 158 bv_set(_not_bv1, 1100); /* should make no difference */ \ 159 Assert(bv_eq(_not_bv1, _not_bv2), "BitVectors are equal"); \ 160 Assert(bv_eq(_not_bv2, _not_bv1), "BitVectors are equal"); \ 161 Assert(bv_eq(_not_bv1, _not_bv1), "bv_eq on self should work"); \ 162 Aiequal(bv_hash(_not_bv1), bv_hash(_not_bv2)); \ 163 bv_destroy(_not_bv1); bv_destroy(_not_bv2); \ 164 } while (0) 165 166 #define test_bvneq(_bv1, _bv2) \ 167 do { \ 168 BitVector *_not_bv1, *_not_bv2; \ 169 Assert(!bv_eq(_bv1, _bv2), "BitVectors are not equal"); \ 170 Assert(!bv_eq(_bv2, _bv1), "BitVectors are not equal"); \ 171 Assert(bv_hash(_bv1) != bv_hash(_bv2), "BitVectors not equal"); \ 172 /* test flipped bitvectors */ \ 173 _not_bv1 = bv_not(_bv1); _not_bv2 = bv_not(_bv2); \ 174 Assert(!bv_eq(_not_bv1, _not_bv2), "BitVectors are not equal"); \ 175 Assert(!bv_eq(_not_bv2, _not_bv1), "BitVectors are not equal"); \ 176 Assert(bv_hash(_not_bv1) != bv_hash(_not_bv2), "Bitvectors !=");\ 177 bv_destroy(_not_bv1); bv_destroy(_not_bv2); \ 178 } while (0) 179 149 180 static void test_bv_eq_hash(TestCase *tc, void *data) 150 181 { … … 155 186 (void)data; 156 187 157 Assert(bv_eq(bv1, bv2), "BitVectors are both empty");188 test_bveq(bv1, bv2); 158 189 Assert(bv_eq(bv1, bv1), "bv_eq on self should work"); 159 Aiequal(bv_hash(bv1), bv_hash(bv2));160 190 161 191 bv_set(bv1, 1); 162 Assert(!bv_eq(bv1, bv2), "BitVectors are not equal"); 163 Assert(bv_hash(bv1) != bv_hash(bv2), "BitVectors are not equal"); 192 test_bvneq(bv1, bv2); 164 193 165 194 bv_set(bv2, 11); 166 Assert(!bv_eq(bv1, bv2), "BitVectors are not equal"); 167 Assert(bv_hash(bv1) != bv_hash(bv2), "BitVectors are not equal"); 195 test_bvneq(bv1, bv2); 168 196 169 197 bv_set(bv1, 11); 170 198 bv_set(bv2, 1); 171 Assert(bv_eq(bv1, bv2), "BitVectors are equal");172 Aiequal(bv_hash(bv1), bv_hash(bv2)); 173 174 bv_unset(bv1, 1000); 175 Assert(bv_eq(bv1, bv2), "BitVectors are equal");176 Aiequal(bv_hash(bv1), bv_hash(bv2));199 test_bveq(bv1, bv2); 200 201 /* This will increase size of bv1 to 1000 */ 202 bv_unset(bv1, 1000); 203 /* difference in size shouldn't matter */ 204 test_bveq(bv1, bv2); 177 205 178 206 for (i = 0; i < COUNT; i++) { … … 181 209 bv_set(bv2, bit); 182 210 } 183 184 Assert(bv_eq(bv1, bv2), "BitVectors are equal"); 185 Aiequal(bv_hash(bv1), bv_hash(bv2)); 211 test_bveq(bv1, bv2); 212 186 213 bv_destroy(bv1); 187 214 bv_destroy(bv2); 188 215 216 /* although the saet bits will be equal, the extension will be different*/ 189 217 bv1 = set_bits(bv_new(), "1, 3, 5"); 190 218 bv2 = bv_not_x(set_bits(bv_new(), "0, 2, 4")); 191 219 bv_set(bv2, 5); 192 Assert(!bv_eq(bv1, bv2), "BitVectors have different extension"); 193 Assert(bv_hash(bv1) != bv_hash(bv2), "BitVectors have different extension"); 220 test_bvneq(bv1, bv2); 221 222 bv_destroy(bv2); 223 bv2 = set_bits(bv_new(), "1, 3, 5"); 224 bv1 = bv_not_x(bv1); 225 bv2 = bv_not_x(bv2); 226 bv_unset(bv1, 1000); 227 test_bvneq(bv1, bv2); 228 194 229 bv_destroy(bv1); 195 230 bv_destroy(bv2); … … 203 238 BitVector *bv1 = bv_new(); 204 239 BitVector *bv2 = bv_new(); 240 BitVector *not_bv1, *not_bv2, *or_bv, *not_and_bv; 205 241 char set1[AND_SIZE]; 206 242 char set2[AND_SIZE]; … … 225 261 } 226 262 263 not_bv1 = bv_not(bv1); not_bv2 = bv_not(bv2); 264 and_bv = bv_and(not_bv1, not_bv2); 265 not_and_bv = bv_not(and_bv); 266 or_bv = bv_or(bv1, bv2); 267 Assert(bv_eq(not_and_bv, or_bv), "BitVectors should be equal"); 268 bv_destroy(not_bv1); bv_destroy(not_bv2); 269 bv_destroy(and_bv); 270 bv_destroy(not_and_bv); 271 bv_destroy(or_bv); 272 227 273 and_bv = bv_and(bv1, bv2); 228 274 … … 231 277 Aiequal(set2[i], bv_get(and_bv, i)); 232 278 } 279 233 280 234 281 bv1 = bv_and_x(bv1, bv2); … … 469 516 (void)data; /* suppress unused argument warning */ 470 517 471 /*472 clock_t t = clock(), total_t = 0;473 */474 475 518 for (i = BV_SCAN_INC; i < BV_SCAN_SIZE; i += BV_SCAN_INC) { 476 519 bv_set_fast(bv, i); … … 481 524 482 525 not_bv = bv_not(bv); 483 /*484 t = clock() - t;485 total_t += t;486 printf("bv_set took %0.3f secs\n", (double) (t) / CLOCKS_PER_SEC);487 t = clock();488 */489 526 490 527 for (i = BV_SCAN_INC; i < BV_SCAN_SIZE; i += BV_SCAN_INC) { … … 495 532 Aiequal(-1, bv_scan_next_unset_from(not_bv, i - BV_SCAN_INC / 2)); 496 533 497 /* 498 t = clock() - t; 499 total_t += t; 500 printf("bv_scan_next_from took %0.3f secs\n", (double) (t) / CLOCKS_PER_SEC); 501 t = clock(); 502 */ 534 /* test scan_next_from where size is actually greater than the highest set 535 * bit */ 536 bv->size++; 537 not_bv->size++; 538 539 bv_scan_reset(bv); 540 bv_scan_reset(not_bv); 541 for (i = BV_SCAN_INC; i < BV_SCAN_SIZE; i += BV_SCAN_INC) { 542 Aiequal(i, bv_scan_next_from(bv, i - BV_SCAN_INC / 2)); 543 Aiequal(i, bv_scan_next_unset_from(not_bv, i - BV_SCAN_INC / 2)); 544 } 545 Aiequal(-1, bv_scan_next_from(bv, i - BV_SCAN_INC / 2)); 546 Aiequal(-1, bv_scan_next_unset_from(not_bv, i - BV_SCAN_INC / 2)); 503 547 504 548 bv_scan_reset(bv); … … 511 555 Aiequal(-1, bv_scan_next_unset(not_bv)); 512 556 513 /*514 t = clock() - t;515 total_t += t;516 printf("bv_scan_next took %0.3f secs\n", (double) (t) / CLOCKS_PER_SEC);517 */518 519 557 bv_clear(bv); 520 558 bv_destroy(not_bv); … … 524 562 not_bv = bv_not(bv); 525 563 526 /*527 t = clock();528 */529 530 564 for (i = 0; i < BV_DENSE_SCAN_SIZE; i++) { 531 565 Aiequal(i, bv_scan_next_from(bv, i)); … … 534 568 Aiequal(-1, bv_scan_next_from(bv, i)); 535 569 Aiequal(-1, bv_scan_next_unset_from(not_bv, i)); 536 537 /*538 t = clock() - t;539 total_t += t;540 printf("dense bv_scan_next_from took %0.3f secs\n", (double) (t) / CLOCKS_PER_SEC);541 t = clock();542 */543 570 544 571 bv_scan_reset(bv); … … 550 577 Aiequal(-1, bv_scan_next(bv)); 551 578 Aiequal(-1, bv_scan_next_unset(not_bv)); 552 553 /*554 t = clock() - t;555 total_t += t;556 printf("dense bv_scan_next took %0.3f secs\n", (double) t / CLOCKS_PER_SEC);557 printf("total time %0.3f seconds\n",558 (double) total_t / CLOCKS_PER_SEC);559 */560 579 561 580 bv_destroy(bv);
