Skip to content

Commit 65e05f3

Browse files
committed
ES: now QC only generates semantically correct programs for conversion
1 parent d9ba215 commit 65e05f3

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

grin/src/Test/ExtendedSyntax/Old/Test.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{-# LANGUAGE DeriveGeneric, LambdaCase, TypeApplications, StandaloneDeriving, RankNTypes #-}
2-
{-# LANGUAGE QuasiQuotes, ViewPatterns, OverloadedStrings #-}
2+
{-# LANGUAGE QuasiQuotes, ViewPatterns, OverloadedStrings, GeneralizedNewtypeDeriving #-}
33
module Test.ExtendedSyntax.Old.Test where
44

55
import Prelude hiding (GT)
@@ -41,6 +41,7 @@ import Data.List
4141

4242
import Debug.Trace
4343
import Data.Text (pack)
44+
import Grin.Pretty (Pretty(..))
4445
import Grin.ExtendedSyntax.Pretty (PP(..))
4546
import Grin.TH
4647
import Grin.ExtendedSyntax.TypeEnv (TypeEnv, emptyTypeEnv) -- NOTE: might become problematic later
@@ -941,3 +942,10 @@ instance Solve G.Prog where
941942

942943
changed :: (Testable prop) => Exp -> Exp -> prop -> Property
943944
changed old new = cover (old /= new) 1 "Transformation has effect"
945+
946+
947+
newtype SemanticallyCorrectProgram = SC { correctProg :: Exp }
948+
deriving (Eq, Ord, Show, Pretty)
949+
950+
instance Arbitrary SemanticallyCorrectProgram where
951+
arbitrary = SC <$> genProg

grin/test/Transformations/ExtendedSyntax/ConversionSpec.hs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import Test.QuickCheck
1212
import Test.Hspec.QuickCheck
1313

1414
import Test.Assertions
15-
import Test.ExtendedSyntax.Old.Test()
16-
import qualified Test.ExtendedSyntax.Old.Grammar as G
15+
import Test.ExtendedSyntax.Old.Test (SemanticallyCorrectProgram(..))
1716

1817
runTests :: IO ()
1918
runTests = hspec spec
@@ -28,11 +27,11 @@ spec = describe "Syntax transformation QuickCheck tests" $ do
2827
-- NOTE: The conversion itself is the proof that it is convertible
2928
-- QUESTION: There must be a better way to do this
3029
-- ANSWER: The conversion function could an Either
31-
convertibleToNew :: G.Exp -> Bool
32-
convertibleToNew exp = force (convertToNew $ G.asExp exp) `seq` True
30+
convertibleToNew :: SemanticallyCorrectProgram -> Bool
31+
convertibleToNew exp = force (convertToNew $ correctProg exp) `seq` True
3332

34-
roundtripConvertibleOld :: G.Exp -> Bool
35-
roundtripConvertibleOld exp = force (convertToOld $ convertToNew $ G.asExp exp) `seq` True where
33+
roundtripConvertibleOld :: SemanticallyCorrectProgram -> Bool
34+
roundtripConvertibleOld exp = force (convertToOld $ convertToNew $ correctProg exp) `seq` True where
3635

3736
convertToOld :: New.Exp -> Exp
3837
convertToOld = convert

0 commit comments

Comments
 (0)