Skip to content

Instantly share code, notes, and snippets.

@DimaD
Last active December 22, 2015 16:19
Show Gist options
  • Save DimaD/6498898 to your computer and use it in GitHub Desktop.
Save DimaD/6498898 to your computer and use it in GitHub Desktop.
-- Modified tests. Scroll down for original version
import Test.HUnit (Assertion, (@=?), runTestTT, Test(..))
import Control.Monad (void)
import Bob (responseFor)
data Reaction = Indifference | Chill | Agreement | Harm
expectedTextFor Indifference = "Whatever."
expectedTextFor Chill = "Woah, chill out!"
expectedTextFor Agreement = "Sure."
expectedTextFor Harm = "Fine. Be that way!"
shouldRespondWith :: Reaction -> String -> Assertion
shouldRespondWith expectedReaction probe = (expectedTextFor expectedReaction) @=? (responseFor probe)
-- syntactic sugar
to = id
inCaseOf :: String -> Assertion -> Test
inCaseOf label assertion = TestLabel label (TestCase assertion)
respondsToTests :: [Test]
respondsToTests =
[ inCaseOf "gibberish" $
shouldRespondWith Indifference (to "Tom-ay-to, tom-aaaah-to.")
, inCaseOf "shouts" $
shouldRespondWith Chill (to "WATCH OUT!")
, inCaseOf "questions" $
shouldRespondWith Agreement (to "Does this cryogenic chamber make me look fat?")
, inCaseOf "forceful talking" $
shouldRespondWith Indifference (to "Let's go make out behind the gym!")
, inCaseOf "acronyms" $
shouldRespondWith Indifference (to "It's OK if you don't want to go to the DMV.")
, inCaseOf "forceful questions" $
shouldRespondWith Chill (to "WHAT THE HELL WERE YOU THINKING?")
, inCaseOf "shouting with special characters" $
shouldRespondWith Chill (to "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!")
, inCaseOf "shouting numbers" $
shouldRespondWith Chill (to "1, 2, 3 GO!")
, inCaseOf "shouting with no exclamation mark" $
shouldRespondWith Chill (to "I HATE YOU")
, inCaseOf "statement containing question mark" $
shouldRespondWith Indifference (to "Ending with ? means a question.")
, inCaseOf "silence" $
shouldRespondWith Harm (to "")
, inCaseOf "prolonged silence" $
shouldRespondWith Harm (to " ")
, inCaseOf "questioned nonsence" $
shouldRespondWith Agreement (to ":) ?")
, inCaseOf "multiple-line statement containing question mark" $
shouldRespondWith Indifference (to "\nDoes this cryogenic chamber make me look fat? \nno")
, inCaseOf "all whitespace is silence" $
shouldRespondWith Harm (to"\n\r \t\v\xA0\x2002") -- \xA0 No-break space, \x2002 En space
]
main :: IO ()
main = void (runTestTT (TestList respondsToTests))
-- Original version of tests
import Test.HUnit (Assertion, (@=?), runTestTT, Test(..))
import Control.Monad (void)
import Bob (responseFor)
testCase :: String -> Assertion -> Test
testCase label assertion = TestLabel label (TestCase assertion)
test_respondsToSomething :: Assertion
test_respondsToSomething =
"Whatever." @=? responseFor "Tom-ay-to, tom-aaaah-to."
test_respondsToShouts :: Assertion
test_respondsToShouts =
"Woah, chill out!" @=? responseFor "WATCH OUT!"
test_respondsToQuestions :: Assertion
test_respondsToQuestions =
"Sure." @=? responseFor "Does this cryogenic chamber make me look fat?"
test_respondsToForcefulTalking :: Assertion
test_respondsToForcefulTalking =
"Whatever." @=? responseFor "Let's go make out behind the gym!"
test_respondsToAcronyms :: Assertion
test_respondsToAcronyms =
"Whatever." @=? responseFor "It's OK if you don't want to go to the DMV."
test_respondsToForcefulQuestions :: Assertion
test_respondsToForcefulQuestions =
"Woah, chill out!" @=? responseFor "WHAT THE HELL WERE YOU THINKING?"
test_respondsToShoutingWithSpecialCharacters :: Assertion
test_respondsToShoutingWithSpecialCharacters =
"Woah, chill out!" @=? responseFor (
"ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!")
test_respondsToShoutingNumbers :: Assertion
test_respondsToShoutingNumbers =
"Woah, chill out!" @=? responseFor "1, 2, 3 GO!"
test_respondsToShoutingWithNoExclamationMark :: Assertion
test_respondsToShoutingWithNoExclamationMark =
"Woah, chill out!" @=? responseFor "I HATE YOU"
test_respondsToStatementContainingQuestionMark :: Assertion
test_respondsToStatementContainingQuestionMark =
"Whatever." @=? responseFor "Ending with ? means a question."
test_respondsToSilence :: Assertion
test_respondsToSilence =
"Fine. Be that way!" @=? responseFor ""
test_respondsToProlongedSilence :: Assertion
test_respondsToProlongedSilence =
"Fine. Be that way!" @=? responseFor " "
test_respondsToNonLettersWithQuestion :: Assertion
test_respondsToNonLettersWithQuestion =
"Sure." @=? responseFor ":) ?"
test_respondsToMultipleLineQuestions :: Assertion
test_respondsToMultipleLineQuestions =
"Whatever." @=? responseFor "\nDoes this cryogenic chamber make me look fat? \nno"
test_respondsToOtherWhitespace :: Assertion
test_respondsToOtherWhitespace =
"Fine. Be that way!" @=? responseFor "\n\r \t\v\xA0\x2002" -- \xA0 No-break space, \x2002 En space
respondsToTests :: [Test]
respondsToTests =
[ testCase "something" test_respondsToSomething
, testCase "shouts" test_respondsToShouts
, testCase "questions" test_respondsToQuestions
, testCase "forceful talking" test_respondsToForcefulTalking
, testCase "acronyms" test_respondsToAcronyms
, testCase "forceful questions" test_respondsToForcefulQuestions
, testCase "shouting with special characters"
test_respondsToShoutingWithSpecialCharacters
, testCase "shouting numbers" test_respondsToShoutingNumbers
, testCase "shouting with no exclamation mark"
test_respondsToShoutingWithNoExclamationMark
, testCase "statement containing question mark"
test_respondsToStatementContainingQuestionMark
, testCase "silence" test_respondsToSilence
, testCase "prolonged silence" test_respondsToProlongedSilence
, testCase "questioned nonsence" test_respondsToNonLettersWithQuestion
, testCase "multiple-line statement containing question mark"
test_respondsToMultipleLineQuestions
, testCase "all whitespace is silence" test_respondsToOtherWhitespace
]
main :: IO ()
main = void (runTestTT (TestList respondsToTests))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment