2016-06-27 20:15:03 +03:00
|
|
|
{-# LANGUAGE DataKinds #-}
|
2016-06-27 20:12:06 +03:00
|
|
|
module Diff.Spec where
|
|
|
|
|
2016-06-27 20:15:03 +03:00
|
|
|
import Category
|
2016-08-10 16:21:58 +03:00
|
|
|
import Data.RandomWalkSimilarity
|
2016-06-27 20:15:03 +03:00
|
|
|
import Data.Record
|
2016-06-27 20:16:48 +03:00
|
|
|
import Data.Text.Arbitrary ()
|
2016-06-27 20:12:06 +03:00
|
|
|
import Diff
|
2016-06-27 20:15:03 +03:00
|
|
|
import Diff.Arbitrary
|
2016-10-13 02:19:36 +03:00
|
|
|
import Diffing (getLabel)
|
2016-08-10 16:21:58 +03:00
|
|
|
import Info
|
2016-06-27 20:15:03 +03:00
|
|
|
import Interpreter
|
2016-06-27 20:12:06 +03:00
|
|
|
import Prologue
|
2016-06-27 20:15:03 +03:00
|
|
|
import Term.Arbitrary
|
2016-06-27 20:12:06 +03:00
|
|
|
import Test.Hspec
|
2016-06-27 20:15:03 +03:00
|
|
|
import Test.Hspec.QuickCheck
|
|
|
|
import Test.QuickCheck
|
2016-06-27 20:12:06 +03:00
|
|
|
|
|
|
|
spec :: Spec
|
|
|
|
spec = parallel $ do
|
2016-08-18 21:03:36 +03:00
|
|
|
let toTerm' = defaultFeatureVectorDecorator (category . headF) . toTerm
|
2016-06-27 20:18:20 +03:00
|
|
|
prop "equality is reflexive" $
|
2016-10-13 02:19:36 +03:00
|
|
|
\ a b -> let diff = diffTerms wrap (==) diffCost getLabel (toTerm' a) (toTerm' (b :: ArbitraryTerm Text (Record '[Category]))) in
|
2016-06-27 20:21:32 +03:00
|
|
|
diff `shouldBe` diff
|
2016-06-27 20:18:20 +03:00
|
|
|
|
2016-07-13 00:29:47 +03:00
|
|
|
prop "equal terms produce identity diffs" $
|
2016-08-10 16:21:58 +03:00
|
|
|
\ a -> let term = toTerm' (a :: ArbitraryTerm Text (Record '[Category])) in
|
2016-10-13 02:19:36 +03:00
|
|
|
diffCost (diffTerms wrap (==) diffCost getLabel term term) `shouldBe` 0
|
2016-06-27 20:18:20 +03:00
|
|
|
|
2016-06-27 20:23:43 +03:00
|
|
|
describe "beforeTerm" $ do
|
|
|
|
prop "recovers the before term" $
|
2016-10-13 02:19:36 +03:00
|
|
|
\ a b -> let diff = diffTerms wrap (==) diffCost getLabel (toTerm' a) (toTerm' (b :: ArbitraryTerm Text (Record '[Category]))) in
|
2016-08-10 16:21:58 +03:00
|
|
|
beforeTerm diff `shouldBe` Just (toTerm' a)
|
2016-06-27 20:15:03 +03:00
|
|
|
|
2016-06-27 20:24:50 +03:00
|
|
|
describe "afterTerm" $ do
|
|
|
|
prop "recovers the after term" $
|
2016-10-13 02:19:36 +03:00
|
|
|
\ a b -> let diff = diffTerms wrap (==) diffCost getLabel (toTerm' a) (toTerm' (b :: ArbitraryTerm Text (Record '[Category]))) in
|
2016-08-10 16:21:58 +03:00
|
|
|
afterTerm diff `shouldBe` Just (toTerm' b)
|
2016-06-27 20:24:50 +03:00
|
|
|
|
2016-06-27 20:15:03 +03:00
|
|
|
describe "ArbitraryDiff" $ do
|
|
|
|
prop "generates diffs of a specific size" . forAll ((arbitrary >>= \ n -> (,) n <$> diffOfSize n) `suchThat` ((> 0) . fst)) $
|
2016-06-27 20:16:48 +03:00
|
|
|
\ (n, diff) -> arbitraryDiffSize (diff :: ArbitraryDiff Text ()) `shouldBe` n
|