Created
September 21, 2016 04:35
-
-
Save ramirez7/e659acd04271bbc98100bac54eabd48c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type UnitTest a = S.StateT Bool IO a | |
| test :: (Show a, Eq a) => String -> a -> a -> UnitTest () | |
| test name found expected | |
| | found == expected = passTest | |
| | otherwise = failTest | |
| where | |
| failTest = (S.put True) >> S.liftIO (testStrLn (printf "[FAILED] \"%s\"; Found { %s } ; Expected { %s }" name (show found) (show expected))) | |
| passTest = S.liftIO (testStrLn (printf "[PASSED] \"%s\"" name)) | |
| runTests :: [UnitTest a] -> IO () | |
| runTests tests = do | |
| (_, failed) <- S.runStateT (F.sequenceA_ tests) False | |
| if failed then testStrLn "Some tests FAILED" else testStrLn "All tests PASSED" | |
| -- example: | |
| -- https://www.hackerrank.com/challenges/time-conversion | |
| tests = [test "Midnight" (to24hr (Time 12 0 0 AM)) "00:00:00", | |
| test "Noon" (to24hr (Time 12 0 0 PM)) "12:00:00", | |
| test "Normal AM" (to24hr (Time 5 24 23 AM)) "05:24:23", | |
| test "Normal PM" (to24hr (Time 7 22 08 PM)) "19:22:08"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment