Ticket #2065 (closed bug: fixed)

Opened 5 years ago

Last modified 5 years ago

QuickCheck: coarbitrary for Double and Float is broken.

Reported by: jedbrown Owned by:
Priority: normal Milestone:
Component: libraries (other) Version: 6.8.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

The coarbitrary definition for these types is incompatible with the way they are generated. First, decodeFloat produces a pair (Integer, Int), then the Integer is manipulated to be positive and then coerced to an Int using fromInteger and passed to variant. Even 'simple' values of type Double and Float (as produced by arbitrary) can have huge significands. In the case of Double, the resulting Int can be negative due to truncation. This causes an exception when variant uses '(!!)' with a negative index. Huge positive values are just as bad since they cause a space leak while evaluating variant with a huge index (and tend not to terminate due to memory constraints). An obvious fix is to use the QuickCheck?-2 approach.

To reproduce, import Test.QuickCheck? and Text.Show.Functions, then run:

verboseCheck ((\f a -> f a == f a) :: (Float -> Int) -> Float -> Bool)

This should pass a few tests before finding a space leak.

verboseCheck ((\f a -> f a == f a) :: (Double -> Int) -> Double -> Bool)

This should also pass a few, then it may find a space leak, or it may error with:

*** Exception: Prelude.(!!): negative index

Note that QuickCheck?-2 has no problems here.

Attachments

variant-bug.patch Download (2.4 KB) - added by patperry 5 years ago.
Patch that fixes the bug

Change History

Changed 5 years ago by igloo

  • status changed from new to closed
  • difficulty set to Unknown
  • resolution set to fixed

Thanks for the report. However, if this works in QuickCheck 2 then I think we should consider this bug closed. If it is important to you that it works in QC1, then I think your best bet is to submit a patch through the  library submissions process.

Changed 5 years ago by patperry

Patch that fixes the bug

Changed 5 years ago by simonmar

  • architecture changed from Multiple to Unknown/Multiple

Changed 5 years ago by simonmar

  • os changed from Multiple to Unknown/Multiple
Note: See TracTickets for help on using tickets.