1
exercism fetch haskell minesweeper

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import Data.Foldable     (for_)
import Test.Hspec        (Spec, describe, it, shouldBe)
import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith)

import Minesweeper (annotate)

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

specs :: Spec
specs = describe "annotate" $ for_ cases test
  where

    test (description, board) = it description assertion
      where
        assertion  = annotate (clearBoard board) `shouldBe` board
        clearBoard = map (map mineOrSpace)
        mineOrSpace '*' = '*'
        mineOrSpace  _  = ' '

    cases = [ ("no rows", [] )

            , ("no columns", [ "" ] )

            , ("no mines", [ "   "
                           , "   "
                           , "   " ] )

            , ("board with only mines", [ "***"
                                        , "***"
                                        , "***" ] )

            , ("mine surrounded by spaces", [ "111"
                                            , "1*1"
                                            , "111" ] )

            , ("space surrounded by mines", [ "***"
                                            , "*8*"
                                            , "***" ] )

            , ("horizontal line", [ "1*2*1" ] )

            , ("horizontal line, mines at edges", [ "*1 1*" ] )

            , ("vertical line", [ "1"
                                , "*"
                                , "2"
                                , "*"
                                , "1" ] )

            , ("vertical line, mines at edges", [ "*"
                                                , "1"
                                                , " "
                                                , "1"
                                                , "*" ] )

            , ("cross", [ " 2*2 "
                        , "25*52"
                        , "*****"
                        , "25*52"
                        , " 2*2 " ] )

            , ("large board", [ "1*22*1"
                              , "12*322"
                              , " 123*2"
                              , "112*4*"
                              , "1*22*2"
                              , "111111" ] )
            ]