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

--Stepを評価する関数
tests = TestList
    [ "fact 1" ~: stepeval [(Lstring "x",Vint 5) , (Lstring "y",Vint 10)] (SasnAdd (Ident "x") (Econ 3)) ~?= [(Lstring "x",Vint 8),(Lstring "y",Vint 10)]
    , "fact 2" ~: stepeval [(Lstring "x",Vint 5) , (Lstring "y",Vint 10)] (SasnAdd (Ident "y") (Econ 3)) ~?= [(Lstring "x",Vint 5),(Lstring "y",Vint 13)]
    , "fact 3" ~: stepeval [(Lstring "x",Vint 5) , (Lstring "y",Vint 10)] (SasnMin (Ident "x") (Econ 3)) ~?= [(Lstring "x",Vint 2),(Lstring "y",Vint 10)]
    , "fact 4" ~: stepeval [(Lstring "x",Vint 5) , (Lstring "y",Vint 10)] (SasnMin (Ident "y") (Econ 3)) ~?= [(Lstring "x",Vint 5),(Lstring "y",Vint 7) ]
    , "fact 5" ~: stepeval [(Lstring "x",Vint 5) , (Lstring "y",Vint 10)] (SasnXor (Ident "x") (Econ 0)) ~?= [(Lstring "x",Vint 0),(Lstring "y",Vint 10)]
    , "fact 6" ~: stepeval [(Lstring "x",Vint 5) , (Lstring "y",Vint 10)] (SasnXor (Ident "x") (Econ 1)) ~?= [(Lstring "x",Vint 1),(Lstring "y",Vint 10)]  
    , "fact 7" ~: stepeval [(Larr "x" (Vint 0) , Vint 10) , (Larr "y" (Vint 0) , Vint 20),(Larr "x" (Vint 2) , Vint 15)] (SasnArrAdd (Ident "x") (Econ 0) (Econ 7)) ~?= [(Larr "x" (Vint 0),Vint 17),(Larr "y" (Vint 0),Vint 20),(Larr "x" (Vint 2) , Vint 15)]
    , "fact 8" ~: stepeval [(Larr "x" (Vint 0) , Vint 10) , (Larr "y" (Vint 1) , Vint 20),(Larr "x" (Vint 2) , Vint 15)] (SasnArrAdd (Ident "y") (Econ 1) (Econ 5)) ~?= [(Larr "x" (Vint 0),Vint 10),(Larr "y" (Vint 1),Vint 25),(Larr "x" (Vint 2) , Vint 15)]
    , "fact 9" ~: stepeval [(Larr "x" (Vint 0) , Vint 10) , (Larr "y" (Vint 0) , Vint 20),(Larr "x" (Vint 2) , Vint 15)] (SasnArrAdd (Ident "x") (Econ 2) (Econ 7)) ~?= [(Larr "x" (Vint 0),Vint 10),(Larr "y" (Vint 0),Vint 20),(Larr "x" (Vint 2) , Vint 22)]  
    , "fact 10" ~: stepeval [(Larr "x" (Vint 0) , Vint 10) , (Larr "y" (Vint 0) , Vint 20),(Larr "x" (Vint 2) , Vint 15)] (SasnArrMin (Ident "x") (Econ 0) (Econ 7)) ~?= [(Larr "x" (Vint 0),Vint 3),(Larr "y" (Vint 0),Vint 20),(Larr "x" (Vint 2) , Vint 15)]
    , "fact 11" ~: stepeval [(Larr "x" (Vint 0) , Vint 10) , (Larr "y" (Vint 1) , Vint 20),(Larr "x" (Vint 2) , Vint 15)] (SasnArrMin (Ident "y") (Econ 1) (Econ 5)) ~?= [(Larr "x" (Vint 0),Vint 10),(Larr "y" (Vint 1),Vint 15),(Larr "x" (Vint 2) , Vint 15)]
    , "fact 12" ~: stepeval [(Larr "x" (Vint 0) , Vint 10) , (Larr "y" (Vint 0) , Vint 20),(Larr "x" (Vint 2) , Vint 15)] (SasnArrMin (Ident "x") (Econ 2) (Econ 7)) ~?= [(Larr "x" (Vint 0),Vint 10),(Larr "y" (Vint 0),Vint 20),(Larr "x" (Vint 2) , Vint 8)]
    , "fact 13" ~: stepeval [(Larr "x" (Vint 0) , Vint 10) , (Larr "y" (Vint 1) , Vint 20) , (Larr "x" (Vint 2) , Vint 30)] (SasnArrXor (Ident "x") (Econ 0) (Econ 7)) ~?= [(Larr "x" (Vint 0),Vint 1),(Larr "y" (Vint 1),Vint 20),(Larr "x" (Vint 2),Vint 30)]
    , "fact 14" ~: stepeval [(Larr "x" (Vint 0) , Vint 10) , (Larr "y" (Vint 1) , Vint 20) , (Larr "x" (Vint 2) , Vint 30)] (SasnArrXor (Ident "y") (Econ 1) (Econ 7)) ~?= [(Larr "x" (Vint 0),Vint 10),(Larr "y" (Vint 1),Vint 1),(Larr "x" (Vint 2),Vint 30)]
    , "fact 15" ~: stepeval [(Larr "x" (Vint 0) , Vint 10) , (Larr "y" (Vint 1) , Vint 20) , (Larr "x" (Vint 2) , Vint 30)] (SasnArrXor (Ident "x") (Econ 2) (Econ 7)) ~?= [(Larr "x" (Vint 0),Vint 10),(Larr "y" (Vint 1),Vint 20),(Larr "x" (Vint 2),Vint 1)]
    , "fact 16" ~: stepeval [(Larr "x" (Vint 0) , Vint 10) , (Larr "y" (Vint 1) , Vint 20) , (Larr "x" (Vint 2) , Vint 30)] (SasnArrXor (Ident "x") (Econ 0) (Econ 0)) ~?= [(Larr "x" (Vint 0),Vint 0),(Larr "y" (Vint 1),Vint 20),(Larr "x" (Vint 2),Vint 30)]
    , "fact 17" ~: stepeval [(Lstring "x", Vsvalue [1,2,3,4]) , (Lstring "y" , Vsvalue [5,6,7,8])] (Spush (Ident "x") (Ident "y")) ~?= [(Lstring "x",Vint 0),(Lstring "y",Vsvalue [1,2,3,4,5,6,7,8])]
    , "fact 18" ~: stepeval [(Lstring "x", Vsvalue []) , (Lstring "y" , Vsvalue [5,6,7,8])] (Spush (Ident "x") (Ident "y")) ~?= [(Lstring "x",Vint 0),(Lstring "y",Vsvalue [5,6,7,8])]
    , "fact 19" ~: stepeval [(Lstring "x", Vsvalue [1,2,3,4]) , (Lstring "y" , Vsvalue [])] (Spush (Ident "x") (Ident "y")) ~?= [(Lstring "x",Vint 0),(Lstring "y",Vsvalue [1,2,3,4])]
    , "fact 20" ~: stepeval [(Lstring "x", Vint 0) , (Lstring "y" , Vsvalue [5,6,7,8])] (Spop (Ident "x") (Ident "y")) ~?= [(Lstring "x",Vsvalue [5]),(Lstring "y",Vsvalue [6,7,8])]
    , "fact 21" ~: stepeval [(Lstring "x", Vint 0) , (Lstring "y" , Vsvalue [4,6,5,3])] (Spop (Ident "x") (Ident "y")) ~?= [(Lstring "x",Vsvalue [4]),(Lstring "y",Vsvalue [6,5,3])]  
      ]

main =
    runTestText (putTextToHandle stderr False) tests
