From fe3c4b97067d065e296dc321f55a7daf7243f011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Senart?= Date: Thu, 5 Dec 2024 17:03:30 +0100 Subject: [PATCH] fixup! assert round-tripping --- bitset_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/bitset_test.go b/bitset_test.go index 77ff334..309e429 100644 --- a/bitset_test.go +++ b/bitset_test.go @@ -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") + } }) } } @@ -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") + } }) } }