Skip to content

Commit

Permalink
Fix Data.RRBVector.Internal.Array.{snoc, cons}
Browse files Browse the repository at this point in the history
Closes #10
  • Loading branch information
konsumlamm committed Oct 21, 2023
1 parent 305f4f2 commit 1b285f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Data/RRBVector/Internal/Array.hs
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,17 @@ last :: Array a -> a
last arr = index arr (length arr - 1)

snoc :: Array a -> a -> Array a
snoc (Array _ len arr) x = Array 0 len' $ runSmallArray $ do
snoc (Array start len arr) x = Array 0 len' $ runSmallArray $ do
sma <- newSmallArray len' x
copySmallArray sma 0 arr 0 len
copySmallArray sma 0 arr start len
pure sma
where
!len' = len + 1

cons :: Array a -> a -> Array a
cons (Array _ len arr) x = Array 0 len' $ runSmallArray $ do
cons (Array start len arr) x = Array 0 len' $ runSmallArray $ do
sma <- newSmallArray len' x
copySmallArray sma 1 arr 0 len
copySmallArray sma 1 arr start len
pure sma
where
!len' = len + 1
Expand Down
10 changes: 10 additions & 0 deletions test/Properties.hs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ properties = testGroup "properties"
]
, instances
, laws
, issues
]

instances :: TestTree
Expand Down Expand Up @@ -219,3 +220,12 @@ laws = testGroup "typeclass laws"
, localOption (QuickCheckTests 500) . localOption (QuickCheckMaxSize 5000) . testLaws $ monadZipLaws proxyV
, localOption (QuickCheckMaxSize 100) . testLaws $ traversableLaws proxyV
]

-- old issues, to avoid regressions
issues :: TestTree
issues = testGroup "issues"
-- https://github.com/konsumlamm/rrb-vector/issues/10
[ testProperty "#10" $ \x v -> case V.viewl v of
Nothing -> property True
Just (_, v') -> x V.<| v' === V.update 0 x v
]

0 comments on commit 1b285f9

Please sign in to comment.