Skip to content

Commit

Permalink
Add tests for shouldBeNear
Browse files Browse the repository at this point in the history
  • Loading branch information
erikd committed Sep 6, 2016
1 parent 96b8fb8 commit dec8922
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/Test/Hspec/ExpectationsSpec.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE CPP #-}

#if MIN_VERSION_base(4,8,1)
#define HAS_SOURCE_LOCATIONS
{-# LANGUAGE ImplicitParams #-}
Expand Down Expand Up @@ -43,6 +44,22 @@ spec = do
it "fails if arguments are not equal" $ do
("foo" `shouldBe` "bar") `shouldThrow` expectationFailed "expected: \"bar\"\n but got: \"foo\""

describe "shouldBeNear" $ do
it "succeeds if arguments are equal" $ do
1.23456789 `shouldBeNear` 1.23456789

it "fails if arguments are not equal" $ do
(1.0 `shouldBe` 2.0) `shouldThrow` expectationFailed "expected: 2.0\n but got: 1.0"

it "succeeds if one argument is zero and the other less than epsilon" $ do
0.0 `shouldBeNear` -1e-16

it "succeeds for large values near one another" $ do
1e20 `shouldBeNear` (1e20 + 1)

it "fails for large values not near each other" $ do
(1e20 `shouldBeNear` 1.1e20) `shouldThrow` expectationFailed "expected: 1.1e20\n but got: 1.0e20"

describe "shouldSatisfy" $ do
it "succeeds if value satisfies predicate" $ do
"" `shouldSatisfy` null
Expand Down

0 comments on commit dec8922

Please sign in to comment.