File: Properties.hs

package info (click to toggle)
haskell-double-conversion 2.0.5.0%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 152 kB
  • sloc: haskell: 611; cpp: 340; ansic: 31; makefile: 6
file content (22 lines) | stat: -rw-r--r-- 818 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
import Test.Framework (Test, defaultMain, testGroup)
import Test.Framework.Providers.QuickCheck2 (testProperty)
import qualified Data.ByteString.Char8 as B
import qualified Data.Double.Conversion.Convertable as C
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 . C.toShortest)
  , testProperty "t_shortest" $ shortest (T.unpack . C.toShortest)
  ]

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