-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add property tests for insert lookup Remove Tree structure and convert sorted list directly to the list with the required order. Fix work with 8.0.2 * Add insert.insert test, fix CI
- Loading branch information
Showing
4 changed files
with
107 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE KindSignatures #-} | ||
{-# LANGUAGE PolyKinds #-} | ||
|
||
{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-} | ||
|
||
module Test.TypeRep.MapProperty where | ||
|
||
import Prelude hiding (lookup) | ||
|
||
import Data.Proxy (Proxy (..)) | ||
import GHC.Stack (HasCallStack) | ||
import GHC.TypeLits (Nat, SomeNat (..), someNatVal) | ||
import Hedgehog (MonadGen, PropertyT, forAll, property, (===)) | ||
import Test.Tasty (TestName, TestTree) | ||
import Test.Tasty.Hedgehog (testProperty) | ||
|
||
import Data.TypeRep.CacheMap (TF (..), TypeRepMap, fromList, insert, lookup) | ||
|
||
import qualified Hedgehog.Gen as Gen | ||
import qualified Hedgehog.Range as Range | ||
|
||
type PropertyTest = [TestTree] | ||
|
||
prop :: HasCallStack => TestName -> PropertyT IO () -> PropertyTest | ||
prop testName = pure . testProperty testName . property | ||
|
||
test_InsertLookup :: PropertyTest | ||
test_InsertLookup = prop "lookup k (insert k v m) == Just v" $ do | ||
m <- forAll genMap | ||
TF (proxy :: IntProxy n) <- forAll genTF | ||
|
||
lookup @n @IntProxy (insert proxy m) === Just proxy | ||
|
||
test_InsertInsert :: PropertyTest | ||
test_InsertInsert = prop "insert k b . insert k a == insert k b" $ do | ||
m <- forAll genMap | ||
TF a@(IntProxy (proxy :: Proxy n) i) <- forAll genTF | ||
let b = IntProxy proxy (i + 1) | ||
lookup @n @IntProxy (insert b $ insert a m) === Just b | ||
|
||
|
||
---------------------------------------------------------------------------- | ||
-- Generators | ||
---------------------------------------------------------------------------- | ||
|
||
data IntProxy (n :: Nat) = IntProxy (Proxy n) Int | ||
deriving (Show, Eq) | ||
|
||
|
||
genMap :: MonadGen m => m (TypeRepMap IntProxy) | ||
genMap = fromList <$> Gen.list (Range.linear 0 1000) genTF | ||
|
||
|
||
genTF :: MonadGen m => m (TF IntProxy) | ||
genTF = do | ||
randNat :: Integer <- Gen.integral (Range.linear 0 10000) | ||
randInt <- Gen.int Range.constantBounded | ||
case someNatVal randNat of | ||
Just (SomeNat proxyNat) -> pure $ TF $ IntProxy proxyNat randInt | ||
Nothing -> error "Invalid test generator" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters