@@ -0,0 +1,83 @@
1+{-# Language TypeSynonymInstances,FlexibleInstances,OverloadedStrings #-}
2+module ProjectM36.MyTest where
3+import ProjectM36.Base
4+import Test.QuickCheck
5+import Test.QuickCheck.Gen
6+import Test.QuickCheck.Random
7+import Test.QuickCheck.Arbitrary.ADT
8+import qualified Data.Text as T
9+import qualified Data.ByteString.Char8 as B
10+import Data.Time
11+import Data.Time.Clock
12+import qualified Data.Vector as V
13+import qualified Data.Map as M
14+
15+{-
16+instance Arbitrary Atom where
17+ arbitrary = IntAtom <$> int
18+ where int = (arbitrary :: Gen Int)
19+
20+genAtom :: IO Atom
21+genAtom = do
22+ seed <- newQCGen
23+ return $ unGen (arbitrary :: Gen Atom) seed (2^29-1)
24+-}
25+
26+instance Arbitrary T.Text where
27+ arbitrary = T.pack <$> elements ["Mary", "Johnny", "Sunny", "Ted"] --(arbitrary :: Gen String)
28+
29+instance Arbitrary Day where
30+ arbitrary = ModifiedJulianDay <$> (arbitrary :: Gen Integer)
31+
32+instance Arbitrary Attribute where
33+ arbitrary = genericArbitrary
34+
35+instance (Arbitrary a) => Arbitrary (V.Vector a) where
36+ arbitrary = do
37+ maxbound <- choose (0,5)
38+ V.fromList <$> vectorOf maxbound arbitrary
39+
40+instance {-# OVERLAPPING #-} Arbitrary TypeVarMap where
41+ arbitrary = undefined
42+
43+instance Arbitrary UTCTime where
44+ arbitrary = UTCTime <$> arbitrary <*> (secondsToDiffTime <$> arbitrary)
45+
46+instance Arbitrary B.ByteString where
47+ arbitrary = B.pack <$> (arbitrary :: Gen String)
48+
49+-- arbitrary attributes seems to involve dependant-type techniques and seems unneccsary for a dud example.
50+attributeNames = ["Number","People","Time","Thing"]
51+atomtypes = [IntAtomType, TextAtomType, DayAtomType, TextAtomType]
52+attributes = V.fromList $ zipWith Attribute attributeNames atomtypes
53+
54+instance Arbitrary RelationTuple where
55+ arbitrary = do
56+ a <- IntAtom <$> (arbitrary :: Gen Int)
57+ b <- TextAtom <$> (arbitrary :: Gen T.Text)
58+ c <- DayAtom <$> (arbitrary :: Gen Day)
59+ d <- TextAtom <$> (arbitrary :: Gen T.Text)
60+ let sample = V.fromList [a,b,c,d]
61+ return $ RelationTuple attributes sample
62+
63+instance Arbitrary Relation where
64+ arbitrary = do
65+ list <- listOf (arbitrary :: Gen RelationTuple)
66+ return $ Relation attributes (RelationTupleSet list)
67+
68+
69+instance Arbitrary AtomType where
70+ arbitrary = genericArbitrary
71+
72+instance Arbitrary Atom where
73+ arbitrary = genericArbitrary
74+
75+instance ToADTArbitrary Atom
76+
77+
78+--three parts
79+-- s# generation
80+-- expr -> Relation
81+-- keyword arbitrary
82+-- database context: seed + expr
83+--