Skip to content
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

Test failure with QuickCheck 2.14.3 #87

Closed
felixonmars opened this issue Jun 4, 2023 · 2 comments · Fixed by #89
Closed

Test failure with QuickCheck 2.14.3 #87

felixonmars opened this issue Jun 4, 2023 · 2 comments · Fixed by #89

Comments

@felixonmars
Copy link

      Seconds truncate is Nano truncate:                                    FAIL
        *** Failed! Falsified (after 5 tests):
        -1.000000000
        Use --quickcheck-replay=391660 to reproduce.
        Use -p '/Seconds truncate is Nano truncate/' to rerun this test only.

It passes with QuickCheck 2.14.2 or older versions, with everything else unchanged.

@CetinSert
Copy link
Member

Please open an issue with QuickCheck and link to this issue there.

@berberman
Copy link

I investigated a bit and found that the test "Seconds truncate is Nano truncate" was broken by nick8325/quickcheck@f295094. Previously, arbitrarySizedFractional would generate high precision fractions like -3.0920546619346832e-12, 5.581150636052472e-11, etc. But for now, since the range of denominator is bounded by max 1 n, it's likely that the generated fractions turn out to be integers like -1.00000, 2.00000, etc. However, I found that the test

clock/tests/test.hs

Lines 97 to 100 in 504a3f5

, QuickCheck.testProperty "Seconds truncate is Nano truncate" $ \(x :: Nano) ->
let nano = truncate x :: Integer
seconds = truncate (realToFrac x :: Seconds)
in nano == seconds

actually fails for all negative integers. For example, let x = -5. According to the definition of properFraction for Seconds:

instance RealFrac Seconds where
properFraction (Seconds (TimeSpec s ns))
| s >= 0 = (fromIntegral s, Seconds $ TimeSpec 0 ns)
| otherwise = (fromIntegral (s+1), Seconds $ TimeSpec (-1) ns)

properFraction (realToFrac x :: Seconds) converts {sec = -5, nsec = 0} to (-4, {sec = -1, nsec = 0}), and then truncate returns the integral part -4, indicating that the integer nearest -5 is -4, instead of -5. Thus, I think this is a bug reveled by the new version of QuickCheck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants