Skip to content

Instantly share code, notes, and snippets.

@richardwu
Last active March 19, 2018 20:51
Show Gist options
  • Save richardwu/2277fc92bdb2edeaa2b59e263d8cf01a to your computer and use it in GitHub Desktop.
Save richardwu/2277fc92bdb2edeaa2b59e263d8cf01a to your computer and use it in GitHub Desktop.
Testing in Haskell (CS 442)
-- eval loop
module TestQ17 where
import Test.HUnit
import Q17
testFn fn (input, expected) =
TestCase $ (fn input) @?= expected
main =
let
testCases = [("hello", "hello"), (1,1), (True, False)]
id = \x -> x
in
runTestTT $ TestList (map (testFn id) testCases)
-- invoke this from the command line `runghs TestQ17.hs`
module TestQ17 where
import Test.HUnit
-- Replace this with the module you want to test
import Q17
-- Fails
test0 =
TestCase $ "hello" @?= "Hello"
-- Passes
test1 =
TestCase $ 1 @?= 1
-- Fails
test2 =
TestCase $ True @?= False
main = runTestTT $ TestList [test0, test1, test2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment