2015-12-17 21:08:47 +03:00
|
|
|
module TermSpec where
|
|
|
|
|
2016-06-01 16:16:47 +03:00
|
|
|
import ArbitraryTerm
|
|
|
|
import Data.String
|
|
|
|
import Data.Text.Arbitrary ()
|
2015-12-17 21:08:47 +03:00
|
|
|
import Diff
|
2016-06-06 19:07:07 +03:00
|
|
|
import Diff.Arbitrary
|
2016-06-01 16:16:47 +03:00
|
|
|
import Interpreter
|
|
|
|
import Prologue
|
|
|
|
import Term.Arbitrary
|
|
|
|
import Test.Hspec
|
|
|
|
import Test.Hspec.QuickCheck
|
2016-06-01 18:52:43 +03:00
|
|
|
import Test.QuickCheck
|
2015-12-17 21:08:47 +03:00
|
|
|
|
|
|
|
spec :: Spec
|
2016-01-05 18:38:51 +03:00
|
|
|
spec = parallel $ do
|
2015-12-17 21:08:47 +03:00
|
|
|
describe "Term" $ do
|
|
|
|
prop "equality is reflexive" $
|
2016-06-01 03:29:12 +03:00
|
|
|
\ a -> toTerm a == toTerm (a :: ArbitraryTerm String ())
|
2015-12-17 21:08:47 +03:00
|
|
|
|
2016-06-01 19:30:05 +03:00
|
|
|
describe "ArbitraryTerm" $
|
2016-06-01 18:52:43 +03:00
|
|
|
prop "generates terms of a specific size" $ forAll ((arbitrary >>= \ n -> (,) n <$> termOfSize n) `suchThat` ((> 0) . fst)) $
|
2016-06-06 19:26:06 +03:00
|
|
|
\ (n, term) -> arbitraryTermSize (term :: ArbitraryTerm String ()) `shouldBe` n
|
2016-06-01 18:52:43 +03:00
|
|
|
|
2016-06-06 19:07:07 +03:00
|
|
|
describe "ArbitraryDiff" $
|
|
|
|
prop "generates diffs of a specific size" $ forAll ((arbitrary >>= \ n -> (,) n <$> diffOfSize n) `suchThat` ((> 0) . fst)) $
|
2016-06-06 19:26:06 +03:00
|
|
|
\ (n, diff) -> arbitraryDiffSize (diff :: ArbitraryDiff String ()) `shouldBe` n
|
2016-06-06 19:07:07 +03:00
|
|
|
|
2015-12-17 21:08:47 +03:00
|
|
|
describe "Diff" $ do
|
|
|
|
prop "equality is reflexive" $
|
2016-06-06 18:36:48 +03:00
|
|
|
\ a b -> let diff = diffTerms (free . Free) (==) diffCost (toTerm a) (toTerm (b :: ArbitraryTerm String CategorySet)) in
|
2015-12-17 21:08:47 +03:00
|
|
|
diff == diff
|
|
|
|
|
|
|
|
prop "equal terms produce identity diffs" $
|
2016-06-01 03:29:12 +03:00
|
|
|
\ a -> let term = toTerm (a :: ArbitraryTerm String CategorySet) in
|
2016-06-06 18:36:48 +03:00
|
|
|
diffCost (diffTerms (free . Free) (==) diffCost term term) == 0
|