int unset_test(bitset_container_t* B) {
    int x;
    for (x = 0; x < 1 << 16; x += 3) {
        bitset_container_unset(B, (uint16_t)x);
    }
    return 0;
}
Ejemplo n.º 2
0
// returns 0 on error, 1 if ok.
int set_get_test() {
    bitset_container_t* B = bitset_container_create();
    int x;
    printf("[%s] %s\n", __FILE__, __func__);
    if (B == NULL) {
        printf("Bug %s, line %d \n", __FILE__, __LINE__);
        return 0;
    }
    for (x = 0; x < 1 << 16; x++) {
        assert(!bitset_container_get(B, x));
    }
    for (x = 0; x < 1 << 16; x += 3) {
        assert(bitset_container_cardinality(B) == x / 3);
        assert(!bitset_container_get(B, x));
        bitset_container_set(B, (uint16_t)x);
        assert(bitset_container_get(B, x));
        assert(bitset_container_cardinality(B) == x / 3 + 1);
    }
    for (x = 0; x < 1 << 16; x++) {
        int isset = bitset_container_get(B, (uint16_t)x);
        int shouldbeset = (x / 3 * 3 == x);
        if (isset != shouldbeset) {
            printf("Bug %s, line %d \n", __FILE__, __LINE__);
            bitset_container_free(B);
            return 0;
        }
    }
    if (bitset_container_cardinality(B) != (1 << 16) / 3 + 1) {
        printf("Bug %s, line %d \n", __FILE__, __LINE__);
        bitset_container_free(B);
        return 0;
    }
    if (bitset_container_compute_cardinality(B) != (1 << 16) / 3 + 1) {
        printf("Bug %s, line %d \n", __FILE__, __LINE__);
        bitset_container_free(B);
        return 0;
    }
    for (x = 0; x < 1 << 16; x += 3) {
        bitset_container_unset(B, (uint16_t)x);
    }
    if (bitset_container_cardinality(B) != 0) {
        printf("Bug %s, line %d \n", __FILE__, __LINE__);
        bitset_container_free(B);
        return 0;
    }
    if (bitset_container_compute_cardinality(B) != 0) {
        printf("Bug %s, line %d \n", __FILE__, __LINE__);
        bitset_container_free(B);
        return 0;
    }
    bitset_container_free(B);
    return 1;
}
Ejemplo n.º 3
0
// returns 0 on error, 1 if ok.
int xor_test() {
    bitset_container_t* B1 = bitset_container_create();
    bitset_container_t* B2 = bitset_container_create();
    bitset_container_t* BI = bitset_container_create();

    int x, c, cx;
    printf("[%s] %s\n", __FILE__, __func__);

    for (x = 0; x < (1 << 16); x += 3) {
        bitset_container_set(B1, (uint16_t)x);
        bitset_container_set(BI, (uint16_t)x);
    }
    for (x = 0; x < (1 << 16);
         x += 62) {  // important: 62 is not divisible by 3
        bitset_container_set(B2, (uint16_t)x);
        bitset_container_set(BI, (uint16_t)x);
    }
    for (x = 0; x < (1 << 16); x += 62 * 3) {
        bitset_container_unset(BI, (uint16_t)x);
    }
    cx = bitset_container_compute_cardinality(BI);  // expected xor
    bitset_container_xor_nocard(B1, B2, BI);
    c = bitset_container_compute_cardinality(BI);
    if (c != cx) {
        printf("Bug %s, line %d \n", __FILE__, __LINE__);
        return 0;
    }
    c = bitset_container_xor(B1, B2, BI);
    if (c != cx) {
        printf("Bug %s, line %d \n", __FILE__, __LINE__);
        return 0;
    }
    bitset_container_free(B1);
    bitset_container_free(B2);
    bitset_container_free(BI);
    return 1;
}