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 fromInfinite error #41

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
1 change: 1 addition & 0 deletions chimera.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ test-suite chimera-test
build-depends:
base >=4.5 && <5,
chimera,
infinite-list,
QuickCheck >=2.10 && <2.15,
tasty <1.6,
tasty-hunit <0.11,
Expand Down
5 changes: 4 additions & 1 deletion src/Data/Chimera/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,10 @@
where
go0 (x :< xs) = G.singleton x : go 0 xs

go k xs = G.fromListN kk ys : go (k + 1) zs
go k xs =
if k == bits
then []
else G.fromListN kk ys : go (k + 1) zs
where
kk = 1 `shiftL` k
(ys, zs) = Inf.splitAt kk xs
Expand Down Expand Up @@ -611,7 +614,7 @@
=> v a
-> Chimera v a
-> Chimera v a
prependVector (G.uncons -> Nothing) ch = ch

Check warning on line 617 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 617 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 617 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 617 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 617 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 617 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 617 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 617 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 617 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 617 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 617 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 617 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 617 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 617 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 617 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 617 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 617 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 617 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 617 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 617 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 617 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 617 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 617 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 617 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
9 changes: 9 additions & 0 deletions test/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import Test.Tasty.QuickCheck as QC hiding ((.&.))
import Data.Bits
import Data.Foldable
import Data.Function (fix)
import qualified Data.List.Infinite as I
import qualified Data.List as L
import qualified Data.List.NonEmpty as NE
import qualified Data.Vector.Generic as G

import Data.Chimera.ContinuousMapping
Expand Down Expand Up @@ -158,6 +160,13 @@ chimeraTests = testGroup "Chimera"
(if fromIntegral jx < length xs then xs !! fromIntegral jx else x) ===
Ch.index (Ch.fromListWithDef x xs :: UChimera Bool) jx

, QC.testProperty "fromInfinite" $
\x xs ix ->
let jx = ix `mod` 65536 in
let ys = I.cycle (x NE.:| xs) in
(ys I.!! jx) ===
Ch.index (Ch.fromInfinite ys :: UChimera Bool) jx

, QC.testProperty "fromVectorWithDef" $
\x xs ix ->
let jx = ix `mod` 65536 in
Expand Down
Loading