1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 23:42:31 +03:00
semantic/test/Diffing/Algorithm/SES/Spec.hs

25 lines
989 B
Haskell
Raw Normal View History

2018-12-01 03:23:29 +03:00
module Diffing.Algorithm.SES.Spec (spec) where
2017-03-20 18:25:58 +03:00
import Data.These
2017-11-27 19:48:39 +03:00
import Diffing.Algorithm.SES
2017-03-20 18:25:58 +03:00
import Test.Hspec
import Test.Hspec.LeanCheck
2017-03-20 18:25:58 +03:00
spec :: Spec
spec = do
describe "ses" $ do
prop "returns equal lists in These" $
2019-10-17 20:44:51 +03:00
\ as -> (ses (==) as as :: [Edit Char Char]) `shouldBe` zipWith These as as
prop "returns deletions in This" $
2019-10-17 20:44:51 +03:00
\ as -> (ses (==) as [] :: [Edit Char Char]) `shouldBe` fmap This as
prop "returns insertions in That" $
2019-10-17 20:44:51 +03:00
\ bs -> (ses (==) [] bs :: [Edit Char Char]) `shouldBe` fmap That bs
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
prop "is lossless w.r.t. both input elements & ordering" $
2019-10-17 20:44:51 +03:00
\ as bs -> foldr (\ each (as, bs) -> these (flip (,) bs. (:as)) ((,) as . (:bs)) (\ a b -> (a:as, b:bs)) each) ([], []) (ses (==) as bs :: [Edit Char Char]) `shouldBe` (as, bs)