switch to rangeN.

This commit is contained in:
Kei Hibino 2016-12-19 18:15:49 +09:00
parent 9d444c89ad
commit 9ec6c3726b

View File

@ -85,12 +85,15 @@ newtype D a =
D { unD :: a } D { unD :: a }
deriving Show deriving Show
rangeN :: (Num a, Enum a) => a -> Gen a
rangeN n = elements [-n .. n]
genVarExpr :: Gen (Selector a) -> Gen (VarExpr a) genVarExpr :: Gen (Selector a) -> Gen (VarExpr a)
genVarExpr gs = genVarExpr gs =
frequency frequency
[ (3, Column <$> gs) [ (3, Column <$> gs)
, (1, VLeft <$> rec' <*> arbitrary <*> elements [-10 .. 10]) , (1, VLeft <$> rec' <*> arbitrary <*> rangeN 5)
, (1, VRight <$> elements [-10 .. 10] <*> arbitrary <*> rec') , (1, VRight <$> rangeN 5 <*> arbitrary <*> rec')
] ]
where where
rec' = genVarExpr gs rec' = genVarExpr gs
@ -236,21 +239,18 @@ predHask r = d where
newtype Ranged a = Ranged { runRanged :: [a] } newtype Ranged a = Ranged { runRanged :: [a] }
deriving (Eq, Show) deriving (Eq, Show)
range5 :: (Num a, Enum a) => Gen a
range5 = elements [-5 .. 5]
instance Arbitrary (Ranged A) where instance Arbitrary (Ranged A) where
arbitrary = arbitrary =
(Ranged <$>) . listOf $ (Ranged <$>) . listOf $
A A
<$> range5 <$> rangeN 5
<*> range5 <*> rangeN 5
<*> range5 <*> rangeN 5
instance Arbitrary (Ranged B) where instance Arbitrary (Ranged B) where
arbitrary = arbitrary =
(Ranged <$>) . listOf $ (Ranged <$>) . listOf $
B B
<$> range5 <$> rangeN 5
<*> range5 <*> rangeN 5
<*> range5 <*> rangeN 5