summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LICENSE1
-rw-r--r--Setup.hs2
-rw-r--r--runtime-arbitrary.cabal33
-rw-r--r--src/Test/RuntimeArbitrary.hs16
-rw-r--r--src/Test/TestInstances.hs26
5 files changed, 78 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d5d21ff
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1 @@
+Public Domain
diff --git a/Setup.hs b/Setup.hs
new file mode 100644
index 0000000..9a994af
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/runtime-arbitrary.cabal b/runtime-arbitrary.cabal
new file mode 100644
index 0000000..b272293
--- /dev/null
+++ b/runtime-arbitrary.cabal
@@ -0,0 +1,33 @@
+-- Initial runtime-arbitrary.cabal generated by cabal init. For further
+-- documentation, see http://haskell.org/cabal/users-guide/
+
+name: runtime-arbitrary
+version: 0.1.0.6
+synopsis: Runtime generation of Arbitrary values
+description: Runtime generation of Arbitrary values
+homepage: http://chriswarbo.net/projects/repos/runtime-arbitrary.html
+license: PublicDomain
+license-file: LICENSE
+author: Chris Warburton
+maintainer: chriswarbo@gmail.com
+-- copyright:
+category: Language
+build-type: Simple
+-- extra-source-files:
+cabal-version: >=1.10
+
+source-repository head
+ type: git
+ location: http://chriswarbo.net/git/runtime-arbitrary.git
+
+library
+ exposed-modules: Test.RuntimeArbitrary
+ , Test.TestInstances
+ -- other-modules:
+ -- other-extensions:
+ build-depends: base >=4.7 && < 4.10
+ , QuickCheck
+ , ifcxt
+ , template-haskell
+ hs-source-dirs: src
+ default-language: Haskell2010
diff --git a/src/Test/RuntimeArbitrary.hs b/src/Test/RuntimeArbitrary.hs
new file mode 100644
index 0000000..2e7c1d8
--- /dev/null
+++ b/src/Test/RuntimeArbitrary.hs
@@ -0,0 +1,16 @@
+{-# LANGUAGE RankNTypes, FlexibleInstances, FlexibleContexts, ScopedTypeVariables, ConstraintKinds #-}
+
+module Test.RuntimeArbitrary where
+
+import Data.Typeable
+import IfCxt
+import Test.QuickCheck
+
+getArbGen :: forall proxy a. (Typeable a,
+ IfCxt (Arbitrary a),
+ IfCxt (Ord a)) => proxy a -> [Gen a]
+getArbGen _ = ifCxt (Proxy::Proxy (Arbitrary a))
+ (ifCxt (Proxy::Proxy (Ord a))
+ [arbitrary]
+ [])
+ []
diff --git a/src/Test/TestInstances.hs b/src/Test/TestInstances.hs
new file mode 100644
index 0000000..8c38ab7
--- /dev/null
+++ b/src/Test/TestInstances.hs
@@ -0,0 +1,26 @@
+module Test.TestInstances where
+
+import Data.Typeable
+import Test.QuickCheck
+
+data Foo = AFoo deriving (Show, Eq, Typeable)
+
+instance Ord Foo where
+ compare x y = EQ
+
+instance Arbitrary Foo where
+ arbitrary = return AFoo
+
+data Nat = Z | S Nat deriving (Show, Eq, Typeable)
+
+instance Ord Nat where
+ Z <= y = True
+ S x <= Z = False
+ S x <= S y = x <= y
+
+instance Arbitrary Nat where
+ arbitrary = toNat <$> arbitrary
+
+toNat :: Integer -> Nat
+toNat 0 = Z
+toNat n = S (toNat (abs n - 1))