module Hydra.PartySpec where

import Hydra.Prelude
import Test.Hydra.Prelude

import Hydra.Party (Party (..))
import Test.Aeson.GenericSpecs (roundtripAndGoldenSpecs)
import Test.Hydra.Fixture (alice, bob, carol)
import Test.QuickCheck ((==>))

spec :: Spec
spec :: Spec
spec = do
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Ord" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> ((Party, Party, Party) -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"is transitive" (((Party, Party, Party) -> Property) -> Spec)
-> ((Party, Party, Party) -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ \(Party
x :: Party, Party
y, Party
z) ->
      Party
x Party -> Party -> Bool
forall a. Ord a => a -> a -> Bool
<= Party
y Bool -> Bool -> Bool
&& Party
y Party -> Party -> Bool
forall a. Ord a => a -> a -> Bool
<= Party
z Bool -> Bool -> Property
forall prop. Testable prop => Bool -> prop -> Property
==> Party
x Party -> Party -> Bool
forall a. Ord a => a -> a -> Bool
<= Party
z
    String -> (Party -> Bool) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"is reflexive" ((Party -> Bool) -> Spec) -> (Party -> Bool) -> Spec
forall a b. (a -> b) -> a -> b
$ \(Party
x :: Party) ->
      Party
x Party -> Party -> Bool
forall a. Ord a => a -> a -> Bool
<= Party
x
    String -> ((Party, Party) -> Bool) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"is antisymmetric" (((Party, Party) -> Bool) -> Spec)
-> ((Party, Party) -> Bool) -> Spec
forall a b. (a -> b) -> a -> b
$ \(Party
x :: Party, Party
y) ->
      (Party
x Party -> Party -> Bool
forall a. Ord a => a -> a -> Bool
<= Party
y Bool -> Bool -> Bool
&& Party
y Party -> Party -> Bool
forall a. Ord a => a -> a -> Bool
<= Party
x) Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== (Party
x Party -> Party -> Bool
forall a. Eq a => a -> a -> Bool
== Party
y)

  String -> ((Party, Party) -> Bool) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"implements Eq and Ord correspondingly" (((Party, Party) -> Bool) -> Spec)
-> ((Party, Party) -> Bool) -> Spec
forall a b. (a -> b) -> a -> b
$ \(Party
x :: Party, Party
y) ->
    (Party -> Party -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Party
x Party
y Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
== Ordering
EQ) Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== (Party
x Party -> Party -> Bool
forall a. Eq a => a -> a -> Bool
== Party
y)

  Proxy Party -> Spec
forall a.
(Arbitrary a, ToJSON a, FromJSON a, Typeable a) =>
Proxy a -> Spec
roundtripAndGoldenSpecs (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @Party)

  String -> Expectation -> SpecM (Arg Expectation) ()
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"has alice, bob, carol sorted" (Expectation -> SpecM (Arg Expectation) ())
-> Expectation -> SpecM (Arg Expectation) ()
forall a b. (a -> b) -> a -> b
$
    [Party] -> [Party]
forall a. Ord a => [a] -> [a]
sort [Party
alice, Party
bob, Party
carol] [Party] -> [Party] -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` [Party
alice, Party
bob, Party
carol]