Packages

The Phi Programming Language

Current section

Files

Jump to
phi tests Test Control Monad State.phi
Raw

tests/Test/Control/Monad/State.phi

module Test.Control.Monad.State where
import Test.QuickCheck (TestGroup(..), TestResult, quickCheck1)
import Prelude (IO, Unit, bind, discard, (+), (-), (==))
import Control.Monad.State (State, evalState, execState, get, gets, put, modify)
fib :: Integer -> State (Integer, Integer) Integer
fib 0 = gets (\(a, b) -> b)
fib n = do
modify (\(a, b) -> (b, a + b))
fib (n - 1)
plus :: State Integer ()
plus = do
a <- get
put (a + 1)
test :: TestGroup (Integer -> IO TestResult)
test = Exe [
quickCheck1 "fib" (evalState (fib 7) (0, 1) == 21),
quickCheck1 "plus" (execState plus 2 == 3)
]