Skip to content

Commit

Permalink
Merge pull request #294 from rbasso/hspec-series
Browse files Browse the repository at this point in the history
series: Rewrite tests to use hspec with fail-fast.
  • Loading branch information
rbasso authored Sep 13, 2016
2 parents de651f4 + 052b913 commit 921a937
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion exercises/series/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ tests:
source-dirs: test
dependencies:
- series
- HUnit
- hspec
51 changes: 25 additions & 26 deletions exercises/series/test/Tests.hs
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
import Test.HUnit (Assertion, (@=?), runTestTT, Test(..), Counts(..))
import System.Exit (ExitCode(..), exitWith)
import Series (slices)
{-# OPTIONS_GHC -fno-warn-type-defaults #-}

exitProperly :: IO Counts -> IO ()
exitProperly m = do
counts <- m
exitWith $ if failures counts /= 0 || errors counts /= 0 then ExitFailure 1 else ExitSuccess
import Test.Hspec (Spec, describe, it, shouldBe)
import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith)

testCase :: String -> Assertion -> Test
testCase label assertion = TestLabel label (TestCase assertion)
import Series (slices)

main :: IO ()
main = exitProperly $ runTestTT $ TestList
[ TestList seriesTests ]

seriesTests :: [Test]
seriesTests =
[ testCase "slices of one" $ do
[] @=? slices 1 ""
[[0],[1],[2],[3],[4]] @=? slices 1 "01234"
, testCase "slices of two" $ do
[] @=? slices 2 ""
[[0,1]] @=? slices 2 "01"
[[0,1],[1,2],[2,3],[3,4]] @=? slices 2 "01234"
, testCase "slices of three" $ do
[] @=? slices 3 "ab"
[[0,1,2]] @=? slices 3 "012"
[[0,1,2],[1,2,3]] @=? slices 3 "0123"
]
main = hspecWith defaultConfig {configFastFail = True} specs

specs :: Spec
specs = describe "series" $ do

-- As of 2016-09-12, there was no reference file
-- for the test cases in `exercism/x-common`.

it "slices of one" $ do
slices 1 "" `shouldBe` []
slices 1 "01234" `shouldBe` [[0], [1], [2], [3], [4]]

it "slices of two" $ do
slices 2 "" `shouldBe` []
slices 2 "01" `shouldBe` [[0,1]]
slices 2 "01234" `shouldBe` [[0,1], [1,2], [2,3], [3,4]]

it "slices of three" $ do
slices 3 "ab" `shouldBe` []
slices 3 "012" `shouldBe` [[0,1,2]]
slices 3 "0123" `shouldBe` [[0,1,2], [1,2,3]]

0 comments on commit 921a937

Please sign in to comment.