http-env-gen-0.0.0.0: test/Network/HTTP/Env/NumericSpec.hs
{-# LANGUAGE NumericUnderscores #-}
module Network.HTTP.Env.NumericSpec (spec) where
import Data.Word (Word64)
import Network.HTTP.Env.Numeric
import Test.Syd
spec :: Spec
spec = do
describe "integerToCount" $ do
it "reads every count from zero to the largest Int" $
map integerToCount [0, 1, toInteger (maxBound :: Int)]
`shouldBe` [Just 0, Just 1, Just 9223372036854775807]
it "reads nothing below zero or above the largest Int" $
map integerToCount [-1, toInteger (maxBound :: Int) + 1]
`shouldBe` [Nothing, Nothing]
describe "nominalDiffTimeToNanos" $ do
it "rounds to the nearest nanosecond" $
nominalDiffTimeToNanos 1.0000000016 `shouldBe` 1_000_000_002
it "holds a negative duration at zero" $
nominalDiffTimeToNanos (-1) `shouldBe` 0
it "holds a duration too long to count at the largest count" $
nominalDiffTimeToNanos 18446744073.709551616 `shouldBe` (maxBound :: Word64)
describe "nominalDiffTimeToMicros" $ do
it "rounds to the nearest microsecond" $
nominalDiffTimeToMicros 1.0000016 `shouldBe` 1_000_002
it "holds a negative duration at zero" $
nominalDiffTimeToMicros (-1) `shouldBe` 0
it "holds a duration too long to count at the largest count" $
nominalDiffTimeToMicros 9223372036854.775808 `shouldBe` (maxBound :: Int)