File: NatRepr.hs

package info (click to toggle)
haskell-parameterized-utils 2.1.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 564 kB
  • sloc: haskell: 7,887; makefile: 6
file content (27 lines) | stat: -rw-r--r-- 761 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{-# LANGUAGE OverloadedStrings #-}
module Test.NatRepr
  ( natTests
  )
where

import           Hedgehog
import qualified Hedgehog.Gen as HG
import           Hedgehog.Range
import           Test.Tasty
import           Test.Tasty.Hedgehog

import           Data.Parameterized.NatRepr
import           Data.Parameterized.Some
import           GHC.TypeLits (natVal)

prop_withKnownNat :: Property
prop_withKnownNat = property $
  do nInt <- forAll $ HG.int (linearBounded :: Range Int)
     case someNat nInt of
       Nothing       -> diff nInt (<) 0
       Just (Some r) -> nInt === withKnownNat r (fromEnum $ natVal r)

natTests :: IO TestTree
natTests = testGroup "Nat" <$> return
  [ testPropertyNamed "withKnownNat" "prop_withKnownNat" prop_withKnownNat
  ]