-- |
-- Module      : Test.Speculate.Expr.Equate
-- Copyright   : (c) 2016-2024 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 String
"==" Dynamic
_ :$ Expr
e1) :$ Expr
e2) = (Expr
e1,Expr
e2)
unEquation Expr
_ = String -> (Expr, Expr)
forall a. HasCallStack => String -> a
error String
"unEquation: not an equation!"

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

unComparison :: Expr -> (Expr,Expr)
unComparison :: Expr -> (Expr, Expr)
unComparison ((Value String
"compare"  Dynamic
_ :$ Expr
e1) :$ Expr
e2) = (Expr
e1,Expr
e2)
unComparison ((Value String
"<"        Dynamic
_ :$ Expr
e1) :$ Expr
e2) = (Expr
e1,Expr
e2)
unComparison ((Value String
"<="       Dynamic
_ :$ Expr
e1) :$ Expr
e2) = (Expr
e1,Expr
e2)
unComparison ((Value String
">"        Dynamic
_ :$ Expr
e1) :$ Expr
e2) = (Expr
e1,Expr
e2)
unComparison ((Value String
">="       Dynamic
_ :$ Expr
e1) :$ Expr
e2) = (Expr
e1,Expr
e2)
unComparison Expr
_ = String -> (Expr, Expr)
forall a. HasCallStack => String -> a
error String
"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 String
"==>" Dynamic
_ :$ Expr
pre) :$ ((Value String
"==" Dynamic
_ :$ Expr
e1) :$ Expr
e2)) = (Expr
pre,Expr
e1,Expr
e2)
unConditionalEquation Expr
_ = String -> (Expr, Expr, Expr)
forall a. HasCallStack => String -> a
error String
"unConditionalEquation: not an equation with side condition"