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
|
|
|
|
import Data.Record
|
|
|
|
import Data.Record.Arbitrary ()
|
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
|
|
|
|
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
|
|
|
|
describe "mergeMaybe" $ do
|
|
|
|
it "is symmetrical" $ pending
|
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
|
2016-06-27 20:15:03 +03:00
|
|
|
|
|
|
|
describe "Diff" $ do
|
|
|
|
prop "equality is reflexive" $
|
2016-06-27 20:16:48 +03:00
|
|
|
\ a b -> let diff = diffTerms (free . Free) (==) diffCost (toTerm a) (toTerm (b :: ArbitraryTerm Text (Record '[Category]))) in
|
2016-06-27 20:15:03 +03:00
|
|
|
diff == diff
|
|
|
|
|
|
|
|
prop "equal terms produce identity diffs" $
|
2016-06-27 20:16:48 +03:00
|
|
|
\ a -> let term = toTerm (a :: ArbitraryTerm Text (Record '[Category])) in
|
2016-06-27 20:15:03 +03:00
|
|
|
diffCost (diffTerms (free . Free) (==) diffCost term term) == 0
|