nick8325 / quickcheck

Automatic testing of Haskell programs.
Other
713 stars 119 forks source link

Tweak Float and Double Arbitrary Instances. #297

Closed phadej closed 2 years ago

phadej commented 4 years ago

Tries to address comments in https://github.com/nick8325/quickcheck/issues/295 and https://github.com/nick8325/quickcheck/pull/296

Doesn't change how arbitrarySizedFractional works. Now it is only used for (Ratio a) instance.

Also two properties which should fail everytime: the Double generator has a chance of generating same values, and it also hits values which break addition associativity.


My take on #295

cartazio commented 4 years ago

Looks like at least a nice starting point. Cc @Bodigrim

cartazio commented 4 years ago

Thx!

cartazio commented 4 years ago

Does this code generate negative zero?

phadej commented 4 years ago

Does this code generate negative zero?

It doesn't. I'll add it.

cartazio commented 4 years ago

I’d also advocate for plus and minus infinity. Since those sometimes have semantic meaning. Ish. And or the smallest and largest magnitude finite floats.

Nans don’t matter / should be runtime exceptions ;)

phadej commented 4 years ago

With infinities you easily get yourself into NaN-land, at which point almost every property is false. That feels like arbitrary choice, who's life you want to make easier/harder

(1/0.0 :: Double) - (1/0.0 :: Double)
NaN
cartazio commented 4 years ago

Touche. Either way nontrivial chance of zeros or duplicates will go a long way!

For a lotta applied math codes, random all distinct numbers in floating point guarantees the code will work almost too well. :)

On Sat, May 16, 2020 at 4:11 PM Oleg Grenrus notifications@github.com wrote:

With infinities you easily get yourself into NaN-land, at which point almost every property is false. That feels like arbitrary choice, who's life you want to make easier/harder

  • People testing numeric code (who probably know what they are doing)
  • People with some Doubles in their business data types (who probably know less well, to not use Double there).

(1/0.0 :: Double) - (1/0.0 :: Double)NaN

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/nick8325/quickcheck/pull/297#issuecomment-629699926, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAABBQVALCS7RF3DTFVSOK3RR3XODANCNFSM4NDA2HAQ .

cartazio commented 4 years ago

i emphatically support this change, it seems like it will help MANY people

phadej commented 4 years ago

Resolved conflict.

phadej commented 4 years ago

@nick8325 ping

nick8325 commented 2 years ago

Sorry for my extremely slow response to this patch - it looks really useful! Merged now.