Skip to content

BitVecGet

Description

Get the value of bit at given index in bitvector.

Parameters

Name Direction Description
bv in Bitvector to get bit from.
idx in Index of bit to get (0-based), in [0, length).

Usage example (from documentation)

  bool flag = BitVecGet(&flags, 5);

Success

Returns true when the bit is set, false when it is clear. The bitvector is not modified.

Failure

Function cannot fail. An out-of-range idx is a caller bug and aborts via LOG_FATAL.

Usage example (Cross-references)

Usage examples (Cross-references)
    
        for (u64 i = 0; i < bv->length; i++) {
            bool bit = BitVecGet(bv, i);
            BitVecSet(out, i, bit);
        }
    }
    
    bool BitVecGet(const BitVec *bitvec, u64 idx) {
        ValidateBitVec(bitvec);
        if (idx >= bitvec->length) {
            LOG_FATAL("Cannot pop from empty bitvector");
        }
        bool value = BitVecGet(bitvec, bitvec->length - 1);
        BitVecResize(bitvec, bitvec->length - 1);
        return value;
    
        for (u64 i = bitvec->length - 1; i > idx; i--) {
            bool bit = BitVecGet(bitvec, i - 1);
            BitVecSet(bitvec, i, bit);
        }
        for (u64 i = old_length; i > idx;) {
            i--;
            bool bit = BitVecGet(bv, i);
            BitVecSet(bv, i + count, bit);
        }
        for (u64 i = old_length; i > idx;) {
            i--;
            bool bit = BitVecGet(bv, i);
            BitVecSet(bv, i + other->length, bit);
        }
    
        for (u64 i = 0; i < other->length; i++) {
            bool bit = BitVecGet(other, i);
            BitVecSet(bv, idx + i, bit);
        }
        for (u64 i = old_length; i > idx;) {
            i--;
            bool bit = BitVecGet(bv, i);
            BitVecSet(bv, i + pattern_bits, bit);
        }
        }
    
        bool removed_bit = BitVecGet(bv, idx);
    
        for (u64 i = idx; i < bv->length - 1; i++) {
    
        for (u64 i = idx; i < bv->length - 1; i++) {
            bool bit = BitVecGet(bv, i + 1);
            BitVecSet(bv, i, bit);
        }
    
        for (u64 i = idx + count; i < bv->length; i++) {
            bool bit = BitVecGet(bv, i);
            BitVecSet(bv, i - count, bit);
        }
        // a survivor, so survivors slide leftward into the gaps left by matches.
        for (u64 read_idx = 0; read_idx < bv->length; read_idx++) {
            bool bit = BitVecGet(bv, read_idx);
            if (bit != value) {
                if (write_idx != read_idx) {
        u64 count = 0;
        for (u64 i = 0; i < bitvec->length; i++) {
            if (BitVecGet(bitvec, i)) {
                count++;
            }
    
        for (u64 i = 0; i < min_len; i++) {
            bool bit_a = BitVecGet(a, i);
            bool bit_b = BitVecGet(b, i);
            BitVecSet(result, i, bit_a && bit_b);
        for (u64 i = 0; i < min_len; i++) {
            bool bit_a = BitVecGet(a, i);
            bool bit_b = BitVecGet(b, i);
            BitVecSet(result, i, bit_a && bit_b);
        }
    
        for (u64 i = 0; i < max_len; i++) {
            bool bit_a = i < a->length ? BitVecGet(a, i) : false;
            bool bit_b = i < b->length ? BitVecGet(b, i) : false;
            BitVecSet(result, i, bit_a || bit_b);
        for (u64 i = 0; i < max_len; i++) {
            bool bit_a = i < a->length ? BitVecGet(a, i) : false;
            bool bit_b = i < b->length ? BitVecGet(b, i) : false;
            BitVecSet(result, i, bit_a || bit_b);
        }
    
        for (u64 i = 0; i < max_len; i++) {
            bool bit_a = i < a->length ? BitVecGet(a, i) : false;
            bool bit_b = i < b->length ? BitVecGet(b, i) : false;
            BitVecSet(result, i, bit_a != bit_b);
        for (u64 i = 0; i < max_len; i++) {
            bool bit_a = i < a->length ? BitVecGet(a, i) : false;
            bool bit_b = i < b->length ? BitVecGet(b, i) : false;
            BitVecSet(result, i, bit_a != bit_b);
        }
    
        for (u64 i = 0; i < bitvec->length; i++) {
            bool bit = BitVecGet(bitvec, i);
            BitVecSet(result, i, !bit);
        }
    
        for (u64 i = 0; i < len; i++) {
            if (BitVecGet(bv1, start1 + i) != BitVecGet(bv2, start2 + i)) {
                return false;
            }
    
        for (u64 i = 0; i < len; i++) {
            bool bit1 = BitVecGet(bv1, start1 + i);
            bool bit2 = BitVecGet(bv2, start2 + i);
        for (u64 i = 0; i < len; i++) {
            bool bit1 = BitVecGet(bv1, start1 + i);
            bool bit2 = BitVecGet(bv2, start2 + i);
    
            // 1 sorts after 0; once a position differs the order is fixed
        for (u64 i = max_len; i > 0;) {
            i--;
            bool bit1 = i < bv1->length ? BitVecGet(bv1, i) : false;
            bool bit2 = i < bv2->length ? BitVecGet(bv2, i) : false;
            i--;
            bool bit1 = i < bv1->length ? BitVecGet(bv1, i) : false;
            bool bit2 = i < bv2->length ? BitVecGet(bv2, i) : false;
    
            if (bit1 != bit2) {
        // Two's-complement: the top bit is the sign, so a set MSB means
        // negative and an unset one means non-negative.
        bool sign1 = bv1->length > 0 ? BitVecGet(bv1, bv1->length - 1) : false;
        bool sign2 = bv2->length > 0 ? BitVecGet(bv2, bv2->length - 1) : false;
        // negative and an unset one means non-negative.
        bool sign1 = bv1->length > 0 ? BitVecGet(bv1, bv1->length - 1) : false;
        bool sign2 = bv2->length > 0 ? BitVecGet(bv2, bv2->length - 1) : false;
    
        if (sign1 != sign2) {
    
        for (u64 i = 0; i < max_len; i++) {
            bool bit1 = i < bv1->length ? BitVecGet(bv1, i) : false;
            bool bit2 = i < bv2->length ? BitVecGet(bv2, i) : false;
        for (u64 i = 0; i < max_len; i++) {
            bool bit1 = i < bv1->length ? BitVecGet(bv1, i) : false;
            bool bit2 = i < bv2->length ? BitVecGet(bv2, i) : false;
    
            if (bit1 && !bit2) {
    
        for (u64 i = 0; i < min_len; i++) {
            if (BitVecGet(bv1, i) && BitVecGet(bv2, i)) {
                return false;
            }
    
        for (u64 i = 0; i < bv->length; i++) {
            bool bit = BitVecGet(bv, i);
    
            if (bit) {
    
        for (u64 i = 0; i < bv->length; i++) {
            char bit_char = BitVecGet(bv, i) ? '1' : '0';
            if (!StrPushBackR(out, bit_char)) {
                StrDeinit(out);
    
        for (u64 i = 0; i < bv->length && i / 8 < bytes_to_copy; i++) {
            if (BitVecGet(bv, i)) {
                u64 byte_idx     = i / 8;
                u64 bit_offset   = i % 8;
    
        for (u64 i = 0; i < max_bits; i++) {
            if (BitVecGet(bv, i)) {
                result |= (1ULL << i);
            }
        // by an earlier iteration writing into a higher index.
        for (u64 i = bv->length - 1; i >= positions; i--) {
            bool bit = BitVecGet(bv, i - positions);
            BitVecSet(bv, i, bit);
        }
    
        for (u64 i = 0; i < bv->length - positions; i++) {
            bool bit = BitVecGet(bv, i + positions);
            BitVecSet(bv, i, bit);
        }
        for (u64 i = 0; i < bv->length; i++) {
            u64  src_idx = (i + positions) % bv->length;
            bool bit     = BitVecGet(&temp, src_idx);
            BitVecSet(bv, i, bit);
        }
        for (u64 i = 0; i < bv->length; i++) {
            u64  src_idx = (i + bv->length - positions) % bv->length;
            bool bit     = BitVecGet(&temp, src_idx);
            BitVecSet(bv, i, bit);
        }
        for (u64 i = 0; i < bv->length / 2; i++) {
            u64  j     = bv->length - 1 - i;
            bool bit_i = BitVecGet(bv, i);
            bool bit_j = BitVecGet(bv, j);
            BitVecSet(bv, i, bit_j);
            u64  j     = bv->length - 1 - i;
            bool bit_i = BitVecGet(bv, i);
            bool bit_j = BitVecGet(bv, j);
            BitVecSet(bv, i, bit_j);
            BitVecSet(bv, j, bit_i);
    
        for (u64 i = 0; i < bv->length; i++) {
            if (BitVecGet(bv, i) == value) {
                return i;
            }
        // wraps to SIZE_MAX, which fails the loop condition.
        for (u64 i = bv->length - 1; i < bv->length; i--) {
            if (BitVecGet(bv, i) == value) {
                return i;
            }
    
        for (u64 i = 0; i < bv->length; i++) {
            if (BitVecGet(bv, i) != value) {
                return false;
            }
    
        for (u64 i = 0; i < bv->length; i++) {
            if (BitVecGet(bv, i) == value) {
                current_run++;
                if (current_run > max_run) {
        u64  run_count          = 0;
        u64  current_run_length = 1;
        bool current_value      = BitVecGet(bv, 0);
    
        for (u64 i = 1; i < bv->length; i++) {
    
        for (u64 i = 1; i < bv->length; i++) {
            bool bit = BitVecGet(bv, i);
            if (bit == current_value) {
                current_run_length++;
    
        u64  current_run_length = 1;
        bool current_value      = BitVecGet(bv, 0);
    
        for (u64 i = 1; i < bv->length; i++) {
    
        for (u64 i = 1; i < bv->length; i++) {
            bool bit = BitVecGet(bv, i);
            if (bit == current_value) {
                current_run_length++;
    
        for (u64 i = 0; i < min_length; i++) {
            if (BitVecGet(bv1, i) != BitVecGet(bv2, i)) {
                distance++;
            }
    
        for (u64 i = 0; i < max_length; i++) {
            bool bit1 = (i < bv1->length) ? BitVecGet(bv1, i) : false;
            bool bit2 = (i < bv2->length) ? BitVecGet(bv2, i) : false;
        for (u64 i = 0; i < max_length; i++) {
            bool bit1 = (i < bv1->length) ? BitVecGet(bv1, i) : false;
            bool bit2 = (i < bv2->length) ? BitVecGet(bv2, i) : false;
    
            if (bit1 || bit2) {
    
        for (u64 i = 0; i < min_length; i++) {
            if (BitVecGet(bv1, i) && BitVecGet(bv2, i)) {
                product++;
            }
    
            for (u64 j = 1; j <= len2; j++) {
                u64 cost = BitVecGet(bv1, i - 1) == BitVecGet(bv2, j - 1) ? 0 : 1;
    
                u64 deletion     = prev_row[j] + 1;
    
        for (u64 i = 0; i < max_length; i++) {
            double val1 = (i < bv1->length && BitVecGet(bv1, i)) ? 1.0 : 0.0;
            double val2 = (i < bv2->length && BitVecGet(bv2, i)) ? 1.0 : 0.0;
        for (u64 i = 0; i < max_length; i++) {
            double val1 = (i < bv1->length && BitVecGet(bv1, i)) ? 1.0 : 0.0;
            double val2 = (i < bv2->length && BitVecGet(bv2, i)) ? 1.0 : 0.0;
    
            sum1        += val1;
    
        for (u64 i = 0; i < min_length; i++) {
            if (BitVecGet(bv1, i) == BitVecGet(bv2, i)) {
                score += match;
            } else {
    
            for (u64 i = 0; i < bv2->length && (offset + i) < bv1->length; i++) {
                if (BitVecGet(bv1, offset + i) == BitVecGet(bv2, i)) {
                    score++;
                } else {
    
        for (u64 i = 0; i < pattern->length; i++) {
            if (BitVecGet(bv, idx + i) != BitVecGet(pattern, i)) {
                return false;
            }
    
        for (u64 i = 0; i < new_pattern->length; i++) {
            if (!BitVecInsert(bv, pos + i, BitVecGet(new_pattern, i))) {
                return false;
            }
    
            for (u64 i = 0; i < new_pattern->length; i++) {
                if (!BitVecInsert(bv, match_pos + i, BitVecGet(new_pattern, i))) {
                    return replacements;
                }
        for (u64 i = 0; i < bv->length; i++) {
            // wildcard bit clear = position is fixed; the pattern must match.
            if (!BitVecGet(wildcard, i)) {
                if (BitVecGet(bv, i) != BitVecGet(pattern, i)) {
                    return false;
            // wildcard bit clear = position is fixed; the pattern must match.
            if (!BitVecGet(wildcard, i)) {
                if (BitVecGet(bv, i) != BitVecGet(pattern, i)) {
                    return false;
                }
            u64 errors = 0;
            for (u64 j = 0; j < pattern->length; j++) {
                if (BitVecGet(bv, i + j) != BitVecGet(pattern, j)) {
                    errors++;
                    if (errors > max_errors) {
    
        for (u64 i = BitVecLen(INT_BITS(value)); i > 0; i--) {
            if (BitVecGet(INT_BITS(value), i - 1)) {
                return i;
            }
    static bool int_is_odd(const Int *value) {
        ValidateInt(value);
        return BitVecLen(INT_BITS(value)) > 0 && BitVecGet(INT_BITS(value), 0);
    }
    static bool int_is_one(const Int *value) {
        ValidateInt(value);
        return IntBitLength(value) == 1 && BitVecGet(INT_BITS(value), 0);
    }
    
        for (u64 i = 0; i < BitVecLen(INT_BITS(value)); i++) {
            if (BitVecGet(INT_BITS(value), i)) {
                return i;
            }
                u64 bit_idx = i * 8 + bit;
    
                if (bit_idx < BitVecLen(INT_BITS(value)) && BitVecGet(INT_BITS(value), bit_idx)) {
                    byte |= (u8)(1u << bit);
                }
                u64 bit_idx = i * 8 + bit;
    
                if (bit_idx < BitVecLen(INT_BITS(value)) && BitVecGet(INT_BITS(value), bit_idx)) {
                    byte |= (u8)(1u << bit);
                }
    
        for (u64 i = a_bits; i > 0; i--) {
            bool a_bit = BitVecGet(INT_BITS(a), i - 1);
            bool b_bit = BitVecGet(INT_BITS(b), i - 1);
        for (u64 i = a_bits; i > 0; i--) {
            bool a_bit = BitVecGet(INT_BITS(a), i - 1);
            bool b_bit = BitVecGet(INT_BITS(b), i - 1);
    
            if (a_bit != b_bit) {
    
        for (u64 i = bits; i > 0; i--) {
            BitVecSet(INT_BITS(value), i - 1 + positions, BitVecGet(INT_BITS(value), i - 1));
        }
    
        for (u64 i = 0; i + positions < bits; i++) {
            BitVecSet(INT_BITS(value), i, BitVecGet(INT_BITS(value), i + positions));
        }
            u64 sum = carry ? 1u : 0u;
    
            if (i < a_bits && BitVecGet(INT_BITS(a), i)) {
                sum++;
            }
                sum++;
            }
            if (i < b_bits && BitVecGet(INT_BITS(b), i)) {
                sum++;
            }
    
        for (u64 i = 0; i < a_bits; i++) {
            int ai   = (i < a_bits && BitVecGet(INT_BITS(a), i)) ? 1 : 0;
            int bi   = (i < b_bits && BitVecGet(INT_BITS(b), i)) ? 1 : 0;
            int diff = ai - bi - (borrow ? 1 : 0);
        for (u64 i = 0; i < a_bits; i++) {
            int ai   = (i < a_bits && BitVecGet(INT_BITS(a), i)) ? 1 : 0;
            int bi   = (i < b_bits && BitVecGet(INT_BITS(b), i)) ? 1 : 0;
            int diff = ai - bi - (borrow ? 1 : 0);
    
        for (u64 i = 0; i < b_bits; i++) {
            if (!BitVecGet(INT_BITS(b), i)) {
                continue;
            }
        // Check that data is still intact
        result = result && (BitVecLen(&bv) == 3);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        result = result && (BitVecLen(&bv) == 3);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
    
        // Clean up
    
        // Check that data is still intact
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        // Check that data is still intact
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
    
        // Try to set capacity smaller than current length (should not shrink below length)
    
        // Data should still be intact
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        // Data should still be intact
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
    
        // Clean up
        // Check bv1 (should now have bv2's original content)
        result = result && (BitVecLen(&bv1) == 2);
        result = result && (BitVecGet(&bv1, 0) == false);
        result = result && (BitVecGet(&bv1, 1) == false);
        result = result && (BitVecLen(&bv1) == 2);
        result = result && (BitVecGet(&bv1, 0) == false);
        result = result && (BitVecGet(&bv1, 1) == false);
    
        // Check bv2 (should now have bv1's original content)
        // Check bv2 (should now have bv1's original content)
        result = result && (BitVecLen(&bv2) == 3);
        result = result && (BitVecGet(&bv2, 0) == true);
        result = result && (BitVecGet(&bv2, 1) == false);
        result = result && (BitVecGet(&bv2, 2) == true);
        result = result && (BitVecLen(&bv2) == 3);
        result = result && (BitVecGet(&bv2, 0) == true);
        result = result && (BitVecGet(&bv2, 1) == false);
        result = result && (BitVecGet(&bv2, 2) == true);
        result = result && (BitVecGet(&bv2, 0) == true);
        result = result && (BitVecGet(&bv2, 1) == false);
        result = result && (BitVecGet(&bv2, 2) == true);
    
        // Clean up
    
        for (u64 i = 0; i < BitVecLen(&original); i++) {
            result = result && (BitVecGet(&clone, i) == BitVecGet(&original, i));
        }
        // Clone should remain unchanged
        result = result && (BitVecLen(&clone) == 4) && (BitVecLen(&original) == 5);
        result = result && (BitVecGet(&clone, 0) == true);
        result = result && (BitVecGet(&clone, 1) == false);
        result = result && (BitVecGet(&clone, 2) == true);
        result = result && (BitVecLen(&clone) == 4) && (BitVecLen(&original) == 5);
        result = result && (BitVecGet(&clone, 0) == true);
        result = result && (BitVecGet(&clone, 1) == false);
        result = result && (BitVecGet(&clone, 2) == true);
        result = result && (BitVecGet(&clone, 3) == false);
        result = result && (BitVecGet(&clone, 0) == true);
        result = result && (BitVecGet(&clone, 1) == false);
        result = result && (BitVecGet(&clone, 2) == true);
        result = result && (BitVecGet(&clone, 3) == false);
        result = result && (BitVecGet(&clone, 1) == false);
        result = result && (BitVecGet(&clone, 2) == true);
        result = result && (BitVecGet(&clone, 3) == false);
    
        // Modify clone to verify independence
    
        // Original should remain unchanged at index 0
        result = result && (BitVecGet(&original, 0) == true);
        result = result && (BitVecGet(&clone, 0) == false);
        // Original should remain unchanged at index 0
        result = result && (BitVecGet(&original, 0) == true);
        result = result && (BitVecGet(&clone, 0) == false);
    
        // Clean up
                      BitVecAllocator(&clone)->effort == BitVecAllocator(&original)->effort &&
                      BitVecAllocator(&clone)->retry_limit == BitVecAllocator(&original)->retry_limit &&
                      BitVecGet(&clone, 0) == true && BitVecGet(&clone, 1) == false && BitVecGet(&clone, 2) == true;
    
        BitVecDeinit(&original);
        BitVecShrinkToFit(&bv);
        result = result && (BitVecLen(&bv) == 1) && (BitVecCapacity(&bv) >= 1);
        result = result && (BitVecGet(&bv, 0) == true);
    
        // Test multiple shrinks (should be safe)
        result = result && (BitVecLen(&bv) == original_length);
        for (u64 i = 0; i < BitVecLen(&bv); i++) {
            result = result && (BitVecGet(&bv, i) == (i % 2 == 0));
        }
        result = result && (BitVecLen(&bv1) == 0);
        result = result && (BitVecLen(&bv2) == 2);
        result = result && (BitVecGet(&bv2, 0) == true);
        result = result && (BitVecGet(&bv2, 1) == false);
        result = result && (BitVecLen(&bv2) == 2);
        result = result && (BitVecGet(&bv2, 0) == true);
        result = result && (BitVecGet(&bv2, 1) == false);
    
        // Test swap with large data
        BitVecSwap(&bv1, &bv2);
        result = result && (BitVecLen(&bv1) == 2) && (BitVecLen(&bv2) == 1000);
        result = result && (BitVecGet(&bv2, 0) == true); // 0 % 3 == 0
        result = result && (BitVecGet(&bv2, 999) == (999 % 3 == 0));
        result = result && (BitVecLen(&bv1) == 2) && (BitVecLen(&bv2) == 1000);
        result = result && (BitVecGet(&bv2, 0) == true); // 0 % 3 == 0
        result = result && (BitVecGet(&bv2, 999) == (999 % 3 == 0));
    
        // Test swapping with itself (should be safe)
        BitVec clone2 = BitVecClone(&bv);
        result        = result && (BitVecLen(&clone2) == 1);
        result        = result && (BitVecGet(&clone2, 0) == true);
        BitVecDeinit(&clone2);
        // Verify all bits match
        for (u64 i = 0; i < 1000; i++) {
            result = result && (BitVecGet(&clone3, i) == BitVecGet(&bv, i));
        }
    
        // Test independence - modify original
        BitVecSet(&bv, 0, !BitVecGet(&bv, 0));
        result = result && (BitVecGet(&clone3, 0) != BitVecGet(&bv, 0));
        // Test independence - modify original
        BitVecSet(&bv, 0, !BitVecGet(&bv, 0));
        result = result && (BitVecGet(&clone3, 0) != BitVecGet(&bv, 0));
    
        BitVecDeinit(&clone3);
            result = result && (BitVecLen(&clone) == cycle * 10);
            if (cycle > 0) {
                result = result && (BitVecGet(&clone, 0) == true); // 0 % 2 == 0
            }
        // Expected result: 1000 (1101 AND 1010)
        bool test_result = (BitVecLen(&result) == 4);
        test_result      = test_result && (BitVecGet(&result, 0) == true);
        test_result      = test_result && (BitVecGet(&result, 1) == false);
        test_result      = test_result && (BitVecGet(&result, 2) == false);
        bool test_result = (BitVecLen(&result) == 4);
        test_result      = test_result && (BitVecGet(&result, 0) == true);
        test_result      = test_result && (BitVecGet(&result, 1) == false);
        test_result      = test_result && (BitVecGet(&result, 2) == false);
        test_result      = test_result && (BitVecGet(&result, 3) == false);
        test_result      = test_result && (BitVecGet(&result, 0) == true);
        test_result      = test_result && (BitVecGet(&result, 1) == false);
        test_result      = test_result && (BitVecGet(&result, 2) == false);
        test_result      = test_result && (BitVecGet(&result, 3) == false);
        test_result      = test_result && (BitVecGet(&result, 1) == false);
        test_result      = test_result && (BitVecGet(&result, 2) == false);
        test_result      = test_result && (BitVecGet(&result, 3) == false);
    
        // Clean up
        // Expected result: 1110 (1100 OR 1010)
        bool test_result = (BitVecLen(&result) == 4);
        test_result      = test_result && (BitVecGet(&result, 0) == true);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == true);
        bool test_result = (BitVecLen(&result) == 4);
        test_result      = test_result && (BitVecGet(&result, 0) == true);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == true);
        test_result      = test_result && (BitVecGet(&result, 3) == false);
        test_result      = test_result && (BitVecGet(&result, 0) == true);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == true);
        test_result      = test_result && (BitVecGet(&result, 3) == false);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == true);
        test_result      = test_result && (BitVecGet(&result, 3) == false);
    
        // Clean up
        // Expected result: 0110 (1100 XOR 1010)
        bool test_result = (BitVecLen(&result) == 4);
        test_result      = test_result && (BitVecGet(&result, 0) == false);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == true);
        bool test_result = (BitVecLen(&result) == 4);
        test_result      = test_result && (BitVecGet(&result, 0) == false);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == true);
        test_result      = test_result && (BitVecGet(&result, 3) == false);
        test_result      = test_result && (BitVecGet(&result, 0) == false);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == true);
        test_result      = test_result && (BitVecGet(&result, 3) == false);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == true);
        test_result      = test_result && (BitVecGet(&result, 3) == false);
    
        // Clean up
        // Expected result: 0101 (NOT 1010)
        bool test_result = (BitVecLen(&result) == 4);
        test_result      = test_result && (BitVecGet(&result, 0) == false);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == false);
        bool test_result = (BitVecLen(&result) == 4);
        test_result      = test_result && (BitVecGet(&result, 0) == false);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == false);
        test_result      = test_result && (BitVecGet(&result, 3) == true);
        test_result      = test_result && (BitVecGet(&result, 0) == false);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == false);
        test_result      = test_result && (BitVecGet(&result, 3) == true);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == false);
        test_result      = test_result && (BitVecGet(&result, 3) == true);
    
        // Clean up
        // New bit[1] = 0 (filled)
        // Expected result: 0010
        test_result = test_result && (BitVecGet(&bv, 0) == false);
        test_result = test_result && (BitVecGet(&bv, 1) == false);
        test_result = test_result && (BitVecGet(&bv, 2) == true);
        // Expected result: 0010
        test_result = test_result && (BitVecGet(&bv, 0) == false);
        test_result = test_result && (BitVecGet(&bv, 1) == false);
        test_result = test_result && (BitVecGet(&bv, 2) == true);
        test_result = test_result && (BitVecGet(&bv, 3) == false);
        test_result = test_result && (BitVecGet(&bv, 0) == false);
        test_result = test_result && (BitVecGet(&bv, 1) == false);
        test_result = test_result && (BitVecGet(&bv, 2) == true);
        test_result = test_result && (BitVecGet(&bv, 3) == false);
        test_result = test_result && (BitVecGet(&bv, 1) == false);
        test_result = test_result && (BitVecGet(&bv, 2) == true);
        test_result = test_result && (BitVecGet(&bv, 3) == false);
    
        // Clean up
    
        bool test_result = (BitVecLen(&bv) == 4);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        bool test_result = (BitVecLen(&bv) == 4);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        test_result      = test_result && (BitVecGet(&bv, 3) == false);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        test_result      = test_result && (BitVecGet(&bv, 3) == false);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        test_result      = test_result && (BitVecGet(&bv, 3) == false);
    
        // Clean up
        // Expected result: 1110 (1011 rotated left by 2)
        bool test_result = (BitVecLen(&bv) == 4);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == true);
        bool test_result = (BitVecLen(&bv) == 4);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == true);
        test_result      = test_result && (BitVecGet(&bv, 3) == false);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == true);
        test_result      = test_result && (BitVecGet(&bv, 3) == false);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == true);
        test_result      = test_result && (BitVecGet(&bv, 3) == false);
    
        // Clean up
        // Expected result: 1101 (1011 rotated right by 1)
        bool test_result = (BitVecLen(&bv) == 4);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        bool test_result = (BitVecLen(&bv) == 4);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        test_result      = test_result && (BitVecGet(&bv, 3) == true);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        test_result      = test_result && (BitVecGet(&bv, 3) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        test_result      = test_result && (BitVecGet(&bv, 3) == true);
    
        // Clean up
        // Expected result: 1101 (1011 reversed)
        bool test_result = (BitVecLen(&bv) == 4);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        bool test_result = (BitVecLen(&bv) == 4);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        test_result      = test_result && (BitVecGet(&bv, 3) == true);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        test_result      = test_result && (BitVecGet(&bv, 3) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        test_result      = test_result && (BitVecGet(&bv, 3) == true);
    
        // Clean up
        BitVecShiftLeft(&bv, 0);
        result = result && (BitVecLen(&bv) == 2);
        result = result && (BitVecGet(&bv, 0) == true);
    
        // Test shift larger than length (should clear all bits)
        BitVecPush(&bv, true);
        BitVecRotateRight(&bv, 0);
        result = result && (BitVecGet(&bv, 0) == true);
    
        // Test rotate by length (should be no-op)
        BitVecPush(&bv1, true);
        BitVecNot(&result_bv, &bv1);
        result = result && (BitVecGet(&result_bv, 0) == false);
    
        BitVecDeinit(&result_bv);
        BitVecReverse(&bv);
        result = result && (BitVecLen(&bv) == 1);
        result = result && (BitVecGet(&bv, 0) == true);
    
        // Test reverse even length
        BitVecPush(&bv, false);
        BitVecReverse(&bv);
        result = result && (BitVecGet(&bv, 0) == false);
        result = result && (BitVecGet(&bv, 1) == true);
        BitVecReverse(&bv);
        result = result && (BitVecGet(&bv, 0) == false);
        result = result && (BitVecGet(&bv, 1) == true);
    
        // Test double reverse (should restore original)
        // Test double reverse (should restore original)
        BitVecReverse(&bv);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        BitVecReverse(&bv);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
    
        BitVecDeinit(&bv);
        BitVecAnd(&result, &bv1, &bv2);
        test_result = test_result && (BitVecLen(&result) == 1);
        test_result = test_result && (BitVecGet(&result, 0) == false);
    
        BitVecOr(&result, &bv1, &bv2);
    
        BitVecOr(&result, &bv1, &bv2);
        test_result = test_result && (BitVecGet(&result, 0) == true);
    
        // Test NOT on large bitvector
        // Verify NOT correctness
        for (int i = 0; i < 100; i++) {
            bool original = BitVecGet(&bv1, i);
            bool inverted = BitVecGet(&result, i);
            test_result   = test_result && (original != inverted);
        for (int i = 0; i < 100; i++) {
            bool original = BitVecGet(&bv1, i);
            bool inverted = BitVecGet(&result, i);
            test_result   = test_result && (original != inverted);
        }
        bool changed = false;
        for (int i = 0; i < (int)BitVecLen(&original); i++) {
            if (BitVecGet(&bv, i) != BitVecGet(&original, i)) {
                changed = true;
                break;
        BitVecShiftLeft(&bv, 2);
        result = result && (BitVecLen(&bv) == 3);
        result = result && (BitVecGet(&bv, 0) == false); // filled with 0
        result = result && (BitVecGet(&bv, 1) == false); // filled with 0
        result = result && (BitVecGet(&bv, 2) == true);  // original bit 0
        result = result && (BitVecLen(&bv) == 3);
        result = result && (BitVecGet(&bv, 0) == false); // filled with 0
        result = result && (BitVecGet(&bv, 1) == false); // filled with 0
        result = result && (BitVecGet(&bv, 2) == true);  // original bit 0
        result = result && (BitVecGet(&bv, 0) == false); // filled with 0
        result = result && (BitVecGet(&bv, 1) == false); // filled with 0
        result = result && (BitVecGet(&bv, 2) == true);  // original bit 0
    
        BitVecDeinit(&bv);
        bool restored = true;
        for (int i = 0; i < 8; i++) {
            if (BitVecGet(&bv, i) != BitVecGet(&original, i)) {
                restored = false;
                break;
        bool unchanged = true;
        for (int i = 0; i < 8; i++) {
            if (BitVecGet(&bv, i) != BitVecGet(&original, i)) {
                unchanged = false;
                break;
        BitVecRotateLeft(&bv, 2);
        // 10101 -> 10110 (rotated left by 2)
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        // 10101 -> 10110 (rotated left by 2)
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        result = result && (BitVecGet(&bv, 3) == true);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        result = result && (BitVecGet(&bv, 3) == true);
        result = result && (BitVecGet(&bv, 4) == false);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        result = result && (BitVecGet(&bv, 3) == true);
        result = result && (BitVecGet(&bv, 4) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        result = result && (BitVecGet(&bv, 3) == true);
        result = result && (BitVecGet(&bv, 4) == false);
    
        BitVecDeinit(&bv);
        bool and_identity = true;
        for (int i = 0; i < 16; i++) {
            if (BitVecGet(&result, i) != BitVecGet(&bv1, i)) {
                and_identity = false;
                break;
        bool or_identity = true;
        for (int i = 0; i < 16; i++) {
            if (BitVecGet(&result, i) != BitVecGet(&bv1, i)) {
                or_identity = false;
                break;
        test_result = test_result && (BitVecLen(&result) == 16);
        for (int i = 0; i < 16; i++) {
            test_result = test_result && (BitVecGet(&result, i) == false);
        }
        bool double_not = true;
        for (int i = 0; i < 16; i++) {
            if (BitVecGet(&result, i) != BitVecGet(&bv1, i)) {
                double_not = false;
                break;
        bool and_zero = true;
        for (int i = 0; i < 16; i++) {
            if (BitVecGet(&result, i) != false) {
                and_zero = false;
                break;
        bool or_ones = true;
        for (int i = 0; i < 16; i++) {
            if (BitVecGet(&result, i) != true) {
                or_ones = false;
                break;
        bool and_commutative = true;
        for (int i = 0; i < 12; i++) {
            if (BitVecGet(&result1, i) != BitVecGet(&result2, i)) {
                and_commutative = false;
                break;
        bool or_commutative = true;
        for (int i = 0; i < 12; i++) {
            if (BitVecGet(&result1, i) != BitVecGet(&result2, i)) {
                or_commutative = false;
                break;
        bool xor_commutative = true;
        for (int i = 0; i < 12; i++) {
            if (BitVecGet(&result1, i) != BitVecGet(&result2, i)) {
                xor_commutative = false;
                break;
        for (int i = 0; i < 1000; i += 77) { // Check every 77th bit
            bool expected = (i % 7 == 0) && (i % 11 == 0);
            bool actual   = BitVecGet(&result, i);
            test_result   = test_result && (expected == actual);
        }
        // Verify NOT correctness on sample
        for (int i = 0; i < 1000; i += 123) {
            bool original = BitVecGet(&bv1, i);
            bool inverted = BitVecGet(&result, i);
            test_result   = test_result && (original != inverted);
        for (int i = 0; i < 1000; i += 123) {
            bool original = BitVecGet(&bv1, i);
            bool inverted = BitVecGet(&result, i);
            test_result   = test_result && (original != inverted);
        }
        // First 100 bits should be 0
        for (int i = 0; i < 100; i++) {
            test_result = test_result && (BitVecGet(&result, i) == false);
        }
            IntAllocator(&clone)->effort == IntAllocator(&original)->effort &&
            IntAllocator(&clone)->retry_limit == IntAllocator(&original)->retry_limit &&
            BitVecGet(&clone.bits, 0) == true && BitVecGet(&clone.bits, 1) == false && BitVecGet(&clone.bits, 2) == true;
    
        IntDeinit(&original);
    
        // Check each bit
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        // Check each bit
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        result = result && (BitVecGet(&bv, 3) == true);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        result = result && (BitVecGet(&bv, 3) == true);
        result = result && (BitVecGet(&bv, 4) == false);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        result = result && (BitVecGet(&bv, 3) == true);
        result = result && (BitVecGet(&bv, 4) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        result = result && (BitVecGet(&bv, 3) == true);
        result = result && (BitVecGet(&bv, 4) == false);
    
        // Clean up
    
        // Check first bit
        bool result = (BitVecLen(&bv) == 1 && BitVecGet(&bv, 0) == true);
    
        // Insert at the end
        // Check bits
        result = result && (BitVecLen(&bv) == 2);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecLen(&bv) == 2);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
    
        // Insert in the middle
        // Check all bits
        result = result && (BitVecLen(&bv) == 3);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == true);
        result = result && (BitVecGet(&bv, 2) == false);
        result = result && (BitVecLen(&bv) == 3);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == true);
        result = result && (BitVecGet(&bv, 2) == false);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == true);
        result = result && (BitVecGet(&bv, 2) == false);
    
        // Clean up
        // Check result: false, true, true, true, false
        bool result = (BitVecLen(&bv) == 5);
        result      = result && (BitVecGet(&bv, 0) == false);
        result      = result && (BitVecGet(&bv, 1) == true);
        result      = result && (BitVecGet(&bv, 2) == true);
        bool result = (BitVecLen(&bv) == 5);
        result      = result && (BitVecGet(&bv, 0) == false);
        result      = result && (BitVecGet(&bv, 1) == true);
        result      = result && (BitVecGet(&bv, 2) == true);
        result      = result && (BitVecGet(&bv, 3) == true);
        result      = result && (BitVecGet(&bv, 0) == false);
        result      = result && (BitVecGet(&bv, 1) == true);
        result      = result && (BitVecGet(&bv, 2) == true);
        result      = result && (BitVecGet(&bv, 3) == true);
        result      = result && (BitVecGet(&bv, 4) == false);
        result      = result && (BitVecGet(&bv, 1) == true);
        result      = result && (BitVecGet(&bv, 2) == true);
        result      = result && (BitVecGet(&bv, 3) == true);
        result      = result && (BitVecGet(&bv, 4) == false);
        result      = result && (BitVecGet(&bv, 2) == true);
        result      = result && (BitVecGet(&bv, 3) == true);
        result      = result && (BitVecGet(&bv, 4) == false);
    
        // Clean up
        // Check result: true, true, true, true, false
        bool result = (BitVecLen(&bv) == 5);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == true);
        result      = result && (BitVecGet(&bv, 2) == true);
        bool result = (BitVecLen(&bv) == 5);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == true);
        result      = result && (BitVecGet(&bv, 2) == true);
        result      = result && (BitVecGet(&bv, 3) == true);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == true);
        result      = result && (BitVecGet(&bv, 2) == true);
        result      = result && (BitVecGet(&bv, 3) == true);
        result      = result && (BitVecGet(&bv, 4) == false);
        result      = result && (BitVecGet(&bv, 1) == true);
        result      = result && (BitVecGet(&bv, 2) == true);
        result      = result && (BitVecGet(&bv, 3) == true);
        result      = result && (BitVecGet(&bv, 4) == false);
        result      = result && (BitVecGet(&bv, 2) == true);
        result      = result && (BitVecGet(&bv, 3) == true);
        result      = result && (BitVecGet(&bv, 4) == false);
    
        // Clean up
        // Pattern 1011 gets inserted as individual bits
        bool result = (BitVecLen(&bv) == 6);
        result      = result && (BitVecGet(&bv, 0) == false); // original
        result      = result && (BitVecGet(&bv, 1) == true);  // bit 0 of pattern (LSB)
        result      = result && (BitVecGet(&bv, 2) == true);  // bit 1 of pattern
        bool result = (BitVecLen(&bv) == 6);
        result      = result && (BitVecGet(&bv, 0) == false); // original
        result      = result && (BitVecGet(&bv, 1) == true);  // bit 0 of pattern (LSB)
        result      = result && (BitVecGet(&bv, 2) == true);  // bit 1 of pattern
        result      = result && (BitVecGet(&bv, 3) == false); // bit 2 of pattern
        result      = result && (BitVecGet(&bv, 0) == false); // original
        result      = result && (BitVecGet(&bv, 1) == true);  // bit 0 of pattern (LSB)
        result      = result && (BitVecGet(&bv, 2) == true);  // bit 1 of pattern
        result      = result && (BitVecGet(&bv, 3) == false); // bit 2 of pattern
        result      = result && (BitVecGet(&bv, 4) == true);  // bit 3 of pattern (MSB)
        result      = result && (BitVecGet(&bv, 1) == true);  // bit 0 of pattern (LSB)
        result      = result && (BitVecGet(&bv, 2) == true);  // bit 1 of pattern
        result      = result && (BitVecGet(&bv, 3) == false); // bit 2 of pattern
        result      = result && (BitVecGet(&bv, 4) == true);  // bit 3 of pattern (MSB)
        result      = result && (BitVecGet(&bv, 5) == false); // original
        result      = result && (BitVecGet(&bv, 2) == true);  // bit 1 of pattern
        result      = result && (BitVecGet(&bv, 3) == false); // bit 2 of pattern
        result      = result && (BitVecGet(&bv, 4) == true);  // bit 3 of pattern (MSB)
        result      = result && (BitVecGet(&bv, 5) == false); // original
        result      = result && (BitVecGet(&bv, 3) == false); // bit 2 of pattern
        result      = result && (BitVecGet(&bv, 4) == true);  // bit 3 of pattern (MSB)
        result      = result && (BitVecGet(&bv, 5) == false); // original
    
        // Test with different pattern - 0x05 (0101 in binary) using only 3 bits
        // Check result: true, false, true, true (3 bits: 101)
        result = result && (BitVecLen(&bv2) == 4);
        result = result && (BitVecGet(&bv2, 0) == true);  // bit 0 of pattern (LSB)
        result = result && (BitVecGet(&bv2, 1) == false); // bit 1 of pattern
        result = result && (BitVecGet(&bv2, 2) == true);  // bit 2 of pattern
        result = result && (BitVecLen(&bv2) == 4);
        result = result && (BitVecGet(&bv2, 0) == true);  // bit 0 of pattern (LSB)
        result = result && (BitVecGet(&bv2, 1) == false); // bit 1 of pattern
        result = result && (BitVecGet(&bv2, 2) == true);  // bit 2 of pattern
        result = result && (BitVecGet(&bv2, 3) == true);  // original
        result = result && (BitVecGet(&bv2, 0) == true);  // bit 0 of pattern (LSB)
        result = result && (BitVecGet(&bv2, 1) == false); // bit 1 of pattern
        result = result && (BitVecGet(&bv2, 2) == true);  // bit 2 of pattern
        result = result && (BitVecGet(&bv2, 3) == true);  // original
        result = result && (BitVecGet(&bv2, 1) == false); // bit 1 of pattern
        result = result && (BitVecGet(&bv2, 2) == true);  // bit 2 of pattern
        result = result && (BitVecGet(&bv2, 3) == true);  // original
    
        // Clean up
        BitVecInsertRange(&bv, 1, 2, false);
        result = result && (BitVecLen(&bv) == 3);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == false);
        result = result && (BitVecLen(&bv) == 3);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == false);
    
        // Test large range insertion
        BitVecInsertRange(&bv, 0, 1000, true);
        result = result && (BitVecLen(&bv) == 1000);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 999) == true);
        result = result && (BitVecLen(&bv) == 1000);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 999) == true);
    
        BitVecDeinit(&bv);
        BitVecPush(&source, true);
        BitVecInsertMultiple(&bv, 0, &source);
        result = result && (BitVecLen(&bv) == 1) && (BitVecGet(&bv, 0) == true);
    
        // Test inserting large bitvec
        BitVecInsertMultiple(&bv, 1, &source);
        result = result && (BitVecLen(&bv) == 501);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 500) == false);
        result = result && (BitVecLen(&bv) == 501);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 500) == false);
    
        BitVecDeinit(&bv);
        BitVecInsertPattern(&bv, 0, 0xAA, 8);            // 10101010 pattern
        result = result && (BitVecLen(&bv) == 8);
        result = result && (BitVecGet(&bv, 0) == false); // First bit of 0xAA
        result = result && (BitVecGet(&bv, 1) == true);  // Second bit
        result = result && (BitVecLen(&bv) == 8);
        result = result && (BitVecGet(&bv, 0) == false); // First bit of 0xAA
        result = result && (BitVecGet(&bv, 1) == true);  // Second bit
    
        BitVecDeinit(&bv);
        // Check result should be: 101110
        result = result && (BitVecLen(&source) == 6);
        result = result && (BitVecGet(&source, 0) == true);
        result = result && (BitVecGet(&source, 1) == false);
        result = result && (BitVecGet(&source, 2) == true);
        result = result && (BitVecLen(&source) == 6);
        result = result && (BitVecGet(&source, 0) == true);
        result = result && (BitVecGet(&source, 1) == false);
        result = result && (BitVecGet(&source, 2) == true);
        result = result && (BitVecGet(&source, 0) == true);
        result = result && (BitVecGet(&source, 1) == false);
        result = result && (BitVecGet(&source, 2) == true);
    
        BitVecDeinit(&source);
    
        // Test NULL bitvec pointer - should abort
        BitVecGet(NULL, 0);
    
        return false;
    
        // Test get from empty bitvec - should abort
        BitVecGet(&bv, 0);
    
        BitVecDeinit(&bv);
    
        // Test with index way beyond length (3) - should abort
        BitVecGet(&bv, 1000);
    
        BitVecDeinit(&bv);
    
        // Test with maximum possible index value - should abort
        BitVecGet(&bv, SIZE_MAX);
    
        BitVecDeinit(&bv);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecGet\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test getting bits
        bool result = (BitVecGet(&bv, 0) == true) && (BitVecGet(&bv, 1) == false) && (BitVecGet(&bv, 2) == true) &&
                      (BitVecGet(&bv, 3) == false);
        // Test getting bits
        bool result = (BitVecGet(&bv, 0) == true) && (BitVecGet(&bv, 1) == false) && (BitVecGet(&bv, 2) == true) &&
                      (BitVecGet(&bv, 3) == false);
    
        BitVecDeinit(&bv);
    
        // Test getting the set bits
        bool result = (BitVecGet(&bv, 0) == true) && (BitVecGet(&bv, 1) == false) && (BitVecGet(&bv, 2) == true) &&
                      (BitVecGet(&bv, 3) == false);
        // Test getting the set bits
        bool result = (BitVecGet(&bv, 0) == true) && (BitVecGet(&bv, 1) == false) && (BitVecGet(&bv, 2) == true) &&
                      (BitVecGet(&bv, 3) == false);
    
        BitVecDeinit(&bv);
    
        // Test the flipped bits
        bool result = (BitVecGet(&bv, 0) == false) && // was true, now false
                      (BitVecGet(&bv, 1) == true) &&  // was false, now true
                      (BitVecGet(&bv, 2) == true) &&  // unchanged
        // Test the flipped bits
        bool result = (BitVecGet(&bv, 0) == false) && // was true, now false
                      (BitVecGet(&bv, 1) == true) &&  // was false, now true
                      (BitVecGet(&bv, 2) == true) &&  // unchanged
                      (BitVecGet(&bv, 3) == false);   // unchanged
        bool result = (BitVecGet(&bv, 0) == false) && // was true, now false
                      (BitVecGet(&bv, 1) == true) &&  // was false, now true
                      (BitVecGet(&bv, 2) == true) &&  // unchanged
                      (BitVecGet(&bv, 3) == false);   // unchanged
                      (BitVecGet(&bv, 1) == true) &&  // was false, now true
                      (BitVecGet(&bv, 2) == true) &&  // unchanged
                      (BitVecGet(&bv, 3) == false);   // unchanged
    
        BitVecDeinit(&bv);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecGet edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        // Test with single bit
        BitVecPush(&bv, true);
        result = result && (BitVecGet(&bv, 0) == true);
    
        // Test with larger index
        }
    
        result = result && (BitVecGet(&bv, 63) == false); // 63 % 2 == 1, so i%2==0 is false for i=63
    
        BitVecDeinit(&bv);
        BitVecResize(&bv, 1);
        BitVecSet(&bv, 0, true);
        bool result = (BitVecGet(&bv, 0) == true);
    
        // Set same bit to false
        // Set same bit to false
        BitVecSet(&bv, 0, false);
        result = result && (BitVecGet(&bv, 0) == false);
    
        BitVecDeinit(&bv);
        BitVecPush(&bv, false);
        BitVecFlip(&bv, 0);
        bool result = (BitVecGet(&bv, 0) == true);
    
        // Flip it again
        // Flip it again
        BitVecFlip(&bv, 0);
        result = result && (BitVecGet(&bv, 0) == false);
    
        BitVecDeinit(&bv);
    
        // Verify pattern: T F T F T
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        // Verify pattern: T F T F T
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        result = result && (BitVecGet(&bv, 3) == false);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        result = result && (BitVecGet(&bv, 3) == false);
        result = result && (BitVecGet(&bv, 4) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        result = result && (BitVecGet(&bv, 3) == false);
        result = result && (BitVecGet(&bv, 4) == true);
        result = result && (BitVecGet(&bv, 2) == true);
        result = result && (BitVecGet(&bv, 3) == false);
        result = result && (BitVecGet(&bv, 4) == true);
    
        // Count and verify
    
        // Verify some positions
        result = result && (BitVecGet(&bv, 0) == true);    // 0 % 2 == 0
        result = result && (BitVecGet(&bv, 1) == false);   // 1 % 2 != 0
        result = result && (BitVecGet(&bv, 500) == true);  // 500 % 2 == 0
        // Verify some positions
        result = result && (BitVecGet(&bv, 0) == true);    // 0 % 2 == 0
        result = result && (BitVecGet(&bv, 1) == false);   // 1 % 2 != 0
        result = result && (BitVecGet(&bv, 500) == true);  // 500 % 2 == 0
        result = result && (BitVecGet(&bv, 999) == false); // 999 % 2 != 0
        result = result && (BitVecGet(&bv, 0) == true);    // 0 % 2 == 0
        result = result && (BitVecGet(&bv, 1) == false);   // 1 % 2 != 0
        result = result && (BitVecGet(&bv, 500) == true);  // 500 % 2 == 0
        result = result && (BitVecGet(&bv, 999) == false); // 999 % 2 != 0
        result = result && (BitVecGet(&bv, 1) == false);   // 1 % 2 != 0
        result = result && (BitVecGet(&bv, 500) == true);  // 500 % 2 == 0
        result = result && (BitVecGet(&bv, 999) == false); // 999 % 2 != 0
    
        // Verify counts
        BitVecSet(&bv, 1, true);
    
        result = result && (BitVecGet(&bv, 0) == false);
        result = result && (BitVecGet(&bv, 1) == true);
    
        result = result && (BitVecGet(&bv, 0) == false);
        result = result && (BitVecGet(&bv, 1) == true);
    
        // Test count operations
        // Verify pattern
        for (int i = 0; i < size && result; i++) {
            result = result && (BitVecGet(&bv, i) == (i % 3 == 0));
        }
                expected = !expected; // Flipped
            }
            result = result && (BitVecGet(&bv, i) == expected);
        }
        for (int i = 0; i < 100 && result; i++) {
            bool expected = (i * 17 + 3) % 7 < 3;
            result        = result && (BitVecGet(&bv, i) == expected);
        }
        BitVecPush(&bv, true);
        result = result && (BitVecLen(&bv) == 1);
        result = result && (BitVecGet(&bv, 0) == true);
    
        // Clean up
        // Check that length was increased and new bits have the default value
        bool result = (BitVecLen(&bv) == 6);
        result      = result && (BitVecGet(&bv, 0) == true);  // Original data
        result      = result && (BitVecGet(&bv, 1) == false); // Original data
        result      = result && (BitVecGet(&bv, 2) == true);  // Original data
        bool result = (BitVecLen(&bv) == 6);
        result      = result && (BitVecGet(&bv, 0) == true);  // Original data
        result      = result && (BitVecGet(&bv, 1) == false); // Original data
        result      = result && (BitVecGet(&bv, 2) == true);  // Original data
        result      = result && (BitVecGet(&bv, 3) == false); // New data (likely default to false)
        result      = result && (BitVecGet(&bv, 0) == true);  // Original data
        result      = result && (BitVecGet(&bv, 1) == false); // Original data
        result      = result && (BitVecGet(&bv, 2) == true);  // Original data
        result      = result && (BitVecGet(&bv, 3) == false); // New data (likely default to false)
        result      = result && (BitVecGet(&bv, 4) == false); // New data (likely default to false)
        result      = result && (BitVecGet(&bv, 1) == false); // Original data
        result      = result && (BitVecGet(&bv, 2) == true);  // Original data
        result      = result && (BitVecGet(&bv, 3) == false); // New data (likely default to false)
        result      = result && (BitVecGet(&bv, 4) == false); // New data (likely default to false)
        result      = result && (BitVecGet(&bv, 5) == false); // New data (likely default to false)
        result      = result && (BitVecGet(&bv, 2) == true);  // Original data
        result      = result && (BitVecGet(&bv, 3) == false); // New data (likely default to false)
        result      = result && (BitVecGet(&bv, 4) == false); // New data (likely default to false)
        result      = result && (BitVecGet(&bv, 5) == false); // New data (likely default to false)
        result      = result && (BitVecGet(&bv, 3) == false); // New data (likely default to false)
        result      = result && (BitVecGet(&bv, 4) == false); // New data (likely default to false)
        result      = result && (BitVecGet(&bv, 5) == false); // New data (likely default to false)
    
        // Test resizing to smaller size
        // Check that length was decreased and data was truncated
        result = result && (BitVecLen(&bv) == 2);
        result = result && (BitVecGet(&bv, 0) == true);  // Original data preserved
        result = result && (BitVecGet(&bv, 1) == false); // Original data preserved
        result = result && (BitVecLen(&bv) == 2);
        result = result && (BitVecGet(&bv, 0) == true);  // Original data preserved
        result = result && (BitVecGet(&bv, 1) == false); // Original data preserved
    
        // Test resizing to same size (should be no-op)
        // New bits should be false
        for (u64 i = 0; i < 5; i++) {
            result = result && (BitVecGet(&bv, i) == false);
        }
        // Check result
        bool result = (popped == true) && (BitVecLen(&bv) == 2);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        bool result = (popped == true) && (BitVecLen(&bv) == 2);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
    
        // Pop another bit
        popped = BitVecPop(&bv);
        result = result && (popped == false) && (BitVecLen(&bv) == 1);
        result = result && (BitVecGet(&bv, 0) == true);
    
        // Pop the last bit
        // Check result: true, false, false, true
        bool result = (removed == true) && (BitVecLen(&bv) == 4);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == false);
        bool result = (removed == true) && (BitVecLen(&bv) == 4);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == false);
        result      = result && (BitVecGet(&bv, 3) == true);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == false);
        result      = result && (BitVecGet(&bv, 3) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == false);
        result      = result && (BitVecGet(&bv, 3) == true);
    
        // Remove bit at index 0 (first bit)
        removed = BitVecRemove(&bv, 0);
        result  = result && (removed == true) && (BitVecLen(&bv) == 3);
        result  = result && (BitVecGet(&bv, 0) == false);
        result  = result && (BitVecGet(&bv, 1) == false);
        result  = result && (BitVecGet(&bv, 2) == true);
        result  = result && (removed == true) && (BitVecLen(&bv) == 3);
        result  = result && (BitVecGet(&bv, 0) == false);
        result  = result && (BitVecGet(&bv, 1) == false);
        result  = result && (BitVecGet(&bv, 2) == true);
        result  = result && (BitVecGet(&bv, 0) == false);
        result  = result && (BitVecGet(&bv, 1) == false);
        result  = result && (BitVecGet(&bv, 2) == true);
    
        // Clean up
        // Check result: true, false, true (removed false, true, true)
        bool result = (BitVecLen(&bv) == 3);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == true);
        bool result = (BitVecLen(&bv) == 3);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == true);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == true);
    
        // Clean up
        // Check result: true, true, false, true (removed first false at index 1)
        bool result = (found == true) && (BitVecLen(&bv) == 4);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == true);
        result      = result && (BitVecGet(&bv, 2) == false);
        bool result = (found == true) && (BitVecLen(&bv) == 4);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == true);
        result      = result && (BitVecGet(&bv, 2) == false);
        result      = result && (BitVecGet(&bv, 3) == true);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == true);
        result      = result && (BitVecGet(&bv, 2) == false);
        result      = result && (BitVecGet(&bv, 3) == true);
        result      = result && (BitVecGet(&bv, 1) == true);
        result      = result && (BitVecGet(&bv, 2) == false);
        result      = result && (BitVecGet(&bv, 3) == true);
    
        // Try to remove first occurrence of a value that doesn't exist (after removal)
        // Check result: true, false, true, true (removed last false at index 3)
        bool result = (found == true) && (BitVecLen(&bv) == 4);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == true);
        bool result = (found == true) && (BitVecLen(&bv) == 4);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == true);
        result      = result && (BitVecGet(&bv, 3) == true);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == true);
        result      = result && (BitVecGet(&bv, 3) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == true);
        result      = result && (BitVecGet(&bv, 3) == true);
    
        // Remove last occurrence of true
        // Check result: true, false, true (removed last true at index 3)
        result = result && (found == true) && (BitVecLen(&bv) == 3);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        result = result && (found == true) && (BitVecLen(&bv) == 3);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
    
        // Clean up
        // Check result: true, true, true (all false bits removed)
        bool result = (removed_count == 3) && (BitVecLen(&bv) == 3);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == true);
        result      = result && (BitVecGet(&bv, 2) == true);
        bool result = (removed_count == 3) && (BitVecLen(&bv) == 3);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == true);
        result      = result && (BitVecGet(&bv, 2) == true);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == true);
        result      = result && (BitVecGet(&bv, 2) == true);
    
        // Try to remove all false bits again (should return 0)
        // Expected result: 1000 (1101 AND 1010)
        bool test_result = (BitVecLen(&result) == 4);
        test_result      = test_result && (BitVecGet(&result, 0) == true);
        test_result      = test_result && (BitVecGet(&result, 1) == false);
        test_result      = test_result && (BitVecGet(&result, 2) == false);
        bool test_result = (BitVecLen(&result) == 4);
        test_result      = test_result && (BitVecGet(&result, 0) == true);
        test_result      = test_result && (BitVecGet(&result, 1) == false);
        test_result      = test_result && (BitVecGet(&result, 2) == false);
        test_result      = test_result && (BitVecGet(&result, 3) == false);
        test_result      = test_result && (BitVecGet(&result, 0) == true);
        test_result      = test_result && (BitVecGet(&result, 1) == false);
        test_result      = test_result && (BitVecGet(&result, 2) == false);
        test_result      = test_result && (BitVecGet(&result, 3) == false);
        test_result      = test_result && (BitVecGet(&result, 1) == false);
        test_result      = test_result && (BitVecGet(&result, 2) == false);
        test_result      = test_result && (BitVecGet(&result, 3) == false);
    
        // Clean up
        // Expected result: 1110 (1100 OR 1010)
        bool test_result = (BitVecLen(&result) == 4);
        test_result      = test_result && (BitVecGet(&result, 0) == true);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == true);
        bool test_result = (BitVecLen(&result) == 4);
        test_result      = test_result && (BitVecGet(&result, 0) == true);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == true);
        test_result      = test_result && (BitVecGet(&result, 3) == false);
        test_result      = test_result && (BitVecGet(&result, 0) == true);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == true);
        test_result      = test_result && (BitVecGet(&result, 3) == false);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == true);
        test_result      = test_result && (BitVecGet(&result, 3) == false);
    
        // Clean up
        // Expected result: 0110 (1100 XOR 1010)
        bool test_result = (BitVecLen(&result) == 4);
        test_result      = test_result && (BitVecGet(&result, 0) == false);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == true);
        bool test_result = (BitVecLen(&result) == 4);
        test_result      = test_result && (BitVecGet(&result, 0) == false);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == true);
        test_result      = test_result && (BitVecGet(&result, 3) == false);
        test_result      = test_result && (BitVecGet(&result, 0) == false);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == true);
        test_result      = test_result && (BitVecGet(&result, 3) == false);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == true);
        test_result      = test_result && (BitVecGet(&result, 3) == false);
    
        // Clean up
        // Expected result: 0101 (NOT 1010)
        bool test_result = (BitVecLen(&result) == 4);
        test_result      = test_result && (BitVecGet(&result, 0) == false);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == false);
        bool test_result = (BitVecLen(&result) == 4);
        test_result      = test_result && (BitVecGet(&result, 0) == false);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == false);
        test_result      = test_result && (BitVecGet(&result, 3) == true);
        test_result      = test_result && (BitVecGet(&result, 0) == false);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == false);
        test_result      = test_result && (BitVecGet(&result, 3) == true);
        test_result      = test_result && (BitVecGet(&result, 1) == true);
        test_result      = test_result && (BitVecGet(&result, 2) == false);
        test_result      = test_result && (BitVecGet(&result, 3) == true);
    
        // Clean up
        // New bit[1] = 0 (filled)
        // Expected result: 0010
        test_result = test_result && (BitVecGet(&bv, 0) == false);
        test_result = test_result && (BitVecGet(&bv, 1) == false);
        test_result = test_result && (BitVecGet(&bv, 2) == true);
        // Expected result: 0010
        test_result = test_result && (BitVecGet(&bv, 0) == false);
        test_result = test_result && (BitVecGet(&bv, 1) == false);
        test_result = test_result && (BitVecGet(&bv, 2) == true);
        test_result = test_result && (BitVecGet(&bv, 3) == false);
        test_result = test_result && (BitVecGet(&bv, 0) == false);
        test_result = test_result && (BitVecGet(&bv, 1) == false);
        test_result = test_result && (BitVecGet(&bv, 2) == true);
        test_result = test_result && (BitVecGet(&bv, 3) == false);
        test_result = test_result && (BitVecGet(&bv, 1) == false);
        test_result = test_result && (BitVecGet(&bv, 2) == true);
        test_result = test_result && (BitVecGet(&bv, 3) == false);
    
        // Clean up
    
        bool test_result = (BitVecLen(&bv) == 4);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        bool test_result = (BitVecLen(&bv) == 4);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        test_result      = test_result && (BitVecGet(&bv, 3) == false);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        test_result      = test_result && (BitVecGet(&bv, 3) == false);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        test_result      = test_result && (BitVecGet(&bv, 3) == false);
    
        // Clean up
        // Expected result: 1110 (1011 rotated left by 2)
        bool test_result = (BitVecLen(&bv) == 4);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == true);
        bool test_result = (BitVecLen(&bv) == 4);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == true);
        test_result      = test_result && (BitVecGet(&bv, 3) == false);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == true);
        test_result      = test_result && (BitVecGet(&bv, 3) == false);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == true);
        test_result      = test_result && (BitVecGet(&bv, 3) == false);
    
        // Clean up
        // Expected result: 1101 (1011 rotated right by 1)
        bool test_result = (BitVecLen(&bv) == 4);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        bool test_result = (BitVecLen(&bv) == 4);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        test_result      = test_result && (BitVecGet(&bv, 3) == true);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        test_result      = test_result && (BitVecGet(&bv, 3) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        test_result      = test_result && (BitVecGet(&bv, 3) == true);
    
        // Clean up
        // Expected result: 1101 (1011 reversed)
        bool test_result = (BitVecLen(&bv) == 4);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        bool test_result = (BitVecLen(&bv) == 4);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        test_result      = test_result && (BitVecGet(&bv, 3) == true);
        test_result      = test_result && (BitVecGet(&bv, 0) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        test_result      = test_result && (BitVecGet(&bv, 3) == true);
        test_result      = test_result && (BitVecGet(&bv, 1) == true);
        test_result      = test_result && (BitVecGet(&bv, 2) == false);
        test_result      = test_result && (BitVecGet(&bv, 3) == true);
    
        // Clean up
        BitVecShiftLeft(&bv, 0);
        result = result && (BitVecLen(&bv) == 2);
        result = result && (BitVecGet(&bv, 0) == true);
    
        // Test shift larger than length (should clear all bits)
        BitVecPush(&bv, true);
        BitVecRotateRight(&bv, 0);
        result = result && (BitVecGet(&bv, 0) == true);
    
        // Test rotate by length (should be no-op)
        BitVecPush(&bv1, true);
        BitVecNot(&result_bv, &bv1);
        result = result && (BitVecGet(&result_bv, 0) == false);
    
        BitVecDeinit(&result_bv);
        BitVecReverse(&bv);
        result = result && (BitVecLen(&bv) == 1);
        result = result && (BitVecGet(&bv, 0) == true);
    
        // Test reverse even length
        BitVecPush(&bv, false);
        BitVecReverse(&bv);
        result = result && (BitVecGet(&bv, 0) == false);
        result = result && (BitVecGet(&bv, 1) == true);
        BitVecReverse(&bv);
        result = result && (BitVecGet(&bv, 0) == false);
        result = result && (BitVecGet(&bv, 1) == true);
    
        // Test double reverse (should restore original)
        // Test double reverse (should restore original)
        BitVecReverse(&bv);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        BitVecReverse(&bv);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
    
        BitVecDeinit(&bv);
        BitVecAnd(&result, &bv1, &bv2);
        test_result = test_result && (BitVecLen(&result) == 1);
        test_result = test_result && (BitVecGet(&result, 0) == false);
    
        BitVecOr(&result, &bv1, &bv2);
    
        BitVecOr(&result, &bv1, &bv2);
        test_result = test_result && (BitVecGet(&result, 0) == true);
    
        // Test NOT on large bitvector
        // Verify NOT correctness
        for (int i = 0; i < 100; i++) {
            bool original = BitVecGet(&bv1, i);
            bool inverted = BitVecGet(&result, i);
            test_result   = test_result && (original != inverted);
        for (int i = 0; i < 100; i++) {
            bool original = BitVecGet(&bv1, i);
            bool inverted = BitVecGet(&result, i);
            test_result   = test_result && (original != inverted);
        }
        bool changed = false;
        for (int i = 0; i < (int)BitVecLen(&original); i++) {
            if (BitVecGet(&bv, i) != BitVecGet(&original, i)) {
                changed = true;
                break;
        BitVecShiftLeft(&bv, 2);
        result = result && (BitVecLen(&bv) == 3);
        result = result && (BitVecGet(&bv, 0) == false); // filled with 0
        result = result && (BitVecGet(&bv, 1) == false); // filled with 0
        result = result && (BitVecGet(&bv, 2) == true);  // original bit 0
        result = result && (BitVecLen(&bv) == 3);
        result = result && (BitVecGet(&bv, 0) == false); // filled with 0
        result = result && (BitVecGet(&bv, 1) == false); // filled with 0
        result = result && (BitVecGet(&bv, 2) == true);  // original bit 0
        result = result && (BitVecGet(&bv, 0) == false); // filled with 0
        result = result && (BitVecGet(&bv, 1) == false); // filled with 0
        result = result && (BitVecGet(&bv, 2) == true);  // original bit 0
    
        BitVecDeinit(&bv);
        bool restored = true;
        for (int i = 0; i < 8; i++) {
            if (BitVecGet(&bv, i) != BitVecGet(&original, i)) {
                restored = false;
                break;
        bool unchanged = true;
        for (int i = 0; i < 8; i++) {
            if (BitVecGet(&bv, i) != BitVecGet(&original, i)) {
                unchanged = false;
                break;
        BitVecRotateLeft(&bv, 2);
        // 10101 -> 10110 (rotated left by 2)
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        // 10101 -> 10110 (rotated left by 2)
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        result = result && (BitVecGet(&bv, 3) == true);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        result = result && (BitVecGet(&bv, 3) == true);
        result = result && (BitVecGet(&bv, 4) == false);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        result = result && (BitVecGet(&bv, 3) == true);
        result = result && (BitVecGet(&bv, 4) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        result = result && (BitVecGet(&bv, 3) == true);
        result = result && (BitVecGet(&bv, 4) == false);
    
        BitVecDeinit(&bv);
        bool and_identity = true;
        for (int i = 0; i < 16; i++) {
            if (BitVecGet(&result, i) != BitVecGet(&bv1, i)) {
                and_identity = false;
                break;
        bool or_identity = true;
        for (int i = 0; i < 16; i++) {
            if (BitVecGet(&result, i) != BitVecGet(&bv1, i)) {
                or_identity = false;
                break;
        test_result = test_result && (BitVecLen(&result) == 16);
        for (int i = 0; i < 16; i++) {
            test_result = test_result && (BitVecGet(&result, i) == false);
        }
        bool double_not = true;
        for (int i = 0; i < 16; i++) {
            if (BitVecGet(&result, i) != BitVecGet(&bv1, i)) {
                double_not = false;
                break;
        bool and_zero = true;
        for (int i = 0; i < 16; i++) {
            if (BitVecGet(&result, i) != false) {
                and_zero = false;
                break;
        bool or_ones = true;
        for (int i = 0; i < 16; i++) {
            if (BitVecGet(&result, i) != true) {
                or_ones = false;
                break;
        bool and_commutative = true;
        for (int i = 0; i < 12; i++) {
            if (BitVecGet(&result1, i) != BitVecGet(&result2, i)) {
                and_commutative = false;
                break;
        bool or_commutative = true;
        for (int i = 0; i < 12; i++) {
            if (BitVecGet(&result1, i) != BitVecGet(&result2, i)) {
                or_commutative = false;
                break;
        bool xor_commutative = true;
        for (int i = 0; i < 12; i++) {
            if (BitVecGet(&result1, i) != BitVecGet(&result2, i)) {
                xor_commutative = false;
                break;
        for (int i = 0; i < 1000; i += 77) { // Check every 77th bit
            bool expected = (i % 7 == 0) && (i % 11 == 0);
            bool actual   = BitVecGet(&result, i);
            test_result   = test_result && (expected == actual);
        }
        // Verify NOT correctness on sample
        for (int i = 0; i < 1000; i += 123) {
            bool original = BitVecGet(&bv1, i);
            bool inverted = BitVecGet(&result, i);
            test_result   = test_result && (original != inverted);
        for (int i = 0; i < 1000; i += 123) {
            bool original = BitVecGet(&bv1, i);
            bool inverted = BitVecGet(&result, i);
            test_result   = test_result && (original != inverted);
        }
        // First 100 bits should be 0
        for (int i = 0; i < 100; i++) {
            test_result = test_result && (BitVecGet(&result, i) == false);
        }
        // Check result
        bool result = ok && (BitVecLen(&bv) == 4);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == true);
        bool result = ok && (BitVecLen(&bv) == 4);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == true);
        result      = result && (BitVecGet(&bv, 3) == true);
        result      = result && (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == true);
        result      = result && (BitVecGet(&bv, 3) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == true);
        result      = result && (BitVecGet(&bv, 3) == true);
    
        // Test with empty string
    
        for (u64 i = 0; i < BitVecLen(&bv); i++) {
            if (BitVecGet(&bv, i)) {
                true_count++;
            } else {
    
        for (u64 i = 0; i < BitVecLen(&bv); i++) {
            if (BitVecGet(&bv, i)) {
                true_count++;
            } else {
        bool all_false = true;
        for (u64 i = 0; i < BitVecLen(&zero_bv); i++) {
            if (BitVecGet(&zero_bv, i)) {
                all_false = false;
                break;
        BitVec bv2 = BitVecFromStr("1", ALLOCATOR_OF(&alloc));
        result     = result && (BitVecLen(&bv2) == 1);
        result     = result && (BitVecGet(&bv2, 0) == true);
        BitVecDeinit(&bv2);
        BitVec bv3 = BitVecFromStr(long_str, ALLOCATOR_OF(&alloc));
        result     = result && (BitVecLen(&bv3) == 1000);
        result     = result && (BitVecGet(&bv3, 0) == true);
        result     = result && (BitVecGet(&bv3, 1) == false);
        BitVecDeinit(&bv3);
        result     = result && (BitVecLen(&bv3) == 1000);
        result     = result && (BitVecGet(&bv3, 0) == true);
        result     = result && (BitVecGet(&bv3, 1) == false);
        BitVecDeinit(&bv3);
        for (u64 i = 0; i < BitVecLen(&recovered_bv); i++) {
            bool expected = (i % 3) == 0;
            bool actual   = BitVecGet(&recovered_bv, i);
            if (expected != actual) {
                recovered_pattern_correct = false;
        for (u64 i = 0; i < BitVecLen(&large_from_str); i++) {
            bool expected = (i % 7) == 0;
            bool actual   = BitVecGet(&large_from_str, i);
            if (expected != actual) {
                large_pattern_correct = false;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecGet\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test getting each bit
        bool result = (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == true);
        // Test getting each bit
        bool result = (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == true);
        result      = result && (BitVecGet(&bv, 3) == false);
        bool result = (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == true);
        result      = result && (BitVecGet(&bv, 3) == false);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == true);
        result      = result && (BitVecGet(&bv, 3) == false);
    
        // Clean up
    
        // Verify changes
        bool result = (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == true);
        // Verify changes
        bool result = (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == true);
        bool result = (BitVecGet(&bv, 0) == true);
        result      = result && (BitVecGet(&bv, 1) == false);
        result      = result && (BitVecGet(&bv, 2) == true);
    
        // Test setting back to false
        // Test setting back to false
        BitVecSet(&bv, 0, false);
        result = result && (BitVecGet(&bv, 0) == false);
    
        // Clean up
    
        // Verify flipped values: should now be 010
        bool result = (BitVecGet(&bv, 0) == false);
        result      = result && (BitVecGet(&bv, 1) == true);
        result      = result && (BitVecGet(&bv, 2) == false);
        // Verify flipped values: should now be 010
        bool result = (BitVecGet(&bv, 0) == false);
        result      = result && (BitVecGet(&bv, 1) == true);
        result      = result && (BitVecGet(&bv, 2) == false);
        bool result = (BitVecGet(&bv, 0) == false);
        result      = result && (BitVecGet(&bv, 1) == true);
        result      = result && (BitVecGet(&bv, 2) == false);
    
        // Flip back
    
        // Should be back to original: 101
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        // Should be back to original: 101
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
        result = result && (BitVecGet(&bv, 0) == true);
        result = result && (BitVecGet(&bv, 1) == false);
        result = result && (BitVecGet(&bv, 2) == true);
    
        // Clean up
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecGet edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        // Test boundary conditions (no longer test empty bitvec - strict bounds checking now)
        BitVecPush(&bv, true);
        result = result && (BitVecGet(&bv, 0) == true); // Valid index
    
        // Test with large data set
        }
    
        result = result && (BitVecGet(&bv, 0) == true);             // First
        result = result && (BitVecGet(&bv, 999) == (999 % 3 == 0)); // Last
    
        result = result && (BitVecGet(&bv, 0) == true);             // First
        result = result && (BitVecGet(&bv, 999) == (999 % 3 == 0)); // Last
    
        BitVecDeinit(&bv);
        BitVecPush(&bv, false);
        BitVecSet(&bv, 0, true);
        result = result && (BitVecGet(&bv, 0) == true);
    
        // Test setting same value multiple times
        BitVecSet(&bv, 0, true);
        BitVecSet(&bv, 0, true);
        result = result && (BitVecGet(&bv, 0) == true);
    
        BitVecDeinit(&bv);
        BitVecPush(&bv, true);
        BitVecFlip(&bv, 0);
        result = result && (BitVecGet(&bv, 0) == false);
    
        BitVecFlip(&bv, 0);
    
        BitVecFlip(&bv, 0);
        result = result && (BitVecGet(&bv, 0) == true);
    
        BitVecDeinit(&bv);
            // Test access during growth
            if (cycle > 0) {
                result = result && (BitVecGet(&bv, 0) == true);
                result = result && (BitVecLen(&bv) == (size)(cycle + 1));
            }
            // Test setting and getting
            BitVecSet(&bv, cycle, cycle % 3 == 0);
            result = result && (BitVecGet(&bv, cycle) == (cycle % 3 == 0));
        }
                for (int bit = 0; bit < 8; bit++) {
                    bool expected = (pattern & (1u << bit)) != 0;
                    bool actual   = BitVecGet(&bv, base_idx + bit);
                    result        = result && (actual == expected);
                }
    
        // Test random access across the large dataset
        result = result && (BitVecGet(&bv, 0) == false);                 // First bit of pattern
        result = result && (BitVecGet(&bv, 2) == true);                  // Third bit of pattern
        result = result && (BitVecGet(&bv, BitVecLen(&bv) - 1) == true); // Last bit
        // Test random access across the large dataset
        result = result && (BitVecGet(&bv, 0) == false);                 // First bit of pattern
        result = result && (BitVecGet(&bv, 2) == true);                  // Third bit of pattern
        result = result && (BitVecGet(&bv, BitVecLen(&bv) - 1) == true); // Last bit
        result = result && (BitVecGet(&bv, 0) == false);                 // First bit of pattern
        result = result && (BitVecGet(&bv, 2) == true);                  // Third bit of pattern
        result = result && (BitVecGet(&bv, BitVecLen(&bv) - 1) == true); // Last bit
    
        BitVecDeinit(&bv);
            u64  idx      = (test * 7 + test * 3) % size; // Pseudo-random indices
            bool expected = (idx / 7) % 2 == 0;
            bool actual   = BitVecGet(&bv, idx);
            result        = result && (actual == expected);
        }
        for (int i = 0; i < boundary_count; i++) {
            if (boundaries[i] < size) {
                bool original = BitVecGet(&bv, boundaries[i]);
                BitVecFlip(&bv, boundaries[i]);
                result = result && (BitVecGet(&bv, boundaries[i]) == !original);
                bool original = BitVecGet(&bv, boundaries[i]);
                BitVecFlip(&bv, boundaries[i]);
                result = result && (BitVecGet(&bv, boundaries[i]) == !original);
                BitVecFlip(&bv, boundaries[i]); // Flip back
                result = result && (BitVecGet(&bv, boundaries[i]) == original);
                result = result && (BitVecGet(&bv, boundaries[i]) == !original);
                BitVecFlip(&bv, boundaries[i]); // Flip back
                result = result && (BitVecGet(&bv, boundaries[i]) == original);
            }
        }
        // Verify all bits are false
        for (int i = 0; i < 100; i++) {
            result = result && (BitVecGet(&bv, i) == false);
        }
        for (int i = 0; i < 100; i++) {
            bool expected = (i % 2 == 0);
            result        = result && (BitVecGet(&bv, i) == expected);
        }
        BitVecPush(&bv, true); // F(1) = 1
        for (int i = 2; i < 50; i++) {
            bool prev1 = BitVecGet(&bv, i - 1);
            bool prev2 = BitVecGet(&bv, i - 2);
            BitVecPush(&bv, prev1 != prev2); // XOR
        for (int i = 2; i < 50; i++) {
            bool prev1 = BitVecGet(&bv, i - 1);
            bool prev2 = BitVecGet(&bv, i - 2);
            BitVecPush(&bv, prev1 != prev2); // XOR
        }
    
        // Verify first few Fibonacci bits
        result = result && (BitVecGet(&bv, 0) == true);  // F(0) = 1
        result = result && (BitVecGet(&bv, 1) == true);  // F(1) = 1
        result = result && (BitVecGet(&bv, 2) == false); // F(2) = 1 XOR 1 = 0
        // Verify first few Fibonacci bits
        result = result && (BitVecGet(&bv, 0) == true);  // F(0) = 1
        result = result && (BitVecGet(&bv, 1) == true);  // F(1) = 1
        result = result && (BitVecGet(&bv, 2) == false); // F(2) = 1 XOR 1 = 0
        result = result && (BitVecGet(&bv, 3) == true);  // F(3) = 1 XOR 0 = 1
        result = result && (BitVecGet(&bv, 0) == true);  // F(0) = 1
        result = result && (BitVecGet(&bv, 1) == true);  // F(1) = 1
        result = result && (BitVecGet(&bv, 2) == false); // F(2) = 1 XOR 1 = 0
        result = result && (BitVecGet(&bv, 3) == true);  // F(3) = 1 XOR 0 = 1
        result = result && (BitVecGet(&bv, 4) == true);  // F(4) = 0 XOR 1 = 1
        result = result && (BitVecGet(&bv, 1) == true);  // F(1) = 1
        result = result && (BitVecGet(&bv, 2) == false); // F(2) = 1 XOR 1 = 0
        result = result && (BitVecGet(&bv, 3) == true);  // F(3) = 1 XOR 0 = 1
        result = result && (BitVecGet(&bv, 4) == true);  // F(4) = 0 XOR 1 = 1
        result = result && (BitVecGet(&bv, 2) == false); // F(2) = 1 XOR 1 = 0
        result = result && (BitVecGet(&bv, 3) == true);  // F(3) = 1 XOR 0 = 1
        result = result && (BitVecGet(&bv, 4) == true);  // F(4) = 0 XOR 1 = 1
    
        BitVecDeinit(&bv);
    
        // Test NULL bitvec pointer - should abort
        BitVecGet(NULL, 0);
    
        return false;
    
        // Test get from empty bitvec - should abort
        BitVecGet(&bv, 0);
    
        BitVecDeinit(&bv);
    
        // Test with index way beyond length (3) - should abort
        BitVecGet(&bv, 1000);
    
        BitVecDeinit(&bv);
    
        // Test with maximum possible index value - should abort
        BitVecGet(&bv, SIZE_MAX);
    
        BitVecDeinit(&bv);
            if ((ValidateBitVec(UNPL(pbv)), 1) && UNPL(pbv)->length > 0)                                                   \
                for (u64 idx = 0, UNPL(d) = 1; UNPL(d); UNPL(d)--)                                                         \
                    for (bool var = 0; idx < UNPL(pbv)->length && (var = BitVecGet(UNPL(pbv), idx), 1); idx++)
    
    ///
                for (u64 idx = UNPL(pbv)->length; idx-- > 0 && idx < UNPL(pbv)->length;)                                   \
                    for (u8 UNPL(run_once) = 1; UNPL(run_once); UNPL(run_once) = 0)                                        \
                        for (bool var = BitVecGet(UNPL(pbv), idx); UNPL(run_once); UNPL(run_once) = 0)
    
    ///
                     UNPL(s) <= idx && idx < UNPL(e) && idx < UNPL(pbv)->length && UNPL(s) <= UNPL(e);                     \
                     ++idx, UNPL(d) = 1)                                                                                   \
                    for (bool var = BitVecGet(UNPL(pbv), idx); UNPL(d); UNPL(d) = 0)
    
Last updated on