Skip to content

Instantly share code, notes, and snippets.

@jsl
Created October 9, 2013 17:40
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 jsl/6905165 to your computer and use it in GitHub Desktop.
Save jsl/6905165 to your computer and use it in GitHub Desktop.
import Test.HUnit
import Control.Applicative
data Piece = Cross | Circle deriving (Show, Eq)
isWon :: [Maybe Piece] -> Bool
isWon [] = False
isWon (x:xs)
| x == Nothing = False
| null xs = True
| x /= head xs = False
| otherwise = isWon xs
isWonTests = TestList [
"test list with Nothing" ~: False ~=? (isWon [Nothing])
, "test unequal list" ~: False ~=?
(isWon [Just Circle, Just Cross])
, "test empty list" ~: False ~=? (isWon [])
, "test won list" ~: True ~=?
(isWon [Just Circle, Just Circle])
]
main = runTestTT isWonTests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment