diff --git a/test/Test/Hspec/ExpectationsSpec.hs b/test/Test/Hspec/ExpectationsSpec.hs index 7162eea..eb2860f 100644 --- a/test/Test/Hspec/ExpectationsSpec.hs +++ b/test/Test/Hspec/ExpectationsSpec.hs @@ -1,4 +1,5 @@ {-# LANGUAGE CPP #-} + #if MIN_VERSION_base(4,8,1) #define HAS_SOURCE_LOCATIONS {-# LANGUAGE ImplicitParams #-} @@ -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 :: Float) + + it "fails if arguments are not equal" $ do + (1.0 `shouldBe` (2.0 :: Float)) `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 :: Float) + + it "succeeds for large values near one another" $ do + 1e20 `shouldBeNear` (1e20 + 1 :: Float) + + it "fails for large values not near each other" $ do + (1e20 `shouldBeNear` (1.1e20 :: Float)) `shouldThrow` expectationFailed "expected: 1.1e20\n but got: 1.0e20" + describe "shouldSatisfy" $ do it "succeeds if value satisfies predicate" $ do "" `shouldSatisfy` null