Created
February 13, 2013 03:06
-
-
Save gigasquid/4941951 to your computer and use it in GitHub Desktop.
Nasa Countdown in Haskell with HUnit - from Cincy FP
This file contains 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
module Main where | |
import Test.HUnit | |
-- nasa :: Int -> [Int] -- | [] | |
nasa n = reverse [0..n] | |
-- | n <= 0 = [0] | |
-- | otherwise = n : (nasa $ n - 1) | |
-- test1 :: Test | |
test1 = TestCase (assertEqual "for (nasa 0)," [0] (nasa 0)) | |
test2 :: Test | |
test2 = TestCase (assertEqual "for (nasa 1)," [1, 0] (nasa 1)) | |
test3 :: Test | |
test3 = TestCase (assertEqual "for (nasa 1)," [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] (nasa 10)) | |
test4 :: Test | |
test4 = TestCase (assertEqual "for (nasa $ -1)," [] (nasa $ -1)) | |
tests :: Test | |
tests = TestList [TestLabel "test1" test1, | |
TestLabel "test2" test2, | |
TestLabel "test3" test3, | |
TestLabel "test4" test4] | |
main :: IO Counts | |
main = do runTestTT tests |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment