Skip to content

Commit

Permalink
Additionnal checks for evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Zalewski committed Apr 24, 2020
1 parent 1928e0c commit ea1414d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions field/TinyLang/Field/Generator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -502,5 +502,6 @@ instance (Field f, Arbitrary f) => Arbitrary (ProgramWithEnv f) where
vals <- genEnvFromVarSigs . progFreeVarSigs $ prog
return $ ProgramWithEnv prog vals
shrink (ProgramWithEnv prog (Env vals)) =
-- TODO: Check why is this keeping extra variable bindings in the env
flip map (shrink prog) $ \shrunk ->
ProgramWithEnv shrunk . Env . IntMap.intersection vals . unEnv $ progFreeVarSigs prog
26 changes: 26 additions & 0 deletions test/Field/Textual.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import TinyLang.Field.Rename
import TinyLang.Field.Evaluator

-- import Data.Bifunctor
import qualified Data.IntMap as IntMap
import System.FilePath
import Test.QuickCheck
import Test.Tasty
Expand Down Expand Up @@ -158,10 +159,35 @@ prop_rename_same_norm (ProgramWithEnv prog env) =
norm = either show (progToString NoIDs) $ normProgram env prog
norm' = either show (progToString NoIDs) $ normProgram env prog'

prop_rename_same_eval :: forall f. (Eq f, TextField f, AsInteger f)
=> ProgramWithEnv f -> Either String ()
prop_rename_same_eval (ProgramWithEnv prog env) =
when (result' /= result) . Left $ unlines [ "evaluation of renamed program"
, result'
, "differs from evaluation of original program"
, result
, "for final state of renamed program"
, show eval'
, "for final state of evaluated program"
, show eval
, "for renamed program"
, progToString WithIDs prog'
, "for original program"
, progToString WithIDs prog
] where
prog' = runSupply $ renameProgram prog
eval = evalProgramUni env prog
eval' = evalProgramUni env prog'
evalToS = either show (show . IntMap.elems . unEnv)
result = evalToS eval
result' = evalToS eval'

test_renaming :: TestTree
test_renaming =
testGroup "renaming" [ testProperty "is stable with respect to equality" $
withMaxSuccess 10000 . property $ prop_rename_same @F17
, testProperty "is stable with respect to normalisation" $
withMaxSuccess 1000 . property $ prop_rename_same_norm @F17
, testProperty "is stable with respect to evaluation" $
withMaxSuccess 1000 . property $ prop_rename_same_eval @F17
]

0 comments on commit ea1414d

Please sign in to comment.