Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fromListWithDef divergence #42

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/Data/Chimera/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -553,13 +553,21 @@
[] -> G.singleton a : map (\k -> G.replicate (1 `shiftL` k) a) [0 .. bits - 1]
x : xs -> G.singleton x : go 0 xs

go k xs = case measureOff kk xs of
Left l ->
G.fromListN kk (xs ++ replicate l a)
: map (\n -> G.replicate (1 `shiftL` n) a) [k + 1 .. bits - 1]
Right (ys, zs) -> G.fromListN kk ys : go (k + 1) zs
go k xs =
if k == bits
then []
else v : go (k + 1) zs
where
kk = 1 `shiftL` k
(v, zs) =
case measureOff kk xs of
Left l ->
( if l == kk
then G.replicate kk a
else G.fromListN kk (xs ++ replicate l a)
, []
)
Right (ys, zs') -> (G.fromListN kk ys, zs')

-- | Create a stream of values from a given infinite list.
--
Expand Down Expand Up @@ -614,7 +622,7 @@
=> v a
-> Chimera v a
-> Chimera v a
prependVector (G.uncons -> Nothing) ch = ch

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.2)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.2)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.2)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.4)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.4)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.4)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.6)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.6)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.6)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.8)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.8)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.8)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.10)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.10)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.10)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 9.0)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 9.0)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 9.0)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 9.2)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 9.2)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 9.2)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 9.4)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 9.4)

Pattern match(es) are non-exhaustive

Check warning on line 625 in src/Data/Chimera/Internal.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 9.4)

Pattern match(es) are non-exhaustive
prependVector (G.uncons -> Just (pref0, pref)) (Chimera as) =
Chimera $
fromListN (bits + 1) $
Expand Down
19 changes: 14 additions & 5 deletions test/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,20 @@ chimeraTests = testGroup "Chimera"
, QC.testProperty "toList" $
\x xs -> xs === take (length xs) (Ch.toList (Ch.fromListWithDef x xs :: UChimera Bool))

, QC.testProperty "fromListWithDef" $
\x xs ix ->
let jx = ix `mod` 65536 in
(if fromIntegral jx < length xs then xs !! fromIntegral jx else x) ===
Ch.index (Ch.fromListWithDef x xs :: UChimera Bool) jx
, testGroup "fromListWithDef"
[ QC.testProperty "finite list" $
\x xs ix ->
let jx = ix `mod` 65536 in
(if fromIntegral jx < length xs then xs !! fromIntegral jx else x) ===
Ch.index (Ch.fromListWithDef x xs :: UChimera Bool) jx

, QC.testProperty "infinite list" $
\x xs ix ->
let jx = ix `mod` 65536 in
let xs' = QC.getInfiniteList xs in
(xs' !! fromIntegral jx) ===
Ch.index (Ch.fromListWithDef x xs' :: UChimera Bool) jx
]

, QC.testProperty "fromInfinite" $
\x xs ix ->
Expand Down
Loading