1
1
mirror of https://github.com/github/semantic.git synced 2024-12-29 18:06:14 +03:00

Test against a set of children instead of sorting.

This reverts commit e5fb9a7a89da22373e7614d0163b64bb3a994b24.
This commit is contained in:
Rob Rix 2016-06-29 11:28:08 -04:00
parent 7bdbb0a963
commit 27cc162e1c

View File

@ -5,6 +5,7 @@ import Category
import Data.DList as DList hiding (toList)
import Data.RandomWalkSimilarity
import Data.RandomWalkSimilarity.Arbitrary ()
import qualified Data.Set as Set
import Diff
import Patch
import Prologue
@ -30,10 +31,11 @@ spec = parallel $ do
describe "rws" $ do
let compare a b = if extract a == extract b then Just (pure (Replace a b)) else Nothing
let enumerate = zipWith (\ i t -> fmap ((,) i) t) [0..]
let sort term = let annotation :< (Indexed children) = runCofree term in cofree (annotation :< Indexed (sortOn (fst . extract) children))
prop "produces correct diffs" $
\ as bs -> let tas = enumerate $ toTerm <$> as
tbs = enumerate $ toTerm <$> bs
diff = free (Free (pure (0, Program) :< Indexed (rws compare snd tas tbs :: [Diff Text (Integer, Category)]))) in
(sort <$> beforeTerm diff, sort <$> afterTerm diff) `shouldBe` (Just (cofree ((0, Program) :< Indexed tas)), Just (cofree ((0, Program) :< Indexed tbs)))
\ as bs -> let tas = toTerm <$> as
tbs = toTerm <$> bs
diff = free (Free (pure Program :< Indexed (rws compare identity tas tbs :: [Diff Text Category]))) in
(childrenOf <$> beforeTerm diff, childrenOf <$> afterTerm diff) `shouldBe` (Just (Set.fromList tas), Just (Set.fromList tbs))
childrenOf :: (Ord leaf, Ord annotation) => Term leaf annotation -> Set.Set (Term leaf annotation)
childrenOf term = let Indexed children = unwrap term in Set.fromList children