{- |
    Module      :  Test.SDP.Estimate
    Copyright   :  (c) Andrey Mulik 2019
    License     :  BSD-style
    Maintainer  :  work.a.mulik@gmail.com
    Portability :  non-portable (requires non-portable modules)
    
    @Test.SDP.Estimate@ provides basic test suite for 'Estimate' instances.
-}
module Test.SDP.Estimate
  (
    -- * Estimate test
    TestEstimate, estimateTest
  )
where

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

default ()

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

-- | TestEstimate is service type synonym for more comfortable quickCheck using.
type TestEstimate e = Int -> e -> e -> Bool

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

-- | 'estimateTest' is basic test suite for 'Estimate' instances.
estimateTest :: (Bordered b i) => Int -> b -> b -> Bool
estimateTest :: Int -> b -> b -> Bool
estimateTest Int
n b
xs b
ys = [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and
  [
    -- by definition
    Ordering
cmp Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
== (Int
sx Compare Int
forall o. Ord o => Compare o
<=>  Int
sy),
    Ordering
cmp Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
== (Int
sx Int -> b -> Ordering
forall e. Estimate e => Int -> e -> Ordering
<=.> b
ys),
    Ordering
cmp Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
== (b
xs b -> Int -> Ordering
forall e. Estimate e => e -> Int -> Ordering
<.=> Int
sy),
    
    (b
xs b -> Int -> Ordering
forall e. Estimate e => e -> Int -> Ordering
<.=> Int
n) Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
== (Int
sx Compare Int
forall o. Ord o => Compare o
<=> Int
n),
    
    case b
xs b -> Int -> Ordering
forall e. Estimate e => e -> Int -> Ordering
<.=> Int
n of
      Ordering
EQ -> b
xs b -> Int -> Bool
forall e. Estimate e => e -> Int -> Bool
.== Int
n Bool -> Bool -> Bool
&& Bool -> Bool
not (b
xs b -> Int -> Bool
forall e. Estimate e => e -> Int -> Bool
./= Int
n)
      Ordering
LT -> b
xs b -> Int -> Bool
forall e. Estimate e => e -> Int -> Bool
.< Int
n Bool -> Bool -> Bool
&& Int
n Int -> b -> Bool
forall e. Estimate e => Int -> e -> Bool
>. b
xs
      Ordering
GT -> b
xs b -> Int -> Bool
forall e. Estimate e => e -> Int -> Bool
.> Int
n Bool -> Bool -> Bool
&& Int
n Int -> b -> Bool
forall e. Estimate e => Int -> e -> Bool
<. b
xs,
    
    case Ordering
cmp of
      Ordering
LT -> Bool
lt1 Bool -> Bool -> Bool
&& b
ys b -> b -> Bool
forall e. Estimate e => e -> e -> Bool
.>. b
xs
      Ordering
GT -> Bool
gt1 Bool -> Bool -> Bool
&& b
ys b -> b -> Bool
forall e. Estimate e => e -> e -> Bool
.<. b
xs
      Ordering
EQ -> Bool
eq1 Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
ne1,
    
    Bool -> Bool
not (b
xs b -> b -> Bool
forall e. Estimate e => e -> e -> Bool
.>. b
xs), (b
xs b -> b -> Bool
forall e. Estimate e => e -> e -> Bool
.>=. b
xs),
    Bool -> Bool
not (b
xs b -> b -> Bool
forall e. Estimate e => e -> e -> Bool
.<. b
xs), (b
xs b -> b -> Bool
forall e. Estimate e => e -> e -> Bool
.<=. b
xs),
    
    -- equality
    Bool
gt1 Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== (b
ys b -> b -> Bool
forall e. Estimate e => e -> e -> Bool
.<. b
xs),
    Bool
lt1 Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== (b
ys b -> b -> Bool
forall e. Estimate e => e -> e -> Bool
.>. b
xs),
    
    Bool
ge1 Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== (b
ys b -> b -> Bool
forall e. Estimate e => e -> e -> Bool
.<=. b
xs),
    Bool
le1 Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== (b
ys b -> b -> Bool
forall e. Estimate e => e -> e -> Bool
.>=. b
xs),
    
    Bool
ge1 Bool -> Bool -> Bool
|| Bool
le1,
    Bool
gt1 Bool -> Bool -> Bool
|| Bool
lt1 Bool -> Bool -> Bool
|| Bool
eq1,
    
    -- inequality
    (Bool
gt1 Bool -> Bool -> Bool
|| Bool
lt1) Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
/= Bool
eq1,
    
    Bool
gt1 Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
/= Bool
le1,
    Bool
lt1 Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
/= Bool
ge1
  ]
  where
    gt1 :: Bool
gt1 = b
xs b -> b -> Bool
forall e. Estimate e => e -> e -> Bool
.>.  b
ys; lt1 :: Bool
lt1 = b
xs b -> b -> Bool
forall e. Estimate e => e -> e -> Bool
.<.  b
ys
    ge1 :: Bool
ge1 = b
xs b -> b -> Bool
forall e. Estimate e => e -> e -> Bool
.>=. b
ys; le1 :: Bool
le1 = b
xs b -> b -> Bool
forall e. Estimate e => e -> e -> Bool
.<=. b
ys
    eq1 :: Bool
eq1 = b
xs b -> b -> Bool
forall e. Estimate e => e -> e -> Bool
.==. b
ys; ne1 :: Bool
ne1 = b
xs b -> b -> Bool
forall e. Estimate e => e -> e -> Bool
./=. b
ys
    cmp :: Ordering
cmp = b
xs Compare b
forall e. Estimate e => Compare e
<==> b
ys
    sx :: Int
sx  = b -> Int
forall b i. Bordered b i => b -> Int
sizeOf  b
xs
    sy :: Int
sy  = b -> Int
forall b i. Bordered b i => b -> Int
sizeOf  b
ys