2018-12-01 03:23:29 +03:00
|
|
|
module Diffing.Algorithm.SES.Spec (spec) where
|
2017-03-20 18:25:58 +03:00
|
|
|
|
2019-10-18 05:53:35 +03:00
|
|
|
import Data.Edit
|
2017-11-27 19:48:39 +03:00
|
|
|
import Diffing.Algorithm.SES
|
2017-03-20 18:25:58 +03:00
|
|
|
import Test.Hspec
|
2017-03-20 18:29:16 +03:00
|
|
|
import Test.Hspec.LeanCheck
|
2017-03-20 18:25:58 +03:00
|
|
|
|
|
|
|
spec :: Spec
|
2017-03-20 18:29:16 +03:00
|
|
|
spec = do
|
|
|
|
describe "ses" $ do
|
2019-10-18 18:26:50 +03:00
|
|
|
prop "returns equal lists in Compare" $
|
2019-10-18 05:44:57 +03:00
|
|
|
\ as -> (ses (==) as as :: [Edit Char Char]) `shouldBe` zipWith Compare as as
|
2017-03-20 18:31:06 +03:00
|
|
|
|
2019-10-18 18:26:50 +03:00
|
|
|
prop "returns deletions in Delete" $
|
2019-10-18 02:31:46 +03:00
|
|
|
\ as -> (ses (==) as [] :: [Edit Char Char]) `shouldBe` fmap Delete as
|
2017-03-20 18:32:03 +03:00
|
|
|
|
2019-10-18 18:26:50 +03:00
|
|
|
prop "returns insertions in Insert" $
|
2019-10-18 02:31:46 +03:00
|
|
|
\ bs -> (ses (==) [] bs :: [Edit Char Char]) `shouldBe` fmap Insert bs
|
2017-03-22 22:38:57 +03:00
|
|
|
|
2017-03-23 00:20:37 +03:00
|
|
|
prop "returns all elements individually for disjoint inputs" $
|
2017-03-23 20:28:40 +03:00
|
|
|
\ as bs -> length (ses (==) ((,) 0 <$> as :: [(Int, Char)]) ((,) 1 <$> bs :: [(Int, Char)])) `shouldBe` length as + length bs
|
2017-03-23 00:26:05 +03:00
|
|
|
|
|
|
|
prop "is lossless w.r.t. both input elements & ordering" $
|
2019-10-18 05:53:35 +03:00
|
|
|
\ as bs -> foldr (\ each (as, bs) -> edit (flip (,) bs. (:as)) ((,) as . (:bs)) (\ a b -> (a:as, b:bs)) each) ([], []) (ses (==) as bs :: [Edit Char Char]) `shouldBe` (as, bs)
|