1
1
mirror of https://github.com/github/semantic.git synced 2024-12-21 13:51:44 +03:00
semantic/test/Diff/Spec.hs

42 lines
1.5 KiB
Haskell
Raw Normal View History

{-# LANGUAGE DataKinds #-}
2016-06-27 20:12:06 +03:00
module Diff.Spec where
import Category
import Data.RandomWalkSimilarity
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
import Diff.Arbitrary
import Info
import Interpreter
2016-06-27 20:12:06 +03:00
import Prologue
import Term.Arbitrary
2016-06-27 20:12:06 +03:00
import Test.Hspec
import Test.Hspec.QuickCheck
import Test.QuickCheck
2016-06-27 20:12:06 +03:00
spec :: Spec
spec = parallel $ do
let toTerm' = featureVectorDecorator (category . headF) 2 2 15 . toTerm
2016-06-27 20:18:20 +03:00
prop "equality is reflexive" $
\ a b -> let diff = diffTerms wrap (==) diffCost (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
prop "equal terms produce identity diffs" $
\ a -> let term = toTerm' (a :: ArbitraryTerm Text (Record '[Category])) in
2016-07-13 00:19:44 +03:00
diffCost (diffTerms wrap (==) diffCost term term) `shouldBe` 0
2016-06-27 20:18:20 +03:00
describe "beforeTerm" $ do
prop "recovers the before term" $
\ a b -> let diff = diffTerms wrap (==) diffCost (toTerm' a) (toTerm' (b :: ArbitraryTerm Text (Record '[Category]))) in
beforeTerm diff `shouldBe` Just (toTerm' a)
describe "afterTerm" $ do
prop "recovers the after term" $
\ a b -> let diff = diffTerms wrap (==) diffCost (toTerm' a) (toTerm' (b :: ArbitraryTerm Text (Record '[Category]))) in
afterTerm diff `shouldBe` Just (toTerm' b)
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