-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #294 from rbasso/hspec-series
series: Rewrite tests to use hspec with fail-fast.
- Loading branch information
Showing
2 changed files
with
26 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,4 @@ tests: | |
source-dirs: test | ||
dependencies: | ||
- series | ||
- HUnit | ||
- hspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]] |