Sorry for a newbie question, but how can I redefine Arbitrary Double
to produce +/- infinity and NaNs as well as usual doubles? And how to use my version of this Arbitrary
?
Asked
Active
Viewed 81 times
1
-
1I see two ways to do this: You can define a `newtype` over `Double` and write a custom `Arbitrary` instance for that. Or you can explicitly pass a `Gen Double` to your test function(s). – MathematicalOrchid Feb 17 '15 at 11:05
1 Answers
1
You don't need to make a new Arbitrary
instance just to make a custom Gen
erator for a type. You can just create it as a free-standing definition:
evilDouble :: Gen Double
evilDouble = oneOf [ weirdDouble, arbitrary ]
where
weirdDouble = error "This is where you generate inf and NaN values"
and then use it explicitly with QuickCheck's forAll
:
prop_foo = forAll evilDouble $ \x -> abs (foo x - 123) < 0.1

Cactus
- 27,075
- 9
- 69
- 149
-
1Here's a hacky implementation I wrote: https://github.com/nick8325/quickcheck/issues/98#issuecomment-722616360 – James Cook Nov 05 '20 at 20:16