Skip to content

Commit

Permalink
Fix adjust modifying the wrong index. fixes #19
Browse files Browse the repository at this point in the history
  • Loading branch information
hdgarrood committed Jan 5, 2016
1 parent 215344b commit 0e6ae2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Data/Sequence.purs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ unsafeAdjust f i (Seq xs) =
g :: Elem a -> Elem a
g = unsafeCoerce f

l' = FT.cons (g x) (force l)
l' = FT.snoc (force l) (g x)
in
Seq (FT.append l' (force r))

Expand Down
8 changes: 8 additions & 0 deletions test/Data/Sequence.purs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ sequenceTests = do
result = sum (S.adjust (+1) idx' seq')
in result == 1 <?> "seq': " <> show seq' <> ", result: " <> show result

log "Test adjust modifies at the correct index"
quickCheck $ \(ArbSeq seq) idx ->
let seq' = const "hello" <$> S.cons 0 seq
idx' = integerBetween 0 (S.length seq') idx
result = S.index idx' (S.adjust (<> ", world") idx' seq')
in (result == Just "hello, world")
<?> "seq': " <> show seq' <> ", result: " <> show result

log "Test take"
-- We must account for potentially negative indices generated by QuickCheck
-- take is defined over negative indices, though the length of the result
Expand Down

0 comments on commit 0e6ae2d

Please sign in to comment.