2016-06-23 16:52:15 +03:00
|
|
|
{-# LANGUAGE DataKinds #-}
|
2016-06-23 00:59:28 +03:00
|
|
|
module Data.RandomWalkSimilarity.Spec where
|
|
|
|
|
|
|
|
import Data.DList as DList hiding (toList)
|
|
|
|
import Data.RandomWalkSimilarity
|
|
|
|
import Data.RandomWalkSimilarity.Arbitrary ()
|
|
|
|
import Data.String
|
|
|
|
import Prologue
|
|
|
|
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
|
|
|
|
describe "pqGrams" $ 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-06-23 17:19:45 +03:00
|
|
|
\ (term, p, q) -> pqGrams p q identity (toTerm term :: Term String String) `shouldSatisfy` all ((== p) . length . stem)
|
2016-06-23 00:59:28 +03:00
|
|
|
|
2016-06-23 17:11:48 +03:00
|
|
|
prop "produces grams with bases of the specified length" . forAll (arbitrary `suchThat` (\ (_, p, q) -> p > 0 && q > 0)) $
|
2016-06-23 17:19:45 +03:00
|
|
|
\ (term, p, q) -> pqGrams p q identity (toTerm term :: Term String String) `shouldSatisfy` all ((== q) . length . base)
|
2016-06-23 00:59:28 +03:00
|
|
|
|
|
|
|
describe "featureVector" $ do
|
2016-06-23 17:11:48 +03:00
|
|
|
prop "produces a vector of the specified dimension" . forAll (arbitrary `suchThat` ((> 0) . snd)) $
|
2016-06-23 17:34:23 +03:00
|
|
|
\ (grams, d) -> length (featureVector d (fromList (grams :: [Gram String]))) `shouldBe` d
|