Skip to content

Commit

Permalink
fixup! assert round-tripping
Browse files Browse the repository at this point in the history
  • Loading branch information
tsenart committed Dec 5, 2024
1 parent 5a7da69 commit fe3c4b9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions bitset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2541,6 +2541,18 @@ func TestBitSetExtract(t *testing.T) {
if !dst.Equal(tc.expected) {
t.Errorf("got %v, expected %v", dst, tc.expected)
}

// Verify inverse relationship within the mask bits
deposited := New(tc.src.Len())
dst.DepositTo(tc.mask, deposited)

// Only bits selected by the mask should match between source and deposited
maskedSource := tc.src.Intersection(tc.mask)
maskedDeposited := deposited.Intersection(tc.mask)

if !maskedSource.Equal(maskedDeposited) {
t.Error("DepositTo(ExtractTo(x,m),m) doesn't preserve masked source bits")
}
})
}
}
Expand Down Expand Up @@ -2657,6 +2669,14 @@ func TestBitSetDeposit(t *testing.T) {
if !dst.Equal(tc.expected) {
t.Errorf("got %v, expected %v", dst, tc.expected)
}

// Verify inverse relationship for set bits up to mask cardinality
extracted := New(tc.src.Len())
dst.ExtractTo(tc.mask, extracted)

if !extracted.Equal(tc.src) {
t.Error("ExtractTo(DepositTo(x,m),m) doesn't preserve source bits that were selected by mask")
}
})
}
}
Expand Down

0 comments on commit fe3c4b9

Please sign in to comment.