-- |
-- Module      : Test.Speculate.Expr.Equate
-- Copyright   : (c) 2016-2019 Rudy Matela
-- License     : 3-Clause BSD  (see the file LICENSE)
-- Maintainer  : Rudy Matela <rudy@matela.com.br>
--
-- This module is part of Speculate.
--
-- This module exports
--   smart constructors,
--   smart destructors
-- and queries over
--   equations,
--   inequations
--   and conditional equations.
module Test.Speculate.Expr.Equate
  ( unEquation
  , isEquation
  , unComparison
  , mkConditionalEquation
  , unConditionalEquation
  )
where

import Test.Speculate.Expr.Core
import Test.Speculate.Expr.Instance
import Data.Express.Fixtures ((-==>-))

unEquation :: Expr -> (Expr,Expr)
unEquation :: Expr -> (Expr, Expr)
unEquation ((Value [Char]
"==" Dynamic
_ :$ Expr
e1) :$ Expr
e2) = (Expr
e1,Expr
e2)
unEquation Expr
_ = [Char] -> (Expr, Expr)
forall a. HasCallStack => [Char] -> a
error [Char]
"unEquation: not an equation!"

isEquation :: Expr -> Bool
isEquation :: Expr -> Bool
isEquation ((Value [Char]
"==" Dynamic
_ :$ Expr
e1) :$ Expr
e2) = Bool
True
isEquation Expr
_ = Bool
False

unComparison :: Expr -> (Expr,Expr)
unComparison :: Expr -> (Expr, Expr)
unComparison ((Value [Char]
"compare"  Dynamic
_ :$ Expr
e1) :$ Expr
e2) = (Expr
e1,Expr
e2)
unComparison ((Value [Char]
"<"        Dynamic
_ :$ Expr
e1) :$ Expr
e2) = (Expr
e1,Expr
e2)
unComparison ((Value [Char]
"<="       Dynamic
_ :$ Expr
e1) :$ Expr
e2) = (Expr
e1,Expr
e2)
unComparison ((Value [Char]
">"        Dynamic
_ :$ Expr
e1) :$ Expr
e2) = (Expr
e1,Expr
e2)
unComparison ((Value [Char]
">="       Dynamic
_ :$ Expr
e1) :$ Expr
e2) = (Expr
e1,Expr
e2)
unComparison Expr
_ = [Char] -> (Expr, Expr)
forall a. HasCallStack => [Char] -> a
error [Char]
"unComparisonL: not a compare/(<)/(<=)/(>)/(>=) application"

mkConditionalEquation :: Instances -> Expr -> Expr -> Expr -> Expr
mkConditionalEquation :: Instances -> Expr -> Expr -> Expr -> Expr
mkConditionalEquation Instances
ti Expr
pre Expr
e1 Expr
e2 = Expr
pre Expr -> Expr -> Expr
-==>- Instances -> Expr -> Expr -> Expr
mkEquation Instances
ti Expr
e1 Expr
e2

unConditionalEquation :: Expr -> (Expr,Expr,Expr)
unConditionalEquation :: Expr -> (Expr, Expr, Expr)
unConditionalEquation ((Value [Char]
"==>" Dynamic
_ :$ Expr
pre) :$ ((Value [Char]
"==" Dynamic
_ :$ Expr
e1) :$ Expr
e2)) = (Expr
pre,Expr
e1,Expr
e2)
unConditionalEquation Expr
_ = [Char] -> (Expr, Expr, Expr)
forall a. HasCallStack => [Char] -> a
error [Char]
"unConditionalEquation: not an equation with side condition"