on master help sign in
better shrinking and not-infinite-dump generation results in passed tests!
commit853e63c91831eb56fbc1559b27ce1574aadd2d18 authorJohn P Mayer Jr <john.p.mayer.jr@gmail.com> dateWed 15 Jan 2014, 01:39 (13 years ago) parentbb3e4ca
2 files changed+20−14
compiler/SourceSyntax/Type.hs+1−1 tests/Tests/Property/Arbitrary.hs+19−13
compiler/SourceSyntax/Type.hs+1−1
@@ -33,7 +33,7 @@ instance Show Type where
3333instance Pretty Type where
3434 pretty tipe =
3535 case tipe of
36− Lambda _ _ -> P.sep [ t, P.sep (map (P.text "->" <+>) ts) ]
36+ Lambda _ _ -> P.hsep [ t, P.hsep (map (P.text "->" <+>) ts) ]
3737 where
3838 t:ts = map prettyLambda (collectLambdas tipe)
3939 prettyLambda t = case t of
tests/Tests/Property/Arbitrary.hs+19−13
@@ -44,8 +44,8 @@ instance Arbitrary Pattern where
4444 ]
4545 where sizedPats = do
4646 len <- choose (0,n)
47− let m = n `div` len in
48− vectorOf len $ pat m
47+ let m = n `div` (len + 1)
48+ vectorOf len $ pat m
4949
5050 shrink pat = case pat of
5151 PAnything -> []
@@ -64,22 +64,28 @@ instance Arbitrary Type where
6464 where tipe :: Int -> Gen Type
6565 tipe n = oneof [ Lambda <$> depthTipe <*> depthTipe
6666 , Var <$> lowVar
67− --, Data <$> capVar <*> listOf depthTipe
68− --, Record <$> listOf1 field <*> (Just <$> lowVar)
69− --, Record <$> listOf field <*> pure Nothing
67+ , Data <$> capVar <*> depthTipes
68+ , Record <$> fields <*> pure Nothing
69+ , Record <$> fields1 <*> (Just <$> lowVar)
7070 ]
71− where depthTipe :: Gen Type
72− depthTipe = do
73− m <- choose (0,n)
74− tipe m
75− field :: Gen (String, Type)
71+ where depthTipe = choose (0,n) >>= tipe
72+ depthTipes = do
73+ len <- choose (0,n)
74+ let m = n `div` (len + 1)
75+ vectorOf len $ tipe m
76+
7677 field = (,) <$> lowVar <*> depthTipe
77−
78+ fields = do
79+ len <- choose (0,n)
80+ let m = n `div` (len + 1)
81+ vectorOf len $ (,) <$> lowVar <*> tipe m
82+ fields1 = (:) <$> field <*> fields
83+
7884 shrink tipe = case tipe of
7985 Lambda s t -> s : t : (Lambda <$> shrink s <*> shrink t)
8086 Var _ -> []
81− Data n ts -> Data <$> shrinkWHead n <*> shrink ts
82− Record fs t -> case t of
87+ Data n ts -> ts ++ (Data <$> shrinkWHead n <*> shrink ts)
88+ Record fs t -> map snd fs ++ case t of
8389 Nothing -> Record <$> shrinkList shrinkField fs <*> pure Nothing
8490 Just _ ->
8591 do