2016-08-05 02:19:03 +03:00
|
|
|
{-# LANGUAGE DataKinds #-}
|
2016-06-23 00:59:28 +03:00
|
|
|
module Data.RandomWalkSimilarity.Spec where
|
|
|
|
|
2016-06-28 21:09:51 +03:00
|
|
|
import Category
|
2016-06-23 00:59:28 +03:00
|
|
|
import Data.DList as DList hiding (toList)
|
|
|
|
import Data.RandomWalkSimilarity
|
2016-08-05 02:19:03 +03:00
|
|
|
import Data.Record
|
2016-08-05 17:14:53 +03:00
|
|
|
import qualified Data.Vector.Arbitrary as Vector
|
2016-06-27 22:37:32 +03:00
|
|
|
import Diff
|
|
|
|
import Patch
|
2016-06-23 00:59:28 +03:00
|
|
|
import Prologue
|
2016-06-27 22:37:32 +03:00
|
|
|
import Syntax
|
2016-06-23 00:59:28 +03:00
|
|
|
import Term
|
|
|
|
import Term.Arbitrary
|
|
|
|
import Test.Hspec
|
|
|
|
import Test.Hspec.QuickCheck
|
2016-06-27 18:46:22 +03:00
|
|
|
import Test.QuickCheck
|
2016-06-23 00:59:28 +03:00
|
|
|
|
|
|
|
spec :: Spec
|
|
|
|
spec = parallel $ do
|
2016-08-09 23:23:38 +03:00
|
|
|
describe "pqGramDecorator" $ do
|
2016-06-23 17:11:48 +03:00
|
|
|
prop "produces grams with stems of the specified length" . forAll (arbitrary `suchThat` (\ (_, p, q) -> p > 0 && q > 0)) $
|
2016-08-09 23:23:38 +03:00
|
|
|
\ (term, p, q) -> pqGramDecorator (rhead . headF) p q (toTerm term :: Term Text (Record '[Text])) `shouldSatisfy` all ((== p) . length . stem . rhead)
|
2016-06-23 00:59:28 +03:00
|
|
|
|
2016-08-05 02:48:21 +03:00
|
|
|
prop "produces grams with bases of the specified width" . forAll (arbitrary `suchThat` (\ (_, p, q) -> p > 0 && q > 0)) $
|
2016-08-09 23:23:38 +03:00
|
|
|
\ (term, p, q) -> pqGramDecorator (rhead . headF) p q (toTerm term :: Term Text (Record '[Text])) `shouldSatisfy` all ((== q) . length . base . rhead)
|
2016-06-23 00:59:28 +03:00
|
|
|
|
|
|
|
describe "featureVector" $ do
|
2016-06-27 22:37:32 +03:00
|
|
|
prop "produces a vector of the specified dimension" . forAll (arbitrary `suchThat` ((> 0) . Prologue.snd)) $
|
2016-06-27 22:32:09 +03:00
|
|
|
\ (grams, d) -> length (featureVector d (fromList (grams :: [Gram Text]))) `shouldBe` d
|
2016-06-27 22:37:32 +03:00
|
|
|
|
|
|
|
describe "rws" $ do
|
2016-06-28 22:02:41 +03:00
|
|
|
let compare a b = if extract a == extract b then Just (pure (Replace a b)) else Nothing
|
2016-06-30 19:37:41 +03:00
|
|
|
prop "produces correct diffs" . forAll (scale (`div` 4) arbitrary) $
|
2016-06-30 19:37:27 +03:00
|
|
|
\ (as, bs) -> let tas = toTerm <$> as
|
|
|
|
tbs = toTerm <$> bs
|
2016-08-05 16:08:17 +03:00
|
|
|
diff = free (Free (pure (Program .: Vector.singleton 0 .: RNil) :< Indexed (rws compare tas tbs :: [Diff Text (Record '[Category, Vector.Vector Double])]))) in
|
2016-08-05 04:01:54 +03:00
|
|
|
(beforeTerm diff, afterTerm diff) `shouldBe` (Just (cofree ((Program .: Vector.singleton 0 .: RNil) :< Indexed tas)), Just (cofree ((Program .: Vector.singleton 0 .: RNil) :< Indexed tbs)))
|