2016-06-27 22:28:11 +03:00
|
|
|
{-# LANGUAGE DataKinds #-}
|
2015-12-16 22:18:09 +03:00
|
|
|
module InterpreterSpec where
|
|
|
|
|
2016-06-27 22:28:04 +03:00
|
|
|
import Category
|
2016-08-12 19:16:48 +03:00
|
|
|
import Data.Functor.Foldable
|
2017-01-09 22:20:11 +03:00
|
|
|
import Data.Functor.Listable
|
2016-08-10 16:26:58 +03:00
|
|
|
import Data.RandomWalkSimilarity
|
2016-06-17 20:33:50 +03:00
|
|
|
import Data.Record
|
2017-01-09 22:20:11 +03:00
|
|
|
import Data.String
|
2016-08-10 16:26:58 +03:00
|
|
|
import Diff
|
2016-10-13 02:19:36 +03:00
|
|
|
import Diffing
|
2016-08-10 16:26:58 +03:00
|
|
|
import Info
|
2016-06-27 20:08:12 +03:00
|
|
|
import Interpreter
|
2015-12-16 22:18:09 +03:00
|
|
|
import Patch
|
2016-06-27 22:28:04 +03:00
|
|
|
import Prologue
|
|
|
|
import Syntax
|
2017-01-09 22:20:11 +03:00
|
|
|
import Term
|
2016-09-15 00:45:23 +03:00
|
|
|
import Test.Hspec (Spec, describe, it, parallel)
|
|
|
|
import Test.Hspec.Expectations.Pretty
|
2017-01-09 22:20:11 +03:00
|
|
|
import Test.Hspec.LeanCheck
|
2015-12-16 22:18:09 +03:00
|
|
|
|
|
|
|
spec :: Spec
|
2016-06-27 20:08:12 +03:00
|
|
|
spec = parallel $ do
|
2016-06-27 20:03:58 +03:00
|
|
|
describe "interpret" $ do
|
2016-08-18 21:03:36 +03:00
|
|
|
let decorate = defaultFeatureVectorDecorator (category . headF)
|
2017-01-09 22:20:11 +03:00
|
|
|
let compare = (==) `on` category . extract
|
2015-12-16 22:18:09 +03:00
|
|
|
it "returns a replacement when comparing two unicode equivalent terms" $
|
2017-01-19 23:36:04 +03:00
|
|
|
let termA = cofree $ (StringLiteral .: Nil) :< Leaf ("t\776" :: String)
|
|
|
|
termB = cofree $ (StringLiteral .: Nil) :< Leaf "\7831" in
|
2016-10-13 02:19:36 +03:00
|
|
|
stripDiff (diffTerms wrap compare diffCost getLabel (decorate termA) (decorate termB)) `shouldBe` replacing termA termB
|
2016-06-27 22:28:11 +03:00
|
|
|
|
|
|
|
prop "produces correct diffs" $
|
2017-01-09 22:20:11 +03:00
|
|
|
\ a b -> let diff = stripDiff $ diffTerms wrap compare diffCost getLabel (decorate (unListableF a)) (decorate (unListableF b :: SyntaxTerm String '[Category])) in
|
|
|
|
(beforeTerm diff, afterTerm diff) `shouldBe` (Just (unListableF a), Just (unListableF b))
|
2016-06-30 20:34:31 +03:00
|
|
|
|
|
|
|
prop "constructs zero-cost diffs of equal terms" $
|
2017-01-09 22:20:11 +03:00
|
|
|
\ a -> let term = decorate (unListableF a :: SyntaxTerm String '[Category])
|
2016-10-13 02:19:36 +03:00
|
|
|
diff = diffTerms wrap compare diffCost getLabel term term in
|
2016-06-30 20:34:31 +03:00
|
|
|
diffCost diff `shouldBe` 0
|
2016-08-11 19:23:34 +03:00
|
|
|
|
2016-08-12 19:16:48 +03:00
|
|
|
it "produces unbiased insertions within branches" $
|
2017-01-19 23:36:04 +03:00
|
|
|
let term s = decorate (cofree ((StringLiteral .: Nil) :< Indexed [ cofree ((StringLiteral .: Nil) :< Leaf s) ]))
|
|
|
|
root = cofree . ((pure 0 .: Program .: Nil) :<) . Indexed in
|
|
|
|
stripDiff (diffTerms wrap compare diffCost getLabel (root [ term "b" ]) (root [ term "a", term "b" ])) `shouldBe` wrap (pure (Program .: Nil) :< Indexed [ inserting (stripTerm (term "a")), cata wrap (fmap pure (stripTerm (term "b"))) ])
|