//{{{ void test_bit_map(void) void test_bit_map(void) { struct bit_map *bm = bit_map_init(100); TEST_ASSERT_EQUAL(0, bit_map_get(bm, 1000)); bit_map_set(bm, 1000); TEST_ASSERT_EQUAL(1, bit_map_get(bm, 1000)); uint32_t A[500]; uint32_t i; A[0] = 1000; for (i = 1; i < 500; ++i) { A[i] = rand() % 10000; bit_map_set(bm, A[i]); } qsort(A, 500, sizeof(uint32_t), uint32_t_cmp); uint32_t j; for (i = 0; i < 499; ++i) { TEST_ASSERT_EQUAL(1, bit_map_get(bm, A[i])); for (j = A[i]+1; j < A[i+1]; ++j) TEST_ASSERT_EQUAL(0, bit_map_get(bm, j)); } char *file_name = "test_bit_map.out"; FILE *f = fopen(file_name, "wb"); bit_map_store(bm, f, file_name); fclose(f); f = fopen(file_name, "rb"); struct bit_map *bm_r = bit_map_load(f, file_name); fclose(f); TEST_ASSERT_EQUAL(bm->num_bits, bm_r->num_bits); TEST_ASSERT_EQUAL(bm->num_ints, bm_r->num_ints); for (i = 0; i < 499; ++i) { TEST_ASSERT_EQUAL(1, bit_map_get(bm_r, A[i])); for (j = A[i]+1; j < A[i+1]; ++j) TEST_ASSERT_EQUAL(0, bit_map_get(bm_r, j)); } bit_map_destroy(&bm); bit_map_destroy(&bm_r); remove(file_name); }
/* Sets up bitmaps for start/middle characters*/ void parser_data_init(parser_data* data, char* start, char* middle) { bit_map_init(data->start_map, start); bit_map_init(data->middle_map, middle); }