Skip to content

Commit 56ce4d8

Browse files
committed
Test that invertInPlace does not corrupt data around its slice
1 parent f4c0958 commit 56ce4d8

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

test/Tests/SetOps.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ setOpTests = testGroup "Set operations"
3737
, mkGroup "invertBits" prop_invertBits
3838

3939
, testProperty "invertInPlace" prop_invertInPlace
40+
, testProperty "invertInPlace around" prop_invertInPlace_around
4041
, testProperty "invertInPlaceWords" prop_invertInPlaceWords
4142
, testProperty "invertInPlace middle" prop_invertInPlace_middle
4243
, testProperty "invertInPlaceLong middle" prop_invertInPlaceLong_middle
@@ -138,6 +139,17 @@ prop_invertInPlace :: U.Vector Bit -> Property
138139
prop_invertInPlace xs =
139140
U.map complement xs === U.modify invertInPlace xs
140141

142+
prop_invertInPlace_around :: U.Vector Bit -> Property
143+
prop_invertInPlace_around xs = ioProperty $ do
144+
let l = U.length xs
145+
when (l < 2) discard
146+
ys <- U.thaw xs
147+
let zs = MU.slice 1 (l - 2) ys
148+
invertInPlace zs
149+
hd <- MU.read ys 0
150+
lst <- MU.read ys (MU.length ys - 1)
151+
pure $ hd === U.head xs .&&. lst === U.last xs
152+
141153
prop_invertInPlaceWords :: Large (U.Vector Bit) -> Property
142154
prop_invertInPlaceWords = prop_invertInPlace . getLarge
143155

0 commit comments

Comments
 (0)