Skip to content

Instantly share code, notes, and snippets.

@gigasquid
Created February 13, 2013 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gigasquid/4941951 to your computer and use it in GitHub Desktop.
Save gigasquid/4941951 to your computer and use it in GitHub Desktop.
Nasa Countdown in Haskell with HUnit - from Cincy FP
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