diff --git a/exercises/minesweeper/package.yaml b/exercises/minesweeper/package.yaml index 2c7bf548e..ad057c5a7 100644 --- a/exercises/minesweeper/package.yaml +++ b/exercises/minesweeper/package.yaml @@ -17,4 +17,4 @@ tests: source-dirs: test dependencies: - minesweeper - - HUnit + - hspec diff --git a/exercises/minesweeper/test/Tests.hs b/exercises/minesweeper/test/Tests.hs index d19b1920d..2011caec0 100644 --- a/exercises/minesweeper/test/Tests.hs +++ b/exercises/minesweeper/test/Tests.hs @@ -1,60 +1,52 @@ -import Test.HUnit (Assertion, (@=?), runTestTT, Test(..), Counts(..)) -import System.Exit (ExitCode(..), exitWith) +import Data.Foldable (for_) +import Test.Hspec (Spec, describe, it, shouldBe) +import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith) + import Minesweeper (annotate) -exitProperly :: IO Counts -> IO () -exitProperly m = do - counts <- m - exitWith $ if failures counts /= 0 || errors counts /= 0 then ExitFailure 1 else ExitSuccess +main :: IO () +main = hspecWith defaultConfig {configFastFail = True} specs -testCase :: String -> Assertion -> Test -testCase label assertion = TestLabel label (TestCase assertion) +specs :: Spec +specs = describe "minesweeper" $ + describe "annotate" $ for_ cases test + where -main :: IO () -main = exitProperly $ runTestTT $ TestList - [ TestList minesweeperTests ] - -clean :: [String] -> [String] -clean = map (map mineOrSpace) - where mineOrSpace '*' = '*' - mineOrSpace _ = ' ' - -check :: [String] -> Assertion -check board = board @=? annotate (clean board) - -minesweeperTests :: [Test] -minesweeperTests = - [ testCase "zero size board" $ do - check [] - , testCase "empty board" $ do - check [ " " - , " " - , " " - ] - , testCase "board full of mines" $ do - check [ "***" - , "***" - , "***" - ] - , testCase "surrounded" $ do - check [ "***" - , "*8*" - , "***" - ] - , testCase "horizontal line" $ do - check [ "1*2*1" ] - , testCase "vertical line" $ do - check [ "1" - , "*" - , "2" - , "*" - , "1" - ] - , testCase "cross" $ do - check [ " 2*2 " - , "25*52" - , "*****" - , "25*52" - , " 2*2 " - ] - ] + -- As of 2016-08-09, there was no reference file + -- for the test cases in `exercism/x-common`. + + test (description, board) = it description assertion + where + assertion = annotate (clearBoard board) `shouldBe` board + clearBoard = map (map mineOrSpace) + mineOrSpace '*' = '*' + mineOrSpace _ = ' ' + + cases = [ ("zero size board" , [] ) + + , ("empty board" , [ " " + , " " + , " " ] ) + + , ("board full of mines" , [ "***" + , "***" + , "***" ] ) + + , ("surrounded", [ "***" + , "*8*" + , "***" ] ) + + , ("horizontal line", [ "1*2*1" ] ) + + , ("vertical line", [ "1" + , "*" + , "2" + , "*" + , "1" ] ) + + , ("cross", [ " 2*2 " + , "25*52" + , "*****" + , "25*52" + , " 2*2 " ] ) + ]