import Test.HUnit
import System.IO
import AbsSRL
import AbsRL hiding (RL,Rlblk,Exp(..),Ident(..),Step(..))
import qualified AbsRL as RL (RL,Rlblk,Exp(..),Ident(..),Step(..))
import Eval

--Expの式の評価を行う関数
tests = TestList
    [ "fact 1" ~: expeval [] (Econ 1) ~?= Vint 1
    , "fact 2" ~: expeval [] (Econ 2) ~?= Vint 2
    , "fact 3" ~: expeval [(Lstring "x",Vint 1),(Lstring "y",Vint 2)] (Evar ((Ident "x"))) ~?= Vint 1
    , "fact 4" ~: expeval [(Lstring "x",Vint 1),(Lstring "y",Vint 2)] (Evar ((Ident "y"))) ~?= Vint 2
    , "fact 5" ~: expeval [(Larr "x" (Vint 0) , Vint 1) , (Larr "y" (Vint 1) , Vint 2)] (Earr (Evar (Ident "x")) (Econ 0)) ~?= Vint 1
    , "fact 6" ~: expeval [(Larr "x" (Vint 0) , Vint 1) , (Larr "y" (Vint 1) , Vint 2)] (Earr (Evar (Ident "y")) (Econ 1)) ~?= Vint 2
    , "fact 7" ~: expeval [(Larr "x" (Vint 1) , Vint 1) , (Larr "y" (Vint 1) , Vint 2)] (Earr (Evar (Ident "x")) (Econ 1)) ~?= Vint 1
    , "fact 8" ~: expeval [] (Exor (Econ 1) (Econ 0)) ~?= Vint 1
    , "fact 9" ~: expeval [] (Exor (Econ 1) (Econ 1)) ~?= Vint 0
    , "fact 10" ~: expeval [] (Exor (Econ 0) (Econ 0)) ~?= Vint 0
    , "fact 11" ~: expeval [] (Eeq (Econ 1) (Econ 1)) ~?= Vint 1
    , "fact 12" ~: expeval [] (Eeq (Econ 1) (Econ 2)) ~?= Vint 0
    , "fact 13" ~: expeval [] (Ene (Econ 1) (Econ 1)) ~?= Vint 0
    , "fact 14" ~: expeval [] (Ene (Econ 1) (Econ 2)) ~?= Vint 1
    , "fact 15" ~: expeval [] (Elt (Econ 1) (Econ 2)) ~?= Vint 1
    , "fact 16" ~: expeval [] (Elt (Econ 2) (Econ 1)) ~?= Vint 0
    , "fact 17" ~: expeval [] (Elt (Econ 1) (Econ 1)) ~?= Vint 0
    , "fact 18" ~: expeval [] (Egt (Econ 2) (Econ 1)) ~?= Vint 1
    , "fact 19" ~: expeval [] (Egt (Econ 1) (Econ 1)) ~?= Vint 0
    , "fact 20" ~: expeval [] (Egt (Econ 1) (Econ 2)) ~?= Vint 0
    , "fact 21" ~: expeval [] (Ele (Econ 2) (Econ 1)) ~?= Vint 1
    , "fact 22" ~: expeval [] (Ele (Econ 1) (Econ 1)) ~?= Vint 1
    , "fact 23" ~: expeval [] (Ele (Econ 1) (Econ 2)) ~?= Vint 0
    , "fact 24" ~: expeval [] (Ege (Econ 1) (Econ 2)) ~?= Vint 1
    , "fact 25" ~: expeval [] (Ege (Econ 1) (Econ 1)) ~?= Vint 1
    , "fact 26" ~: expeval [] (Ege (Econ 2) (Econ 1)) ~?= Vint 0
    , "fact 27" ~: expeval [] (Eadd (Econ 2) (Econ 3)) ~?= Vint 5
    , "fact 28" ~: expeval [] (Eadd (Econ 5) (Econ 5)) ~?= Vint 10
    , "fact 29" ~: expeval [] (Emin (Econ 2) (Econ 3)) ~?= Vint (-1)
    , "fact 30" ~: expeval [] (Emin (Econ 3) (Econ 2)) ~?= Vint 1
    , "fact 31" ~: expeval [] (Emul (Econ 2) (Econ 3)) ~?= Vint 6
    , "fact 32" ~: expeval [] (Emul (Econ (-3)) (Econ 2)) ~?= Vint (-6)
    , "fact 33" ~: expeval [] (Emul (Econ 0) (Econ 2)) ~?= Vint 0
    , "fact 34" ~: expeval [] (Ediv (Econ 10) (Econ 5)) ~?= Vint 2
    , "fact 35" ~: expeval [] (Ediv (Econ (-6)) (Econ 2)) ~?= Vint (-3)
    , "fact 36" ~: expeval [] (Ediv (Econ 0) (Econ 2)) ~?= Vint 0
    , "fact 37" ~: expeval [] (Ediv (Econ 2) (Econ 3)) ~?= Vint 0
    , "fact 38" ~: expeval [(Lstring "x", Vsvalue [5,2,3,4]),(Lstring "y", Vsvalue [10,7,9,8])] (Etop (Evar (Ident "x"))) ~?= Vint 5
    , "fact 39" ~: expeval [(Lstring "x", Vsvalue [5,2,3,4]),(Lstring "y", Vsvalue [10,7,9,8])] (Etop (Evar (Ident "y"))) ~?= Vint 10
    , "fact 40" ~: expeval [(Lstring "x", Vsvalue [1,2,3,4]) , (Lstring "y", Vsvalue [])] (Eempty (Evar (Ident "x"))) ~?= Vint 0
    , "fact 41" ~: expeval [(Lstring "x", Vsvalue [1,2,3,4]) , (Lstring "y", Vsvalue [])] (Eempty (Evar (Ident "y"))) ~?= Vint 1  
    ]

main =
    runTestText (putTextToHandle stderr False) tests
