Skip to content

Commit

Permalink
wip: Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pgujjula committed Dec 13, 2024
1 parent 86ee0cf commit 9efa974
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions test/Test/Data/List/ApplyMerge/New.hs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,76 @@ testNonEmptyFunctions label am funcs op =
expected = NE.sort $ on (liftA2 f) (take1 limit) xs ys
in on (===) (NE.take limit) actual expected

data family Ordered (f :: Type -> Type)

Check failure on line 174 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.10.1

Not in scope: type constructor or class ‘Type’

Check failure on line 174 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.10.1

Not in scope: type constructor or class ‘Type’

Check failure on line 174 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.8.4

Not in scope: type constructor or class ‘Type’

Check failure on line 174 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.8.4

Not in scope: type constructor or class ‘Type’

Check failure on line 174 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.2.8

Not in scope: type constructor or class ‘Type’

Check failure on line 174 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.2.8

Not in scope: type constructor or class ‘Type’

Check failure on line 174 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.4.8

Not in scope: type constructor or class ‘Type’

Check failure on line 174 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.4.8

Not in scope: type constructor or class ‘Type’

Check failure on line 174 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.6.6

Not in scope: type constructor or class ‘Type’

Check failure on line 174 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.6.6

Not in scope: type constructor or class ‘Type’

data instance Ordered []
= OrderedList
{ olOrigin :: Integer,
olSequence :: Either [Natural] (InfiniteList Natural)

Check failure on line 179 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.10.1

Not in scope: type constructor or class ‘InfiniteList’

Check failure on line 179 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.8.4

Not in scope: type constructor or class ‘InfiniteList’

Check failure on line 179 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.2.8

Not in scope: type constructor or class ‘InfiniteList’

Check failure on line 179 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.4.8

Not in scope: type constructor or class ‘InfiniteList’

Check failure on line 179 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.6.6

Not in scope: type constructor or class ‘InfiniteList’
}
deriving (Generic)

Check failure on line 181 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.10.1

Not in scope: type constructor or class ‘Generic’

Check failure on line 181 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.8.4

Not in scope: type constructor or class ‘Generic’

Check failure on line 181 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.2.8

Not in scope: type constructor or class ‘Generic’

Check failure on line 181 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.4.8

Not in scope: type constructor or class ‘Generic’

Check failure on line 181 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.6.6

Not in scope: type constructor or class ‘Generic’

instance Arbitrary (Ordered []) where

Check failure on line 183 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.10.1

Not in scope: type constructor or class ‘Arbitrary’

Check failure on line 183 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.8.4

Not in scope: type constructor or class ‘Arbitrary’

Check failure on line 183 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.2.8

Not in scope: type constructor or class ‘Arbitrary’

Check failure on line 183 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.4.8

Not in scope: type constructor or class ‘Arbitrary’

Check failure on line 183 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.6.6

Not in scope: type constructor or class ‘Arbitrary’
arbitrary = liftA2 OrderedList arbitrary arbitrary
shrink = genericShrink

data instance Ordered NonEmpty
= OrderedNonEmpty
{ onOrigin :: Integer,
onSequence :: (Natural, Either [Natural] (InfiniteList Natural))

Check failure on line 190 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.10.1

Not in scope: type constructor or class ‘InfiniteList’

Check failure on line 190 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.8.4

Not in scope: type constructor or class ‘InfiniteList’

Check failure on line 190 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.2.8

Not in scope: type constructor or class ‘InfiniteList’

Check failure on line 190 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.4.8

Not in scope: type constructor or class ‘InfiniteList’

Check failure on line 190 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.6.6

Not in scope: type constructor or class ‘InfiniteList’
}
deriving (Generic)

Check failure on line 192 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.10.1

Not in scope: type constructor or class ‘Generic’

Check failure on line 192 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.8.4

Not in scope: type constructor or class ‘Generic’

Check failure on line 192 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.2.8

Not in scope: type constructor or class ‘Generic’

Check failure on line 192 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.4.8

Not in scope: type constructor or class ‘Generic’

Check failure on line 192 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.6.6

Not in scope: type constructor or class ‘Generic’

instance Arbitrary (Ordered NonEmpty) where

Check failure on line 194 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.10.1

Not in scope: type constructor or class ‘Arbitrary’

Check failure on line 194 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.8.4

Not in scope: type constructor or class ‘Arbitrary’

Check failure on line 194 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.2.8

Not in scope: type constructor or class ‘Arbitrary’

Check failure on line 194 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.4.8

Not in scope: type constructor or class ‘Arbitrary’

Check failure on line 194 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.6.6

Not in scope: type constructor or class ‘Arbitrary’
arbitrary = liftA2 OrderedNonEmpty arbitrary arbitrary
shrink = genericShrink

class (Functor f) => ApplyMergeable (f :: Type -> Type) where

Check failure on line 198 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.10.1

Not in scope: type constructor or class ‘Type’

Check failure on line 198 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.10.1

Not in scope: type constructor or class ‘Type’

Check failure on line 198 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.8.4

Not in scope: type constructor or class ‘Type’

Check failure on line 198 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.8.4

Not in scope: type constructor or class ‘Type’

Check failure on line 198 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.2.8

Not in scope: type constructor or class ‘Type’

Check failure on line 198 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.2.8

Not in scope: type constructor or class ‘Type’

Check failure on line 198 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.4.8

Not in scope: type constructor or class ‘Type’

Check failure on line 198 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.4.8

Not in scope: type constructor or class ‘Type’

Check failure on line 198 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.6.6

Not in scope: type constructor or class ‘Type’

Check failure on line 198 in test/Test/Data/List/ApplyMerge/New.hs

View workflow job for this annotation

GitHub Actions / cabal test - ghc-9.6.6

Not in scope: type constructor or class ‘Type’
getIncreasing :: Ordered f -> f Natural
getDecreasing :: Ordered f -> f Integer
toList :: f a -> [a]

instance ApplyMergeable [] where
getIncreasing =
olSequence
>>> either id getInfiniteList
>>> scanl1 (+)

getDecreasing ol =
let x0 = olOrigin ol
xs = map (negate . toInteger) (getIncreasing ol)
in map (+ x0) xs

toList = id

instance ApplyMergeable NonEmpty where
getIncreasing =
onSequence
>>> second (either id getInfiniteList)
>>> uncurry (:|)
>>> NonEmpty.scanl1 (+)

getDecreasing one =
let x0 = onOrigin one
xs = fmap (negate . toInteger) (getIncreasing one)
in fmap (+ x0) xs

toList = NonEmpty.toList

testGenericFunctions :: (Arbitrary (Ordered f), Show (Ordered f)) => (ApplyMergeable f) => TestFunctions f
testGenericFunctions label am _ _ =
QC.testProperty label $ do
(fName, f) <- QC.elements increasingNaturalFuncs
let limit = 100
pure . QC.counterexample fName $
\(getIncreasing -> xs) (getIncreasing -> ys) ->
let actual :: [Natural]
actual = toList (am f xs ys)

expected :: [Natural]
expected = sort $ on (liftA2 f) (take limit) (toList xs) (toList ys)
in on (===) (take limit) actual expected

-- Utilities
take1 :: Int -> NonEmpty a -> NonEmpty a
take1 n (x :| xs) = x :| take n xs

0 comments on commit 9efa974

Please sign in to comment.