Frank like withdrawing a message after he sent it on a chatting channel. If the message is useful, Frank will withdraw it, while he will leave the unimportant message along.
So we need to write a bot to prevent Frank from withdrawing a message. If Frank withdraw something after saying it:
Frank: This message is useful!
Frank: Recalled a message
the bot should display(return) what Frank withdraw:
bot: Frank: This message is useful!
If Frank say something without withdrawing it:
Frank: I will not withdraw this message
the bot should not display anything:
module Kata (bot) where
bot :: String -> String
bot txt
| length msgs < 2 = ""
| head msgs == "Frank: Recalled a message" = "bot: " ++ (msgs !! 1)
| otherwise = ""
where msgs = reverse $ lines txt
module ExampleSpec where
import Test.Hspec
import Kata (bot)
-- `spec` of type `Spec` must exist
spec :: Spec
spec = do
describe "Test for bot" $ do
it "withdrawing" $ do
bot "Frank: Ho ho ho!\nFrank: Recalled a message"
`shouldBe` "bot: Frank: Ho ho ho!"
bot "Frank: \nFrank: Recalled a message"
`shouldBe` "bot: Frank: "
bot "Frank: Frank: Ha ha !\nFrank: Recalled a message"
`shouldBe` "bot: Frank: Frank: Ha ha !"
bot "Frank: Ho ho ho!\nFrank: Frank: Ha ha !\nFrank: Recalled a message"
`shouldBe` "bot: Frank: Frank: Ha ha !"
it "normal" $ do
bot "Frank: Ha ha!" `shouldBe` ""
bot "Frank: Ho ho ho!\nFrank: Ha ha!" `shouldBe` ""
-- the following line is optional for 8.2
main = hspec spec