|
1 | 1 | {-# OPTIONS_GHC -fno-warn-type-defaults #-}
|
2 | 2 | {-# LANGUAGE RecordWildCards #-}
|
3 | 3 |
|
4 |
| -import Control.Monad (unless) |
5 |
| -import System.Exit (exitFailure) |
| 4 | +import Data.Foldable (for_) |
| 5 | +import Test.Hspec (Spec, describe, it, shouldBe) |
| 6 | +import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith) |
6 | 7 |
|
7 |
| -import Test.HUnit |
8 |
| - ( (~:) |
9 |
| - , (~=?) |
10 |
| - , Counts (failures, errors) |
11 |
| - , Test (TestList) |
12 |
| - , runTestTT |
13 |
| - ) |
| 8 | +-- base >= 4.8 re-exports Control.Applicative.(<$>). |
| 9 | +import Control.Applicative -- This is only need for <$>, if GHC < 7.10. |
| 10 | +import Prelude -- This trick avoids a warning if GHC >= 7.10. |
14 | 11 |
|
15 | 12 | import Hamming (distance)
|
16 | 13 |
|
17 | 14 | main :: IO ()
|
18 |
| -main = do |
19 |
| - counts <- runTestTT tests |
20 |
| - unless (failures counts == 0 && errors counts == 0) exitFailure |
| 15 | +main = hspecWith defaultConfig {configFastFail = True} specs |
21 | 16 |
|
22 |
| -tests :: Test |
23 |
| -tests = TestList $ map test cases |
| 17 | +specs :: Spec |
| 18 | +specs = describe "hamming" $ |
| 19 | + describe "distance" $ for_ cases test |
24 | 20 | where
|
25 |
| - test (Case {..}) = description |
26 |
| - ~: fmap fromIntegral (distance strand1 strand2) |
27 |
| - ~=? expected |
28 | 21 |
|
29 |
| --- Test cases adapted from x-common/hamming.json from 2016-03-13. |
| 22 | + test Case{..} = it description assertion |
| 23 | + where |
| 24 | + assertion = expression `shouldBe` fromIntegral <$> expected |
| 25 | + expression = distance strand1 strand2 |
| 26 | + |
| 27 | +-- Test cases adapted from `exercism/x-common/hamming.json` on 2016-07-12. |
| 28 | + |
30 | 29 | data Case = Case { description :: String
|
31 | 30 | , strand1 :: String
|
32 | 31 | , strand2 :: String
|
|
0 commit comments