-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Infinities as floating point range endpoints #68
Changes from all commits
d7c0462
7c48e36
a18a273
9baee56
ef90a0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,13 +130,21 @@ integralSpec px = | |
|
||
floatingSpec :: | ||
forall a. | ||
(SC.Serial IO a, Typeable a, Num a, Ord a, Random a, UniformRange a, Show a) | ||
(SC.Serial IO a, Typeable a, Num a, Ord a, Random a, UniformRange a, Read a, Show a) | ||
=> Proxy a -> TestTree | ||
floatingSpec px = | ||
testGroup ("(" ++ showsType px ")") | ||
[ SC.testProperty "uniformR" $ seeded $ Range.uniformRangeWithin px | ||
, testCase "r = +inf, x = 0" $ positiveInf @?= fst (uniformR (0, positiveInf) (ConstGen 0)) | ||
, testCase "r = +inf, x = 1" $ positiveInf @?= fst (uniformR (0, positiveInf) (ConstGen 1)) | ||
, testCase "l = -inf, x = 0" $ negativeInf @?= fst (uniformR (negativeInf, 0) (ConstGen 0)) | ||
, testCase "l = -inf, x = 1" $ negativeInf @?= fst (uniformR (negativeInf, 0) (ConstGen 1)) | ||
-- TODO: Add more tests | ||
] | ||
where | ||
positiveInf, negativeInf :: a | ||
positiveInf = read "Infinity" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would write positiveInf = 1 / 0 then you don't need the Read constraint but I don't know if this is good practice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is certainly much faster. Probably even constant-folded There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Considering that it is in a test suite, I don't think performance matters much. Using |
||
negativeInf = read "-Infinity" | ||
|
||
runSpec :: TestTree | ||
runSpec = testGroup "runStateGen_ and runPrimGenIO_" | ||
|
@@ -165,3 +173,9 @@ data Foo | |
| Final () | ||
deriving (Eq, Ord, Show, Generic, Finite, Uniform) | ||
instance Monad m => Serial m Foo | ||
|
||
newtype ConstGen = ConstGen Word64 | ||
|
||
instance RandomGen ConstGen where | ||
genWord64 g@(ConstGen c) = (c, g) | ||
split g = (g, g) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test fails without the additional guards in
uniformRM
, and passes when they are added.