Commits

Bryan O'Sullivan committed ea8af40

Cover both Text and ByteString versions of toShortest.

Comments (0)

Files changed (2)

double-conversion.cabal

   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,

tests/Properties.hs

-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)
        ]