2019-08-31 19:17:27 +02:00
|
|
|
{-# LANGUAGE ApplicativeDo #-}
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
module Xanthous.Data.EntityMapSpec where
|
|
|
|
--------------------------------------------------------------------------------
|
2019-11-29 20:33:52 +01:00
|
|
|
import Test.Prelude
|
2019-08-31 19:17:27 +02:00
|
|
|
--------------------------------------------------------------------------------
|
2019-11-29 20:33:52 +01:00
|
|
|
import qualified Data.Aeson as JSON
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
import Xanthous.Data.EntityMap
|
2019-08-31 19:17:27 +02:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = defaultMain test
|
|
|
|
|
|
|
|
test :: TestTree
|
2019-09-15 19:00:28 +02:00
|
|
|
test = localOption (QuickCheckTests 20)
|
|
|
|
$ testGroup "Xanthous.Data.EntityMap"
|
2019-08-31 19:17:27 +02:00
|
|
|
[ testBatch $ monoid @(EntityMap Int) mempty
|
2019-09-15 19:00:28 +02:00
|
|
|
, testGroup "Deduplicate"
|
2019-09-20 18:03:30 +02:00
|
|
|
[ testGroup "Semigroup laws"
|
|
|
|
[ testProperty "associative" $ \(a :: Deduplicate (EntityMap Int)) b c ->
|
|
|
|
a <> (b <> c) === (a <> b) <> c
|
|
|
|
]
|
2019-09-15 19:00:28 +02:00
|
|
|
]
|
2019-08-31 19:17:27 +02:00
|
|
|
, testGroup "Eq laws"
|
|
|
|
[ testProperty "reflexivity" $ \(em :: EntityMap Int) ->
|
|
|
|
em == em
|
|
|
|
, testProperty "symmetric" $ \(em₁ :: EntityMap Int) em₂ ->
|
|
|
|
(em₁ == em₂) == (em₂ == em₁)
|
|
|
|
, testProperty "transitive" $ \(em₁ :: EntityMap Int) em₂ em₃ ->
|
|
|
|
if (em₁ == em₂ && em₂ == em₃)
|
|
|
|
then (em₁ == em₃)
|
|
|
|
else True
|
|
|
|
]
|
2019-11-29 20:33:52 +01:00
|
|
|
, testGroup "JSON encoding/decoding"
|
|
|
|
[ testProperty "Preserves IDs" $ \(em :: EntityMap Int) ->
|
|
|
|
let Just em' = JSON.decode $ JSON.encode em
|
|
|
|
in toEIDsAndPositioned em' === toEIDsAndPositioned em
|
|
|
|
]
|
2019-08-31 19:17:27 +02:00
|
|
|
]
|