{- |
    Module      :  Test.SDP.Ord
    Copyright   :  (c) Andrey Mulik 2019
    License     :  BSD-style
    Maintainer  :  work.a.mulik@gmail.com
    Portability :  portable
    
    @Test.SDP.Ord@ provides basic test suite for 'Ord' instances.
-}
module Test.SDP.Ord
(
  -- * Ord test
  TestOrd, ordTest,
  
  -- ** Lexicographic test
  lexicographicOrdTest
)
where

import Prelude ()
import SDP.SafePrelude
import SDP.Linear

default ()

--------------------------------------------------------------------------------

-- | TestOrd is service type synonym for more comfortable quickCheck using.
type TestOrd l = l -> l -> l -> Bool

--------------------------------------------------------------------------------

-- | ordTest is basic test suite for 'Ord' instances.
ordTest :: (Ord l) => l -> l -> l -> Bool
ordTest :: l -> l -> l -> Bool
ordTest l
xs l
ys l
zs = [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and
  [
    -- antisymmetry
    (l
xs l -> l -> Bool
forall a. Ord a => a -> a -> Bool
<= l
ys Bool -> Bool -> Bool
&& l
ys l -> l -> Bool
forall a. Ord a => a -> a -> Bool
<= l
xs) Bool -> Bool -> Bool
forall a. Ord a => a -> a -> Bool
<= (l
xs l -> l -> Bool
forall a. Eq a => a -> a -> Bool
== l
ys),
    
    -- transitivity
    (l
xs l -> l -> Bool
forall a. Ord a => a -> a -> Bool
<= l
ys Bool -> Bool -> Bool
&& l
ys l -> l -> Bool
forall a. Ord a => a -> a -> Bool
<= l
zs) Bool -> Bool -> Bool
forall a. Ord a => a -> a -> Bool
<= (l
xs l -> l -> Bool
forall a. Ord a => a -> a -> Bool
<= l
zs),
    
    -- totality
    (l
xs l -> l -> Bool
forall a. Ord a => a -> a -> Bool
<= l
ys) Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
/= (l
xs l -> l -> Bool
forall a. Ord a => a -> a -> Bool
> l
ys)
  ]

-- | lexicographicOrdTest checks 'Linear' structures for lexicographic order.
lexicographicOrdTest :: (Linear l e, Ord l, Ord e) => l -> l -> Bool
lexicographicOrdTest :: l -> l -> Bool
lexicographicOrdTest l
xs l
ys = (l
xs Compare l
forall o. Ord o => Compare o
<=> l
ys) Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
== (l -> [e]
forall l e. Linear l e => l -> [e]
listL l
xs Compare [e]
forall o. Ord o => Compare o
<=> l -> [e]
forall l e. Linear l e => l -> [e]
listL l
ys)