1
exercism fetch haskell secret-handshake

test/Tests.hs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import Test.Hspec        (Spec, it, shouldBe)
import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith)

import SecretHandshake (handshake)

main :: IO ()
main = hspecWith defaultConfig {configFastFail = True} specs

specs :: Spec
specs = do

    it "wink for 1" $
      handshake (1 :: Int) `shouldBe` ["wink"]

    it "double blink for 10" $
      handshake (2 :: Int) `shouldBe` ["double blink"]

    it "close your eyes for 100" $
      handshake (4 :: Int) `shouldBe` ["close your eyes"]

    it "jump for 1000" $
      handshake (8 :: Int) `shouldBe` ["jump"]

    it "combine two actions" $
      handshake (3 :: Int) `shouldBe` ["wink", "double blink"]

    it "reverse two actions" $
      handshake (19 :: Int) `shouldBe` ["double blink", "wink"]

    it "reversing one action gives the same action" $
      handshake (24 :: Int) `shouldBe` ["jump"]

    it "reversing no actions still gives no actions" $
      handshake (16 :: Int) `shouldBe` []

    it "all possible actions" $
      handshake (15 :: Int) `shouldBe` ["wink", "double blink", "close your eyes", "jump"]

    it "reverse all possible actions" $
      handshake (31 :: Int) `shouldBe` ["jump", "close your eyes", "double blink", "wink"]

    it "do nothing for zero" $
      handshake (0 :: Int) `shouldBe` []