@@ -1,4 +1,4 @@
1−{-# LANGUAGE ExistentialQuantification,DeriveGeneric,DeriveAnyClass,TypeSynonymInstances,FlexibleInstances,OverloadedStrings #-}
1+{-# LANGUAGE ExistentialQuantification,FlexibleInstances,OverloadedStrings #-}
22{-# OPTIONS_GHC -fno-warn-orphans #-}
33
44module ProjectM36.Arbitrary where
@@ -7,27 +7,16 @@ import ProjectM36.Error
77import ProjectM36.AtomType
88import ProjectM36.Attribute (atomType,attributeName)
99import ProjectM36.DataConstructorDef as DCD
10−import qualified Data.Map as M
11−import qualified Data.Set as S
1210import qualified Data.Vector as V
13−import qualified Data.List as L
14−import Data.Text (Text,unpack,pack)
11+import Data.Text (Text,pack)
1512import Test.QuickCheck
16−import Test.QuickCheck.Gen
17−import Test.QuickCheck.Random
18−import Test.QuickCheck.Arbitrary
1913import qualified Data.ByteString.Char8 as B
2014import Data.Time
21−import Data.Time.Clock
22−import Debug.Trace
2315import Control.Monad.Reader
24−import Data.Either
25−import Data.Either.Combinators
2616
2717arbitrary' :: AtomType -> WithTCMap Gen (Either RelationalError Atom)
28−arbitrary' IntegerAtomType = do
29− i <- lift (arbitrary :: Gen Integer)
30− pure $ Right $ IntegerAtom i
18+arbitrary' IntegerAtomType =
19+ Right . IntegerAtom <$> lift (arbitrary :: Gen Integer)
3120
3221arbitrary' (RelationAtomType attrs) = do
3322 tcMap <-ask
@@ -36,29 +25,26 @@ arbitrary' (RelationAtomType attrs) = do
3625 Left err -> pure $ Left err
3726 Right rel -> pure $ Right $ RelationAtom rel
3827
39−arbitrary' IntAtomType = do
40− i <- lift (arbitrary :: Gen Int)
41− pure $ Right $ IntAtom i
28+arbitrary' IntAtomType =
29+ Right . IntAtom <$> lift (arbitrary :: Gen Int)
4230
43−arbitrary' DoubleAtomType = do
44− i <- lift (arbitrary :: Gen Double)
45− pure $ Right $ DoubleAtom i
31+arbitrary' DoubleAtomType =
32+ Right . DoubleAtom <$> lift (arbitrary :: Gen Double)
4633
47−arbitrary' TextAtomType = do
48− i <- lift (arbitrary :: Gen Text)
49− pure $ Right $ TextAtom i
34+arbitrary' TextAtomType =
35+ Right . TextAtom <$> lift (arbitrary :: Gen Text)
5036
51−arbitrary' DayAtomType = do
52− i <- lift (arbitrary :: Gen Day)
53− pure $ Right $ DayAtom i
37+arbitrary' DayAtomType =
38+ Right . DayAtom <$> lift (arbitrary :: Gen Day)
5439
55−arbitrary' DateTimeAtomType = do
56− i <- lift (arbitrary :: Gen UTCTime)
57− pure $ Right $ DateTimeAtom i
40+arbitrary' DateTimeAtomType =
41+ Right . DateTimeAtom <$> lift (arbitrary :: Gen UTCTime)
42+
43+arbitrary' ByteStringAtomType =
44+ Right . ByteStringAtom <$> lift (arbitrary :: Gen B.ByteString)
5845
59−arbitrary' BoolAtomType = do
60− i <- lift (arbitrary :: Gen Bool)
61− pure $ Right $ BoolAtom i
46+arbitrary' BoolAtomType =
47+ Right . BoolAtom <$> lift (arbitrary :: Gen Bool)
6248
6349arbitrary' (IntervalAtomType atomTy) = do
6450 tcMap <- ask
@@ -81,7 +67,7 @@ arbitrary' constructedAtomType@(ConstructedAtomType tcName tvMap) = do
8167 case eitherGenDCDef of
8268 Left err -> pure $ Left err
8369 Right genDCDef -> do
84− dcDef <- lift $ genDCDef
70+ dcDef <- lift genDCDef
8571 case resolvedAtomTypesForDataConstructorDefArgs tcMap tvMap dcDef of
8672 Left err -> pure $ Left err
8773 Right atomTypes -> do
@@ -91,7 +77,7 @@ arbitrary' constructedAtomType@(ConstructedAtomType tcName tvMap) = do
9177 case eitherListOfAtom of
9278 Left err -> pure $ Left err
9379 Right listOfAtom -> pure $ Right $ ConstructedAtom (DCD.name dcDef) constructedAtomType listOfAtom
94−arbitrary' (TypeVariableType tvName) = undefined
80+arbitrary' (TypeVariableType _) = error "arbitrary on type variable"
9581
9682maybeToRight :: b -> Maybe a -> Either b a
9783maybeToRight _ (Just x) = Right x
@@ -112,7 +98,7 @@ instance Arbitrary B.ByteString where
11298arbitraryRelationTuple :: Attributes -> WithTCMap Gen (Either RelationalError RelationTuple)
11399arbitraryRelationTuple attris = do
114100 tcMap <- ask
115− listOfMaybeAType <- lift $ sequence $ map ((\aTy -> runReaderT (arbitrary' aTy) tcMap) . atomType) (V.toList attris)
101+ listOfMaybeAType <- lift $ mapM ((\aTy -> runReaderT (arbitrary' aTy) tcMap) . atomType) (V.toList attris)
116102 case sequence listOfMaybeAType of
117103 Left err -> pure $ Left err
118104 Right listOfAttr -> do