Skip to content

BitVecInit

Description

Initialize an empty BitVec. Inside a Scope block the allocator argument may be omitted; the internal MisraScope allocator is used. Otherwise pass a typed allocator handle or a raw Allocator *.

Usage example (Cross-references)

Usage examples (Cross-references)
    
    BitVec bitvec_init_with_capacity(u64 cap, Allocator *alloc) {
        BitVec result = BitVecInit(alloc);
    
        if (cap == 0) {
        }
    
        *out = BitVecInit(bv->allocator);
        if (bv->length == 0) {
            return true;
        if (!BitVecReserve(out, bv->length) || !BitVecResize(out, bv->length)) {
            BitVecDeinit(out);
            *out = BitVecInit(bv->allocator);
            return false;
        }
    
        ValidateBitVec(bv);
        clone = BitVecInit(bv->allocator);
        (void)BitVecTryClone(&clone, bv);
        return clone;
        }
    
        *out = BitVecInit(alloc);
    
        if (!BitVecReserve(out, str_len)) {
                if (!BitVecPush(out, true)) {
                    BitVecDeinit(out);
                    *out = BitVecInit(alloc);
                    return false;
                }
                if (!BitVecPush(out, false)) {
                    BitVecDeinit(out);
                    *out = BitVecInit(alloc);
                    return false;
                }
    
        if (!bitvec_try_from_str_zstr(&result, str, alloc)) {
            result = BitVecInit(alloc);
        }
    
        if (!bitvec_try_from_str_str(&result, str, alloc)) {
            result = BitVecInit(alloc);
        }
        }
    
        *out = BitVecInit(alloc);
    
        if (bit_len == 0) {
        if (!BitVecReserve(out, bit_len) || !BitVecResize(out, bit_len)) {
            BitVecDeinit(out);
            *out = BitVecInit(alloc);
            return false;
        }
    
        if (!bitvec_try_from_bytes(&result, bytes, bit_len, alloc)) {
            result = BitVecInit(alloc);
        }
        }
    
        *out = BitVecInit(alloc);
        if (bits == 0) {
            return true;
        if (!BitVecReserve(out, bits) || !BitVecResize(out, bits)) {
            BitVecDeinit(out);
            *out = BitVecInit(alloc);
            return false;
        }
    
        if (!bitvec_try_from_integer(&result, value, bits, alloc)) {
            result = BitVecInit(alloc);
        }
        WriteFmt("Testing BitVecPop\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add some bits
        WriteFmt("Testing BitVecRemove (single bit)\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add some bits: true, false, true, false, true
        WriteFmt("Testing BitVecRemoveRange\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add some bits: true, false, true, true, false, true
        WriteFmt("Testing BitVecRemoveFirst\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add some bits: true, false, true, false, true
        WriteFmt("Testing BitVecRemoveLast\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add some bits: true, false, true, false, true
        WriteFmt("Testing BitVecRemoveAll\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add some bits: true, false, true, false, true, false
        WriteFmt("Testing BitVecPop edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecRemove edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecRemoveRange edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecRemoveFirst/Last edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecRemoveAll edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec remove invalid range handling\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test removing beyond capacity limit - should abort
        WriteFmt("Testing BitVec pop bounds checking\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test pop from empty bitvec - should abort
        WriteFmt("Testing BitVec remove bounds checking\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test remove from empty bitvec - should abort
        WriteFmt("Testing BitVec remove range bounds checking\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test remove range from empty bitvec - should abort
        WriteFmt("Testing BitVecRemoveRange clamps oversized count\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Length 10, all true.
        WriteFmt("Testing BitVecRemoveRange clamp gap count\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Length 10, all true.
        WriteFmt("Testing BitVecRemoveRange shifts tail down\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Pattern: indices 0..9 = [1,0,1,0,0,1,0,1,1,0]
        WriteFmt("Testing BitVecRemove rejects idx == length\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv, true);
        BitVecPush(&bv, false);
        WriteFmt("Testing BitVec get bounds checking\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test get from empty bitvec - should abort
        WriteFmt("Testing BitVec set bounds checking\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test set on empty bitvec - should abort
        WriteFmt("Testing BitVec flip bounds checking\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test flip on empty bitvec - should abort
        WriteFmt("Testing BitVec get with large out-of-bounds index\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv, true);
        BitVecPush(&bv, false);
        WriteFmt("Testing BitVec set with large out-of-bounds index\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv, true);
        BitVecPush(&bv, false);
        WriteFmt("Testing BitVec flip with edge case out-of-bounds index\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 10; i++) {
            BitVecPush(&bv, i % 2 == 0);
        WriteFmt("Testing BitVec get with maximum index value\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv, true);
        WriteFmt("Testing BitVecPush\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Push some bits
        WriteFmt("Testing BitVecInsert (single bit)\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Insert at index 0 (empty bitvector)
        WriteFmt("Testing BitVecInsertRange\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create target bitvector
        WriteFmt("Testing BitVecInsertMultiple\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Start with some bits
        WriteFmt("Testing BitVecInsertPattern\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Start with some bits
    
        // Test with different pattern - 0x05 (0101 in binary) using only 3 bits
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv2, true);
        WriteFmt("Testing BitVecInsertRange edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecInsertMultiple edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec empty  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec empty  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec empty  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecInsertPattern edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec insert invalid range handling\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test inserting beyond capacity limit - should abort
        WriteFmt("Testing BitVecInsertRange shifts existing tail bits\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Original: [1, 0, 1, 1]
        WriteFmt("Testing BitVecInsertMultiple shifts existing tail bits\n");
    
        BitVec bv    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec other = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec other = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // bv: [1, 0, 1]
        WriteFmt("Testing BitVecInsertMultiple NULL bv validation\n");
    
        BitVec other = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&other, true);
        WriteFmt("Testing BitVecInsertMultiple NULL other validation\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv, true);
        StrClear(&output);
    
        BitVec bv_empty = BitVecInit(alloc_base);
        StrAppendFmt(&output, "{}", bv_empty);
        success = success && (StrLen(&output) == 0);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(alloc_base);
        Zstr   z  = "0x1";
        StrReadFmt(z, "{}", bv);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(alloc_base);
        Zstr   z  = "0xDEAD";
        StrReadFmt(z, "{}", bv);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(alloc_base);
        Zstr   z  = "0xDEAD";
        StrReadFmt(z, "{}", bv);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(alloc_base);
        Zstr   z  = "0o1";
        StrReadFmt(z, "{}", bv);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(alloc_base);
        Zstr   z  = "0o10";
        StrReadFmt(z, "{}", bv);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(alloc_base);
        Zstr   z  = "0o755";
        StrReadFmt(z, "{}", bv);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(alloc_base);
        Zstr   z  = "0x3ff";
        StrReadFmt(z, "{}", bv);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(alloc_base);
        Zstr   z  = "0xff";
        StrReadFmt(z, "{}", bv);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(alloc_base);
        Zstr   z  = "0x10000";
        StrReadFmt(z, "{}", bv);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec a = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 256; i++) {
    
        BitVec a = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 256; i++) {
            BitVecPush(&a, false);
    bool test_blind_rotate_right_exact(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        BitVec           bv    = BitVecInit(ALLOCATOR_OF(&alloc));
    
        bool pat[5] = {true, false, false, true, true};
        WriteFmt("Testing BitVecGet\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Push some bits
        WriteFmt("Testing BitVecSet\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Reserve space and set bits
        WriteFmt("Testing BitVecFlip\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Push some bits
        WriteFmt("Testing BitVecLength and BitVecCapacity\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Initially empty
        WriteFmt("Testing BitVecCount operations\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Push a pattern: true, false, true, false, true
        WriteFmt("Testing BitVecGet edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecSet edge cases\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set first bit
        WriteFmt("Testing BitVecFlip edge cases\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test flipping single bit
        WriteFmt("Testing BitVecCount edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec multiple access operations\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec access with large patterns\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec macro functions\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec access stress test\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec comprehensive bit patterns\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecFind functions\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec predicate functions\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecLongestRun\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecFind edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec predicate edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecLongestRun edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecAnd\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up first bitvector: 1101
        WriteFmt("Testing BitVecOr\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up first bitvector: 1100
        WriteFmt("Testing BitVecXor\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up first bitvector: 1100
        WriteFmt("Testing BitVecNot\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up bitvector: 1010
        WriteFmt("Testing BitVecShiftLeft\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up bitvector: 1011 (indices 0,1,2,3)
        WriteFmt("Testing BitVecShiftRight\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up bitvector: 1011
        WriteFmt("Testing BitVecRotateLeft\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up bitvector: 1011
        WriteFmt("Testing BitVecRotateRight\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up bitvector: 1011
        WriteFmt("Testing BitVecReverse\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up bitvector: 1011
        WriteFmt("Testing BitVec shift edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec rotate edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec bitwise operations edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        // Test operations on empty bitvecs
        BitVec result_bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecAnd(&result_bv, &bv1, &bv2);
        result = result && (BitVecLen(&result_bv) == 0);
        WriteFmt("Testing BitVecReverse edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec comprehensive bitwise operations\n");
    
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result      = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result      = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   test_result = true;
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result      = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   test_result = true;
        WriteFmt("Testing BitVec comprehensive shift operations\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec comprehensive rotate operations\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec bitwise identity operations\n");
    
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result      = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result      = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   test_result = true;
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result      = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   test_result = true;
        WriteFmt("Testing BitVec bitwise commutative properties\n");
    
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result1     = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result1     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result2     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result1     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result2     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   test_result = true;
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result1     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result2     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   test_result = true;
        WriteFmt("Testing BitVec bitwise operations with large patterns\n");
    
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result      = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result      = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   test_result = true;
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result      = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   test_result = true;
        WriteFmt("Testing BitVecOr widens past shorter operand a\n");
    
        BitVec a      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec a      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec a      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // a = 10 (len 2)
        WriteFmt("Testing BitVecXor widens past shorter operand a\n");
    
        BitVec a      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec a      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec a      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // a = 10 (len 2)
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 8; i++) {
            BitVecPush(&bv, true);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv, true);  // bit 0
        BitVecPush(&bv, true);  // bit 1
        WriteFmt("Testing BitVecToStr\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create pattern: 1011
        WriteFmt("Testing BitVecToBytes\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create pattern: 10110011 (0xB3)
        WriteFmt("Testing BitVecToInteger\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create pattern: 1011 (decimal 11 if MSB first, 13 if LSB first)
    
        // Test with larger pattern
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 8; i++) {
            BitVecPush(&bv2, (i % 2 == 0)); // Alternating pattern
        WriteFmt("Testing BitVec convert edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec bytes conversion edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec integer conversion edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        // Test oversized bitvec to integer (should handle gracefully)
        BitVec oversized = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 100; i++) { // 100 bits > 64 bit limit
            BitVecPush(&oversized, i % 2 == 0);
    
        // Test zero-length conversions
        BitVec empty = BitVecInit(ALLOCATOR_OF(&alloc));
    
        Str empty_str = BitVecToStr(&empty);
    
        // Test with very large bitvectors
        BitVec large_bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create a 1000-bit pattern
        WriteFmt("Testing BitVec bytes zero max_len handling\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv, true);
        WriteFmt("Testing BitVecToBytes 4-bit pack does not over-read\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        // 4-bit pattern 1011 -> LSB-first packing: bits 0,2,3 set -> 0x0D.
        BitVecPush(&bv, true);  // bit 0
        WriteFmt("Testing BitVecToBytes truncation respects max_len\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        // 16 bits; ensure byte 1 has at least one set bit (bit 8 -> byte1 bit0).
        for (u64 i = 0; i < 16; i++) {
    
        // Create a bitvector
        BitVec bitvec = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Check initial state
    
        // Create a valid bitvector
        BitVec bitvec = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // This should not abort
    static bool test_read_bitvec_hex(void) {
        DebugAllocator dbg = DebugAllocatorInit();
        BitVec         bv  = BitVecInit(&dbg.base);
        Zstr           z   = "0x1";
        StrReadFmt(z, "{}", bv);
    static bool test_read_bitvec_hex_wide(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        BitVec           bv    = BitVecInit(&alloc.base);
        Zstr             z     = "0xDEAD";
        StrReadFmt(z, "{}", bv);
    static bool test_read_bitvec_octal(void) {
        DebugAllocator dbg = DebugAllocatorInit();
        BitVec         bv  = BitVecInit(&dbg.base);
        Zstr           z   = "0o1";
        StrReadFmt(z, "{}", bv);
    static bool test_read_bitvec_binary(void) {
        DebugAllocator dbg = DebugAllocatorInit();
        BitVec         bv  = BitVecInit(&dbg.base);
        Zstr           z   = "10110";
        StrReadFmt(z, "{}", bv);
        WriteFmt("Testing BitVecShrinkToFit\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add some bits
        WriteFmt("Testing BitVecReserve\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add some bits
        WriteFmt("Testing BitVecSwap\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up first bitvector
        WriteFmt("Testing BitVecClone\n");
    
        BitVec original = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up original bitvector
        alloc.base.retry_limit = 9;
    
        BitVec original = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVecPush(&original, true);
        WriteFmt("Testing BitVecShrinkToFit edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecReserve edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecSwap edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecClone edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        for (int cycle = 0; cycle < 10; cycle++) {
            BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
            BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int cycle = 0; cycle < 10; cycle++) {
            BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
            BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
            // Add random-sized data
        WriteFmt("Testing BitVec swap NULL handling\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test NULL pointer - should abort
        WriteFmt("Testing resize-grow clears stale tail bits\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Fill a full byte with ones so bits 5,6,7 are set in the backing byte.
        WriteFmt("Testing BitVecReserve with zero capacity returns true\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        bool result = (BitVecReserve(&bv, 0) == true);
        WriteFmt("Testing BitVecShrinkToFit preserves bits on a large vector\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // 400 bits => doubling growth yields capacity 512, byte_size 64,
        WriteFmt("Testing BitVecShrinkToFit keeps the vector structurally valid\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        for (int i = 0; i < 400; i++) {
        WriteFmt("Testing BitVecSwap keeps a swapped-in large vector valid\n");
    
        BitVec small = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec large = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec small = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec large = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVecPush(&small, true);
        WriteFmt("Testing BitVecSwap aborts on an invalid second argument\n");
    
        BitVec good = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&good, true);
        WriteFmt("Testing BitVecTryClone aborts on an invalid source\n");
    
        BitVec out = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad = {0}; // magic 0 => invalid bitvec
        WriteFmt("Testing BitVecForeachIdx macro\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add test pattern: true, false, true, false
        WriteFmt("Testing BitVecForeach macro\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add test pattern: true, false, true
        WriteFmt("Testing BitVecForeachReverseIdx macro\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add test pattern: true, false, true, false
        WriteFmt("Testing BitVecForeachReverse macro\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add test pattern: true, false, true
        WriteFmt("Testing BitVecForeachInRangeIdx macro\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add test pattern: true, false, true, false, true
        WriteFmt("Testing BitVecForeachInRange macro\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add test pattern: false, true, true, false, true
        WriteFmt("Testing BitVec foreach edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        int    count  = 0;
        WriteFmt("Testing BitVec foreach idx edge cases\n");
    
        BitVec bv       = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result   = true;
        u64    last_idx = SIZE_MAX;
        WriteFmt("Testing BitVec foreach reverse edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec foreach range edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        for (int sz = 0; sz < 100; sz += 10) {
            BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
            // Create bitvec of varying sz
        WriteFmt("Testing BitVecRunLengths basic functionality\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecRunLengths Vec form\n");
    
        BitVec bv = BitVecInit(base);
        BitVecPush(&bv, true);
        BitVecPush(&bv, true);
    
        // Test 1: Empty bitvector
        BitVec empty_bv = BitVecInit(ALLOCATOR_OF(&alloc));
        u64    runs[5];
        bool   values[5];
    
        // Test 2: Single bit (true)
        BitVec single_bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&single_bv, true);
        count  = BitVecRunLengths(&single_bv, runs, values, 5);
    
        // Test 3: Single bit (false)
        BitVec single_false_bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&single_false_bv, false);
        count  = BitVecRunLengths(&single_false_bv, runs, values, 5);
    
        // Test 4: All same bits (all true)
        BitVec all_true_bv = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 10; i++) {
            BitVecPush(&all_true_bv, true);
    
        // Test 5: Alternating bits (0101010)
        BitVec alternating_bv = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 7; i++) {
            BitVecPush(&alternating_bv, i % 2 == 0);
        WriteFmt("Testing BitVecRunLengths boundary conditions\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        // Test with large bitvector
        BitVec large_bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create pattern that results in many runs
        WriteFmt("Testing BitVecEquals\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv3 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv3 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv3 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test equal empty bitvectors
        WriteFmt("Testing BitVecCompare\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test equal bitvectors
        WriteFmt("Testing BitVecLexCompare\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test lexicographic comparison
        WriteFmt("Testing BitVecNumericalCompare\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create bitvectors representing different numbers
        WriteFmt("Testing BitVecWeightCompare\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // bv1: 111 (3 ones)
        WriteFmt("Testing BitVecIsSubset\n");
    
        BitVec subset   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec superset = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec subset   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec superset = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create superset: 1111
        WriteFmt("Testing BitVecSignedCompare\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test positive vs negative (MSB is sign bit)
        WriteFmt("Testing BitVecIsSuperset\n");
    
        BitVec superset = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec subset   = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec superset = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec subset   = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create superset: 1111
        WriteFmt("Testing BitVecOverlaps\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create overlapping bitvectors
        WriteFmt("Testing BitVecDisjoint and BitVecIntersects\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create disjoint bitvectors
        WriteFmt("Testing BitVecEqualsRange\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create test patterns
        WriteFmt("Testing BitVecCompareRange\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create test patterns
        WriteFmt("Testing BitVecIsLexicographicallyLess and BitVecIsNumericallyLess\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test lexicographic comparison
        WriteFmt("Testing BitVecIsSorted\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test empty bitvector (should be sorted)
        WriteFmt("Testing BitVec compare edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec set operations edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec comprehensive comparison operations\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        // Test transitivity: if A < B and B < C, then A < C
        BitVec bv3 = BitVecInit(ALLOCATOR_OF(&alloc));
        // bv3: larger than bv2
        for (int i = 0; i < 8; i++) {
    
        // Test subset/superset consistency
        BitVec subset   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec superset = BitVecInit(ALLOCATOR_OF(&alloc));
        // Test subset/superset consistency
        BitVec subset   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec superset = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create actual subset/superset relationship
        WriteFmt("Testing BitVec large-scale comparison operations\n");
    
        BitVec large1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec large2 = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec large1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec large2 = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        // Verify signed vs unsigned comparison differences
        BitVec pos = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec neg = BitVecInit(ALLOCATOR_OF(&alloc));
        // Verify signed vs unsigned comparison differences
        BitVec pos = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec neg = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Positive number (MSB = 0): 01111111
        WriteFmt("Testing BitVec compare NULL pointer handling\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test NULL pointer - should abort
        WriteFmt("Testing BitVec range operations NULL handling\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test NULL pointer in range operations - should abort
        WriteFmt("Testing BitVec range operations bounds checking\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create small bitvectors
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec a = BitVecInit(base);
        BitVec b = BitVecInit(base);
        for (int i = 0; i < 11; i++) {
    
        BitVec a = BitVecInit(base);
        BitVec b = BitVecInit(base);
        for (int i = 0; i < 11; i++) {
            BitVecPush(&a, (i % 2) == 0);
        }
    
        BitVec empty1 = BitVecInit(base);
        BitVec empty2 = BitVecInit(base);
    
        BitVec empty1 = BitVecInit(base);
        BitVec empty2 = BitVecInit(base);
    
        bool result = (bitvec_hash(&a, 0) == bitvec_hash(&b, 0));
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec a = BitVecInit(base);
        BitVec b = BitVecInit(base);
        BitVec c = BitVecInit(base);
    
        BitVec a = BitVecInit(base);
        BitVec b = BitVecInit(base);
        BitVec c = BitVecInit(base);
        BitVec a = BitVecInit(base);
        BitVec b = BitVecInit(base);
        BitVec c = BitVecInit(base);
    
        BitVecPush(&a, true);
        Map(BitVec, u64) counts = MapInit(bitvec_hash, bitvec_compare, &alloc);
    
        BitVec k1 = BitVecInit(base);
        BitVecPush(&k1, true);
        BitVecPush(&k1, false);
        BitVecPush(&k1, true);
    
        BitVec k2 = BitVecInit(base);
        BitVecPush(&k2, false);
        BitVecPush(&k2, true);
        MapInsertR(&counts, k2, 2u);
    
        BitVec probe = BitVecInit(base);
        BitVecPush(&probe, true);
        BitVecPush(&probe, false);
        u64 *got = MapGetFirstPtr(&counts, probe);
    
        BitVec missing = BitVecInit(base);
        BitVecPush(&missing, true);
        BitVecPush(&missing, true);
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec a = BitVecInit(base);
        BitVecPush(&a, false);
        BitVecPush(&a, true);
        BitVecPush(&a, true);
    
        BitVec b = BitVecInit(base);
        BitVecPush(&b, false);
        BitVecPush(&b, true);
        BitVecPush(&b, true);
    
        BitVec c = BitVecInit(base);
        BitVecPush(&c, true);
        BitVecPush(&c, false);
        WriteFmt("Testing BitVecEquals rejects bad second operand\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad = {0};
        WriteFmt("Testing BitVecEqualsRange rejects bad second operand\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad = {0};
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec a = BitVecInit(base); // byte 0x00
        BitVec b = BitVecInit(base); // byte 0x01
    
        BitVec a = BitVecInit(base); // byte 0x00
        BitVec b = BitVecInit(base); // byte 0x01
    
        // a: 8 zero bits -> byte 0x00.
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec a = BitVecInit(base); // 10101010
        BitVec b = BitVecInit(base); // 01010101
    
        BitVec a = BitVecInit(base); // 10101010
        BitVec b = BitVecInit(base); // 01010101
    
        for (int i = 0; i < 8; i++) {
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec a = BitVecInit(base); // byte0 = 0xFF, byte1 = 0x00
        BitVec b = BitVecInit(base); // byte0 = 0xFF, byte1 = 0xFF
    
        BitVec a = BitVecInit(base); // byte0 = 0xFF, byte1 = 0x00
        BitVec b = BitVecInit(base); // byte0 = 0xFF, byte1 = 0xFF
    
        // a: first 8 bits set, next 8 clear.
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(base);
        BitVecPush(&bv, true);
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(base);
        BitVecPush(&bv, true);
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(base);
        BitVecPush(&bv, true);
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(base);
        BitVecPush(&bv, true);
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(base);
        BitVecPush(&bv, true);
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec bv1 = BitVecInit(base);
        BitVec bv2 = BitVecInit(base);
    
        BitVec bv1 = BitVecInit(base);
        BitVec bv2 = BitVecInit(base);
    
        for (u64 i = 0; i < 50; i++) {
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec neg   = BitVecInit(base);
        BitVec empty = BitVecInit(base);
    
        BitVec neg   = BitVecInit(base);
        BitVec empty = BitVecInit(base);
    
        BitVecPush(&neg, true); // single bit set -> MSB set -> negative
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec empty = BitVecInit(base);
        BitVec neg   = BitVecInit(base);
    
        BitVec empty = BitVecInit(base);
        BitVec neg   = BitVecInit(base);
    
        BitVecPush(&neg, true); // negative
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec neg = BitVecInit(base);
        BitVec pos = BitVecInit(base);
    
        BitVec neg = BitVecInit(base);
        BitVec pos = BitVecInit(base);
    
        BitVecPush(&neg, true);  // length 1, MSB set -> negative
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec empty = BitVecInit(base);
        BitVec neg   = BitVecInit(base);
    
        BitVec empty = BitVecInit(base);
        BitVec neg   = BitVecInit(base);
    
        BitVecPush(&neg, true); // negative
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec neg   = BitVecInit(base);
        BitVec empty = BitVecInit(base);
    
        BitVec neg   = BitVecInit(base);
        BitVec empty = BitVecInit(base);
    
        BitVecPush(&neg, true); // negative
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec a = BitVecInit(base);
        BitVec b = BitVecInit(base);
    
        BitVec a = BitVecInit(base);
        BitVec b = BitVecInit(base);
    
        // [1,1]: MSB (index 1) set -> both negative, identical magnitude.
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec a = BitVecInit(base);
        BitVec b = BitVecInit(base);
    
        BitVec a = BitVecInit(base);
        BitVec b = BitVecInit(base);
    
        // a = [1,1]: index1 (MSB) set -> negative, magnitude 3.
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(base);
        BitVecPush(&bv, true);
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(base);
        BitVecPush(&bv, true);
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(base);
        BitVecPush(&bv, true);
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(base);
        BitVecPush(&bv, true);
        WriteFmt("Testing BitVecIsSubset scans past index 42\n");
    
        BitVec bv1 = BitVecInit(base);
        BitVec bv2 = BitVecInit(base);
    
        BitVec bv1 = BitVecInit(base);
        BitVec bv2 = BitVecInit(base);
    
        for (u64 i = 0; i < 50; i++) {
        WriteFmt("Testing BitVecIsSubset with shorter bv1 stays in bounds\n");
    
        BitVec bv1 = BitVecInit(base); // length 2
        BitVec bv2 = BitVecInit(base); // length 5
    
        BitVec bv1 = BitVecInit(base); // length 2
        BitVec bv2 = BitVecInit(base); // length 5
    
        BitVecPush(&bv1, true);
        WriteFmt("Testing BitVecIsSubset with shorter bv2 stays in bounds\n");
    
        BitVec bv1 = BitVecInit(base); // length 5
        BitVec bv2 = BitVecInit(base); // length 2
    
        BitVec bv1 = BitVecInit(base); // length 5
        BitVec bv2 = BitVecInit(base); // length 2
    
        BitVecPush(&bv1, true);
        WriteFmt("Testing BitVecDisjoint scans beyond position 0\n");
    
        BitVec bv1 = BitVecInit(base);
        BitVec bv2 = BitVecInit(base);
    
        BitVec bv1 = BitVecInit(base);
        BitVec bv2 = BitVecInit(base);
    
        // Both: 0 1 1 -- no shared 1 at position 0, shared 1s at 1 and 2.
        WriteFmt("Testing BitVecIsSubset rejects NULL bv2\n");
    
        BitVec bv1 = BitVecInit(base);
        BitVecPush(&bv1, true);
        WriteFmt("Testing BitVecDisjoint rejects NULL bv1\n");
    
        BitVec bv2 = BitVecInit(base);
        BitVecPush(&bv2, true);
        WriteFmt("Testing BitVecDisjoint rejects NULL bv2\n");
    
        BitVec bv1 = BitVecInit(base);
        BitVecPush(&bv1, true);
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        BitVec bv = BitVecInit(adbg);
    
        // 1011 -- length > 1 and positions % length != 0 so the rotate body
        WriteFmt("Testing BitVec bitwise operations NULL handling\n");
    
        BitVec bv  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test NULL pointer - should abort
        WriteFmt("Testing BitVec AND with NULL result handling\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
        BitVecPush(&bv2, false);
        WriteFmt("Testing BitVec OR with NULL operand handling\n");
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test NULL operand - should abort
        WriteFmt("Testing BitVec XOR with NULL second operand handling\n");
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test NULL second operand - should abort
        WriteFmt("Testing BitVec NOT with NULL handling\n");
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test NULL operand - should abort
        WriteFmt("Testing BitVecAnd rejects bad third operand\n");
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec a      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad    = {0};
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec a      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad    = {0};
        WriteFmt("Testing BitVecAnd rejects bad second operand\n");
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad    = {0};
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad    = {0};
        WriteFmt("Testing BitVecOr rejects bad second operand\n");
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad    = {0};
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad    = {0};
        WriteFmt("Testing BitVecXor rejects bad third operand\n");
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec a      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad    = {0};
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec a      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad    = {0};
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        BitVec bv = BitVecInit(adbg);
    
        // length > 1 and positions % length != 0 so the rotate body
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        BitVec bv = BitVecInit(adbg);
    
        // 101010 so the render is a non-empty Str that must be freed.
        Allocator       *pbase  = ALLOCATOR_OF(&palloc);
    
        BitVec bv = BitVecInit(adbg);
        BitVecPush(&bv, true);
        BitVecPush(&bv, false);
        WriteFmt("Testing BitVecHammingDistance basic functionality\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecHammingDistance edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecJaccardSimilarity basic functionality\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecJaccardSimilarity edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecCosineSimilarity basic functionality\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecCosineSimilarity edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecDotProduct basic functionality\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecDotProduct edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecEditDistance basic functionality\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecEditDistance edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecCorrelation basic functionality\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecCorrelation edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecEntropy basic functionality\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecEntropy edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecAlignmentScore basic functionality\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecAlignmentScore edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecBestAlignment basic functionality\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecBestAlignment edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec Math stress tests\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        // Test edit distance with smaller vectors (expensive operation)
        BitVec small1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec small2 = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 50; i++) {
        // Test edit distance with smaller vectors (expensive operation)
        BitVec small1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec small2 = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 50; i++) {
            BitVecPush(&small1, i % 2 == 0);
    
        WriteFmt("Testing BitVecHammingDistance(NULL, bv2) - should fatal\n");
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv2, true);
        BitVecHammingDistance(NULL, &bv2);
    
        WriteFmt("Testing BitVecHammingDistance(bv1, NULL) - should fatal\n");
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
        BitVecHammingDistance(&bv1, NULL);
    
        WriteFmt("Testing BitVecJaccardSimilarity(NULL, bv2) - should fatal\n");
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv2, true);
        BitVecJaccardSimilarity(NULL, &bv2);
    
        WriteFmt("Testing BitVecJaccardSimilarity(bv1, NULL) - should fatal\n");
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
        BitVecJaccardSimilarity(&bv1, NULL);
    
        WriteFmt("Testing BitVecCosineSimilarity(NULL, bv2) - should fatal\n");
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv2, true);
        BitVecCosineSimilarity(NULL, &bv2);
    
        WriteFmt("Testing BitVecCosineSimilarity(bv1, NULL) - should fatal\n");
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
        BitVecCosineSimilarity(&bv1, NULL);
    
        WriteFmt("Testing BitVecDotProduct(NULL, bv2) - should fatal\n");
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv2, true);
        BitVecDotProduct(NULL, &bv2);
    
        WriteFmt("Testing BitVecDotProduct(bv1, NULL) - should fatal\n");
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
        BitVecDotProduct(&bv1, NULL);
    
        WriteFmt("Testing BitVecEditDistance(NULL, bv2) - should fatal\n");
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv2, true);
        BitVecEditDistance(NULL, &bv2);
    
        WriteFmt("Testing BitVecEditDistance(bv1, NULL) - should fatal\n");
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
        BitVecEditDistance(&bv1, NULL);
    
        WriteFmt("Testing BitVecCorrelation(NULL, bv2) - should fatal\n");
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv2, true);
        BitVecCorrelation(NULL, &bv2);
    
        WriteFmt("Testing BitVecCorrelation(bv1, NULL) - should fatal\n");
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
        BitVecCorrelation(&bv1, NULL);
    
        WriteFmt("Testing BitVecAlignmentScore(NULL, bv2, 1, -1) - should fatal\n");
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv2, true);
        BitVecAlignmentScore(NULL, &bv2, 1, -1);
    
        WriteFmt("Testing BitVecAlignmentScore(bv1, NULL, 1, -1) - should fatal\n");
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
        BitVecAlignmentScore(&bv1, NULL, 1, -1);
    
        WriteFmt("Testing BitVecBestAlignment(NULL, bv2) - should fatal\n");
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv2, true);
        BitVecBestAlignment(NULL, &bv2);
    
        WriteFmt("Testing BitVecBestAlignment(bv1, NULL) - should fatal\n");
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
        BitVecBestAlignment(&bv1, NULL);
        WriteFmt("Testing BitVecJaccardSimilarity guard only fires when both empty\n");
    
        BitVec empty = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec one   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&one, true);
    
        BitVec empty = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec one   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&one, true);
        WriteFmt("Testing BitVecJaccardSimilarity with bv1 shorter than bv2\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // bv1 = {1}, bv2 = {1, 0}. Intersection 1 (pos 0), union 1 -> 1.0.
        WriteFmt("Testing BitVecJaccardSimilarity with bv2 shorter than bv1\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // bv1 = {1, 0}, bv2 = {1}. Intersection 1 (pos 0), union 1 -> 1.0.
        WriteFmt("Testing BitVecJaccardSimilarity reads bv2 bits in valid region\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // bv1 = {0, 0}, bv2 = {1, 1}. Intersection 0, union 2 -> 0.0.
        WriteFmt("Testing BitVecEditDistance column-0 base case\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVecPush(&bv1, false);
        WriteFmt("Testing BitVecEditDistance deletion term\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVecPush(&bv1, false);
        // exact size the empty->5 distance will recycle, guaranteeing the stale
        // (large) values land in prev_row[len2].
        BitVec warm_a = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec warm_b = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 5; i++) {
        // (large) values land in prev_row[len2].
        BitVec warm_a = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec warm_b = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 5; i++) {
            BitVecPush(&warm_a, (i % 2) == 0);
        BitVecDeinit(&warm_b);
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc)); // empty
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 5; i++) {
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc)); // empty
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 5; i++) {
            BitVecPush(&bv2, true);
        // the empty->4 distance recycles, so the unfilled prev_row[len2] holds a
        // stale large value rather than a coincidental 4.
        BitVec warm_a = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec warm_b = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 4; i++) {
        // stale large value rather than a coincidental 4.
        BitVec warm_a = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec warm_b = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 4; i++) {
            BitVecPush(&warm_a, (i % 2) == 1);
        BitVecDeinit(&warm_b);
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc)); // empty
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 4; i++) {
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc)); // empty
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 4; i++) {
            BitVecPush(&bv2, false);
        WriteFmt("Testing BitVecEditDistance insertion term\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVecPush(&bv1, true);
        WriteFmt("Testing BitVecJaccardSimilarity rejects bad second operand\n");
    
        BitVec empty = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad   = {0};
        WriteFmt("Testing BitVecCorrelation with bv1 shorter than bv2 (no OOB)\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecCorrelation with bv2 shorter than bv1 (no OOB)\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecEntropy on an unbalanced (3 ones, 1 zero) vector\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecBestAlignment all-mismatch best offset == 3\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecCosineSimilarity of identical vectors == 1.0\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecEntropy of a 3:1 distribution\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec bv     = BitVecInit(base);
        bool   result = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&bv1, "1011");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&bv1, "1011");
        push_bits(&bv2, "11");
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&bv1, "11");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&bv1, "11");
        push_bits(&bv2, "000");
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&bv1, "1010");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&bv1, "1010");
        push_bits(&bv2, "10");
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&bv1, "0011");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&bv1, "0011");
        push_bits(&bv2, "11");
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&bv1, "0011");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&bv1, "0011");
        push_bits(&bv2, "11");
        bool success = true;
    
        BitVec bv1 = BitVecInit(alloc_base);
        z          = "10110";
        StrReadFmt(z, "{}", bv1);
        BitVecDeinit(&bv1);
    
        BitVec bv2 = BitVecInit(alloc_base);
        z          = "0xDEAD";
        StrReadFmt(z, "{}", bv2);
        BitVecDeinit(&bv2);
    
        BitVec bv3 = BitVecInit(alloc_base);
        z          = "0o755";
        StrReadFmt(z, "{}", bv3);
        BitVecDeinit(&bv3);
    
        BitVec bv4 = BitVecInit(alloc_base);
        z          = "   1101";
        StrReadFmt(z, "{}", bv4);
        BitVecDeinit(&bv4);
    
        BitVec bv5 = BitVecInit(alloc_base);
        z          = "0";
        StrReadFmt(z, "{}", bv5);
        WriteFmt("Testing basic BitVec pattern functions\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecFindPattern function\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecFindLastPattern function\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecFindAllPattern function\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecFindAllPattern Vec form\n");
    
        BitVec source  = BitVecInit(base);
        BitVec pattern = BitVecInit(base);
        bool   result  = true;
    
        BitVec source  = BitVecInit(base);
        BitVec pattern = BitVecInit(base);
        bool   result  = true;
        WriteFmt("Testing BitVec pattern edge cases\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVec pattern stress tests\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecStartsWith basic functionality\n");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec prefix = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec prefix = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecStartsWith edge cases\n");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec prefix = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec prefix = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecEndsWith basic functionality\n");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec suffix = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec suffix = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecEndsWith edge cases\n");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec suffix = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec suffix = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecFindPattern basic functionality\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecContainsAt basic functionality\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecContainsAt edge cases\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecCountPattern basic functionality\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecRFindPattern basic functionality\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecReplace basic functionality\n");
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result      = true;
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result      = true;
        WriteFmt("Testing BitVecReplaceAll basic functionality\n");
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result      = true;
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result      = true;
        WriteFmt("Testing BitVecMatches basic functionality\n");
    
        BitVec source   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec wildcard = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec source   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec wildcard = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result   = true;
        BitVec source   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec wildcard = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result   = true;
        WriteFmt("Testing BitVecFuzzyMatch basic functionality\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecRegexMatch basic functionality\n");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecPrefixMatch basic functionality\n");
    
        BitVec  source   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecs patterns = VecInitWithDeepCopy(NULL, BitVecDeinit, ALLOCATOR_OF(&alloc));
        bool    result   = true;
        BitVec *p2 = VecPtrAt(&patterns, 2);
    
        *p0 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p1 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        *p0 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p1 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p2 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p0 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p1 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Pattern 0: 111 (should not match)
        WriteFmt("Testing BitVecSuffixMatch basic functionality\n");
    
        BitVec  source   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecs patterns = VecInitWithDeepCopy(NULL, BitVecDeinit, ALLOCATOR_OF(&alloc));
        bool    result   = true;
        BitVec *p2 = VecPtrAt(&patterns, 2);
    
        *p0 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p1 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        *p0 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p1 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p2 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p0 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p1 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Pattern 0: 111 (should not match)
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source  = BitVecInit(base);
        BitVec pattern = BitVecInit(base);
        bool   result  = true;
    
        BitVec source  = BitVecInit(base);
        BitVec pattern = BitVecInit(base);
        bool   result  = true;
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source  = BitVecInit(base);
        BitVec pattern = BitVecInit(base);
        bool   result  = true;
    
        BitVec source  = BitVecInit(base);
        BitVec pattern = BitVecInit(base);
        bool   result  = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec suffix = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&source, "101");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec suffix = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&source, "101");
        push_bits(&suffix, "101");
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&source, "101");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&source, "101");
        push_bits(&pattern, "101");
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&source, "101");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&source, "101");
        push_bits(&pattern, "101");
        WriteFmt("Testing BitVecRFindPattern window-condition (ge_to_lt)\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecRFindPattern window-condition (add_to_sub)\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecRFindPattern window-value (add_to_sub)\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecRFindPattern loop-seed (add_to_sub)\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecRFindPattern loop-guard (gt_to_ge)\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecReplaceAll found-flag init\n");
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result      = true;
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result      = true;
        WriteFmt("Testing BitVecReplaceAll forward-scan direction\n");
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result      = true;
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result      = true;
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source = BitVecInit(base);
        BitVec old    = BitVecInit(base);
        BitVec neww   = BitVecInit(base);
    
        BitVec source = BitVecInit(base);
        BitVec old    = BitVecInit(base);
        BitVec neww   = BitVecInit(base);
        bool   result = true;
        BitVec source = BitVecInit(base);
        BitVec old    = BitVecInit(base);
        BitVec neww   = BitVecInit(base);
        bool   result = true;
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source = BitVecInit(base);
        BitVec old    = BitVecInit(base);
        BitVec neww   = BitVecInit(base);
    
        BitVec source = BitVecInit(base);
        BitVec old    = BitVecInit(base);
        BitVec neww   = BitVecInit(base);
        bool   result = true;
        BitVec source = BitVecInit(base);
        BitVec old    = BitVecInit(base);
        BitVec neww   = BitVecInit(base);
        bool   result = true;
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source   = BitVecInit(base);
        BitVec pattern  = BitVecInit(base);
        BitVec wildcard = BitVecInit(base);
    
        BitVec source   = BitVecInit(base);
        BitVec pattern  = BitVecInit(base);
        BitVec wildcard = BitVecInit(base);
        bool   result   = true;
        BitVec source   = BitVecInit(base);
        BitVec pattern  = BitVecInit(base);
        BitVec wildcard = BitVecInit(base);
        bool   result   = true;
        // Sanity: an all-wildcard mask must still match (proves we did not just
        // wire the function to always return false).
        BitVec wild_all = BitVecInit(base);
        for (int i = 0; i < 4; i++)
            BitVecPush(&wild_all, true);
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source  = BitVecInit(base);
        BitVec pattern = BitVecInit(base);
        bool   result  = true;
    
        BitVec source  = BitVecInit(base);
        BitVec pattern = BitVecInit(base);
        bool   result  = true;
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source  = BitVecInit(base);
        BitVec pattern = BitVecInit(base);
        bool   result  = true;
    
        BitVec source  = BitVecInit(base);
        BitVec pattern = BitVecInit(base);
        bool   result  = true;
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source  = BitVecInit(base);
        BitVec pattern = BitVecInit(base);
    
        BitVec source  = BitVecInit(base);
        BitVec pattern = BitVecInit(base);
    
        // source: 4096 zero bits; pattern: a single 1. No window ever matches with
        WriteFmt("Testing bitvec_regex_match_str returns false on non-match\n");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecInit\n");
    
        // Test basic initialization
    
        // Test basic initialization
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Check initial state
        WriteFmt("Testing BitVecDeinit\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add some data to make sure deinitialization works with allocated memory
        WriteFmt("Testing BitVecReserve\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Reserve space for 50 bits
        WriteFmt("Testing BitVecClear\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add some data
        WriteFmt("Testing BitVecResize\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add some initial data
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecInit edge cases\n");
    
        // Test multiple initializations
    
        // Test multiple initializations
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv3 = BitVecInit(ALLOCATOR_OF(&alloc));
        // Test multiple initializations
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv3 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv3 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        bool result = (BitVecLen(&bv1) == 0) && (BitVecLen(&bv2) == 0) && (BitVecLen(&bv3) == 0);
        WriteFmt("Testing BitVecReserve edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecReu64 edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecClear edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        // Test multiple init/deinit cycles
        for (int cycle = 0; cycle < 100; cycle++) {
            BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
            // Add some data
        // failure rather than aborting. The Must variant aborts, so use it here
        // to validate the deadend abort path.
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVecMustReserve(&bv, SIZE_MAX);
        // failure rather than aborting. The Must variant aborts, so use it here
        // to validate the deadend abort path.
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVecMustResize(&bv, SIZE_MAX);
    bool test_leak_write_bitvec_freed(void) {
        HeapAllocator va = HeapAllocatorInit();
        BitVec        v  = BitVecInit(ALLOCATOR_OF(&va));
        BitVecResize(&v, 12);
        LEAK_WRITE_PRELUDE();
    static bool leak_bitvec_overflow(Zstr input) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        BitVec         bv  = BitVecInit(ALLOCATOR_OF(&dbg));
        Zstr           p   = input;
        StrReadFmt(p, "{}", bv);
        WriteFmt("Testing BitVecRunLengths with NULL runs array\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv, true);
        bool values[5];
        WriteFmt("Testing BitVecRunLengths with NULL values array\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv, true);
        u64 runs[5];
        WriteFmt("Testing BitVecRunLengths with zero max_runs\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv, true);
        u64  runs[5];
        // no public setter exists -- the whole point of this test is to plant
        // length>0 with data==NULL so ValidateBitVec aborts in the foreach prologue.
        BitVec bv   = BitVecInit(ALLOCATOR_OF(&alloc));
        bv.length   = 5;
        bv.capacity = 10;
        WriteFmt("Testing BitVecFindPattern(NULL, pattern) - should fatal\n");
    
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&pattern, true);
        WriteFmt("Testing BitVecFindPattern(source, NULL) - should fatal\n");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVecPush(&source, false);
        WriteFmt("Testing BitVecFindLastPattern(NULL, pattern) - should fatal\n");
    
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&pattern, true);
        WriteFmt("Testing BitVecFindLastPattern(source, NULL) - should fatal\n");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVecPush(&source, false);
        WriteFmt("Testing BitVecFindAllPattern(source, NULL, results, 10) - should fatal\n");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        size   results[10];
        BitVecPush(&source, true);
        WriteFmt("Testing BitVecFindAllPattern(source, pattern, NULL, 10) - should fatal\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVecPush(&source, false);
        WriteFmt("Testing BitVecFindAllPattern(source, pattern, results, 0) - should fatal\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        size   results[10];
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        size   results[10];
        BitVecPush(&source, true);
    
        WriteFmt("Testing BitVecStartsWith(NULL, prefix) - should fatal\n");
        BitVec prefix = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&prefix, true);
        BitVecStartsWith(NULL, &prefix);
    
        WriteFmt("Testing BitVecStartsWith(source, NULL) - should fatal\n");
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVecStartsWith(&source, NULL);
    
        WriteFmt("Testing BitVecEndsWith(NULL, suffix) - should fatal\n");
        BitVec suffix = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&suffix, true);
        BitVecEndsWith(NULL, &suffix);
    
        WriteFmt("Testing BitVecEndsWith(source, NULL) - should fatal\n");
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVecEndsWith(&source, NULL);
    
        WriteFmt("Testing BitVecContainsAt(NULL, pattern, 0) - should fatal\n");
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&pattern, true);
        BitVecContainsAt(NULL, &pattern, 0);
    
        WriteFmt("Testing BitVecContainsAt(source, NULL, 0) - should fatal\n");
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVecContainsAt(&source, NULL, 0);
    
        WriteFmt("Testing BitVecMatches(NULL, pattern, wildcard) - should fatal\n");
        BitVec pattern  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec wildcard = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&pattern, true);
        WriteFmt("Testing BitVecMatches(NULL, pattern, wildcard) - should fatal\n");
        BitVec pattern  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec wildcard = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&pattern, true);
        BitVecPush(&wildcard, false);
    
        WriteFmt("Testing BitVecRegexMatch(source, NULL) - should fatal\n");
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVecRegexMatch(&source, (Zstr)NULL);
    
        WriteFmt("Testing BitVecPrefixMatch(source, NULL, 1) - should fatal\n");
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVecPrefixMatch(&source, NULL);
    
        WriteFmt("Testing BitVecSuffixMatch(source, NULL, 1) - should fatal\n");
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVecSuffixMatch(&source, NULL);
        WriteFmt("Testing BitVecFindAllPattern (vec) with NULL bitvector\n");
    
        BitVec pattern = BitVecInit(base);
        BitVecPush(&pattern, true);
        WriteFmt("Testing BitVecFindAllPattern (vec) with NULL pattern\n");
    
        BitVec source = BitVecInit(base);
        BitVecPush(&source, true);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&pattern, true);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&pattern, true);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        WriteFmt("Testing BitVecReplace(src, old, NULL) with old absent - should fatal\n");
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&source, "0000");
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&source, "0000");
        push_bits(&old_pattern, "111");             // not present in source
    
        BitVec bad         = {0}; // magic mismatch -> ValidateBitVec aborts
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&old_pattern, "1");
        BitVec bad         = {0}; // magic mismatch -> ValidateBitVec aborts
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&old_pattern, "1");
        push_bits(&new_pattern, "0");
        WriteFmt("Testing BitVecReplaceAll(empty, NULL, new) - should fatal\n");
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc)); // empty
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&new_pattern, "0");
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc)); // empty
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&new_pattern, "0");
        WriteFmt("Testing BitVecReplaceAll(empty, old, NULL) - should fatal\n");
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc)); // empty
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&old_pattern, "1");
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc)); // empty
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&old_pattern, "1");
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source   = BitVecInit(base);
        BitVec wildcard = BitVecInit(base);
        BitVecPush(&source, true);
    
        BitVec source   = BitVecInit(base);
        BitVec wildcard = BitVecInit(base);
        BitVecPush(&source, true);
        BitVecPush(&wildcard, false);
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source  = BitVecInit(base);
        BitVec pattern = BitVecInit(base);
        BitVecPush(&source, true);
    
        BitVec source  = BitVecInit(base);
        BitVec pattern = BitVecInit(base);
        BitVecPush(&source, true);
        BitVecPush(&pattern, true);
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec pattern = BitVecInit(base);
        BitVecPush(&pattern, true);
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source = BitVecInit(base);
        BitVecPush(&source, true);
Last updated on