File: Properties.hs

package info (click to toggle)
haskell-double-conversion 2.0.2.0%2Bds1-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 116 kB
  • sloc: haskell: 222; cpp: 108; ansic: 23; makefile: 5
file content (23 lines) | stat: -rw-r--r-- 867 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import Test.Framework (Test, defaultMain, testGroup)
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
import qualified Regressions

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

tests :: Test
tests = testGroup "Properties" [
    testProperty "b_shortest" $ shortest (B.unpack . B.toShortest)
  , testProperty "t_shortest" $ shortest (T.unpack . T.toShortest)
  ]

main :: IO ()
main = defaultMain [tests, Regressions.tests]