Skip to content

Commit 380e322

Browse files
committed
update: add arbitrary for kind
1 parent 626b270 commit 380e322

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck/Kind.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
module LambdaBuffers.Compiler.KindCheck.Kind (Kind (KType, (:->:), KVar), kind2ProtoKind, protoKind2Kind) where
22

3+
import GHC.Generics (Generic)
34
import LambdaBuffers.Compiler.KindCheck.Variable (Atom)
45
import LambdaBuffers.Compiler.ProtoCompat.Types qualified as PC
56
import Prettyprinter (Pretty (pretty), parens, (<+>))
7+
import Test.QuickCheck.Arbitrary.Generic (Arbitrary, GenericArbitrary (GenericArbitrary))
68

79
infixr 8 :->:
810

911
data Kind
1012
= KType
1113
| Kind :->: Kind
1214
| KVar Atom
13-
deriving stock (Eq, Show)
15+
deriving stock (Eq, Show, Generic)
16+
deriving (Arbitrary) via GenericArbitrary Kind
1417

1518
instance Pretty Kind where
1619
pretty = \case

lambda-buffers-compiler/test/Test/KindCheck.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import LambdaBuffers.Compiler.KindCheck (
99

1010
import LambdaBuffers.Compiler.KindCheck.Kind (Kind (KType, (:->:)))
1111
import Test.KindCheck.Errors (testGKindCheckErrors)
12+
import Test.QuickCheck (Arbitrary (arbitrary), forAll, (===))
1213
import Test.Tasty (TestTree, testGroup)
1314
import Test.Tasty.HUnit (assertBool, testCase, (@?=))
15+
import Test.Tasty.QuickCheck (testProperty)
1416
import Test.Utils.CompilerInput (
1517
compilerInput'incoherent,
1618
compilerInput'maybe,
@@ -61,7 +63,7 @@ testFolds =
6163
"Test Folds"
6264
[ testGroup
6365
"Test Arrow Folds"
64-
[testArrowFold0, testArrowFold1, testArrowFold2, testArrowFold3HK, testArrowFold4HK, testArrowFoldHHK]
66+
[testArrowFold0, testArrowFold1, testArrowFold2, testArrowFold3HK, testArrowFold4HK, testArrowFoldHHK, testFoldWithArrowToTypeTotal]
6567
]
6668

6769
{-
@@ -175,3 +177,9 @@ testArrowFoldHHK =
175177
testCase "Fold 2 HKT" $
176178
foldWithArrowToType [ty, (ty :->: ty) :->: ty, ty]
177179
@?= (ty :->: (((ty :->: ty) :->: ty) :->: (ty :->: ty)))
180+
181+
testFoldWithArrowToTypeTotal :: TestTree
182+
testFoldWithArrowToTypeTotal =
183+
testProperty "foldWithArrowToType is total" $
184+
forAll arbitrary $
185+
\ts -> foldWithArrowToType ts === foldWithArrowToType ts

0 commit comments

Comments
 (0)