Permalink
Browse files

Cover both Text and ByteString versions of toShortest.

  • Loading branch information...
1 parent 10f90ad commit 0d8ad82cc8677e8a421d33fbc303b6a68a38a277 @bos committed Aug 10, 2011
Showing with 15 additions and 6 deletions.
  1. +2 −1 double-conversion.cabal
  2. +13 −5 tests/Properties.hs
View
@@ -103,9 +103,10 @@ test-suite tests
type: exitcode-stdio-1.0
hs-source-dirs: tests
main-is: Properties.hs
+ ghc-options: -Wall
build-depends:
- QuickCheck,
base,
+ bytestring,
double-conversion,
test-framework,
test-framework-quickcheck2,
View
@@ -1,11 +1,19 @@
-import Data.Double.Conversion.Text
-import Test.QuickCheck
-import Test.Framework (defaultMain, testGroup)
+import Test.Framework (defaultMain)
import Test.Framework.Providers.QuickCheck2 (testProperty)
+import qualified Data.ByteString.Char8 as B
+import qualified Data.Double.Conversion.ByteString as B
+import qualified Data.Double.Conversion.Text as T
import qualified Data.Text as T
-shortest a = (read . T.unpack . toShortest) a == a
+shortest :: (Double -> String) -> Double -> Double -> Bool
+shortest f a b = case read (f ab) of
+ ba | isNaN ba -> isNaN ab
+ | isInfinite ba -> isInfinite ab && signum ba == signum ab
+ | otherwise -> ba == ab
+ where ab = a / b
+main :: IO ()
main = defaultMain [
- testProperty "shortest" shortest
+ testProperty "b_shortest" $ shortest (B.unpack . B.toShortest)
+ , testProperty "t_shortest" $ shortest (T.unpack . T.toShortest)
]

0 comments on commit 0d8ad82

Please sign in to comment.