dumb-cas-0.2.1.0: test/tasty/test.hs
-- |
-- Module : Main
-- Copyright : (c) Justus SagemΓΌller 2017
-- License : GPL v3
--
-- Maintainer : (@) jsag $ hvl.no
-- Stability : experimental
-- Portability : portable
--
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE CPP #-}
module Main where
import CAS.Dumb
import Test.Tasty
import Test.Tasty.HUnit
main = defaultMain tests
type Expr = Expression String
tests :: TestTree
tests = testGroup "Tests"
[ testGroup "Explicit transformations"
[ testCase "π + π * π &~: γ+γ :=: γ+γ" $
(π + π * π &~: γ+γ :=: γ+γ) %@?= (π * π + π :: Expr)
, testCase "(π+π) * π &~: γ+γ :=: γ+γ" $
((π+π) * π &~: γ+γ :=: γ+γ) %@?= ((π+π) * π :: Expr)
, testCase "π*π - π*π &~: γ*γ :=: γ*γ" $
(π*π - π*π &~: γ*γ :=: γ*γ) %@?= (π*π - π*π :: Expr)
, testCase "π*π - π*π &~? γ*γ :=: γ*γ" $
(π*π - π*π &~? γ*γ :=: γ*γ) @?= [π*π - π*π, π*π - π*π :: Expr]
, testCase "π + π + π + π &~: γ+γ :=: γ+γ" $
(π + π + π + π &~: γ+γ :=: γ+γ) %@?= (π + π + π + π :: Expr)
, testCase "π + π + π + π &~: π+π :=: π+π" $
(π + π + π + π &~: π+π :=: π+π) %@?= (π + π + π + π :: Expr)
, testCase "π + π + π + π &~? γ+γ :=: γ+γ" $
(π + π + π + π &~? γ+γ :=: γ+γ) @?= [ π + π + π + π
, π + π + π + π
, π + π + π + π :: Expr]
, testCase "π + π + π &~? π+π :=: ΞΎ" $
(π + π + π &~? π+π :=: ΞΎ ) @?= [ ΞΎ + π :: Expr]
, testCase "π + π + π &~? π+π :=: π+π &~? π+π :=: ΞΎ" $
((π + π + π &~? π+π:=:π+π) >>= (&~? π+π:=:ΞΎ) )
@?= [ ΞΎ+π :: Expr]
, testCase "π*π₯ + π*π₯ + π &~: γ*γ+γ*γ :=: (γ+γ)*γ" $
(π*π₯ + π*π₯ + π &~: γ*γ+γ*γ :=: (γ+γ)*γ) %@?= ((π+π)*π₯ + π :: Expr)
, testCase "(π+π)*π₯ + π &~: (γ+γ)*γ :=: γ*γ+γ*γ" $
((π+π)*π₯ + π &~: (γ+γ)*γ :=: γ*γ+γ*γ) %@?= (π*π₯ + π*π₯ + π :: Expr)
, testCase "π*π*π*π &~: π*π :=: π*π" $
(π*π*π*π &~: π*π :=: π*π) %@?= (π*π*π*π :: Expr)
, testCase "π*π*π*π &~: π*π :=: π*π" $
(π*π*π*π &~: π*π :=: π*π) %@?= (π*π*π*π :: Expr)
, testCase "π*π*π*π &~: π*π :=: π*π" $
(π*π*π*π &~: π*π :=: π*π) %@?= (π*π*π*π :: Expr)
, testCase "π + π - π &~: π-π :=: (-π)+π" $
(π + π - π &~: π-π :=: (-π)+π) %@?= (π + (-π) + π :: Expr)
, testCase "Rename local symbols" $
(map succ%$> π+π) * π₯ %@?= ((π+π) * π₯ :: Expr)
]
, testGroup "Show instance"
[ testCase "π+π+π" $
π+π+π %@?= "π+π+π"
, testCase "π-π+π" $
π-π+π %@?= "π-π+π"
, testCase "π+(π+π)" $
π+(π+π) %@?= "π+(π+π)"
, testCase "π+π*π" $
π+π*π %@?= "π+π*π"
, testCase "3*π§-1" $
3*π§-1 %@?= "3*π§-1"
, testCase "(π+π)*π" $
(π+π)*π %@?= "(π+π)*π"
, testCase "abs (π+π)" $
abs (π+π) %@?= "abs (π+π)"
, testCase "abs 3" $
abs 3 %@?= "abs 3"
, testCase "π + -3" $
π+(-3) %@?= "π-3"
, testCase "π / signum Ο" $
π/signum Ο %@?= "π/signum Ο"
, testCase "logBase 2 32 ** atan pi" $
logBase 2 32 ** atan pi %@?= "2`logBase`32**atan pi"
, testCase "37.84" $
37.84 %@?= "37.84"
, testCase "5e-23" $
5e-23 %@?= "5e-23"
, testCase "-5.3e7" $
-5.3e8 %@?= " -5.3e8"
]
]
infix 1 %@?=
class ComparableExpressions e f | f -> e where
(%@?=) :: HasCallStack => e -> f -> Assertion
instance ComparableExpressions Expr Expr where
e %@?= f
| e==f = return ()
| otherwise = assertFailure
$ "Expected "++show f++" γstructure: "++showStructure f++"γ,"
++ "\nbut got " ++show e++" γstructure: "++showStructure e++"γ,"
instance ComparableExpressions Expr String where
e %@?= f
| show e==f = return ()
| otherwise = assertFailure $ "Expected \""++f++"\""
++ "\nbut got \"" ++show e++"\" γstructure: "++showStructure e++"γ,"