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 in test_frac.py for function float_to_twelths_frac #14

Open
mhucka opened this issue Sep 28, 2024 · 0 comments
Open

Test failure in test_frac.py for function float_to_twelths_frac #14

mhucka opened this issue Sep 28, 2024 · 0 comments

Comments

@mhucka
Copy link
Contributor

mhucka commented Sep 28, 2024

With Python 3.10.0 and 3.12.5 on macOS 14.7, running pytest produces a failure in test_frac.py:

    def test_float_to_twelths_frac() -> None:
        with pytest.raises(ValueError):
            u.float_to_twelths_frac(1.0 / 24)
        with pytest.raises(ValueError):
            u.float_to_twelths_frac(1.0 / 7)
        with pytest.raises(ValueError):
            u.float_to_twelths_frac(1.0 / 5)
        with pytest.raises(ValueError):
            u.float_to_twelths_frac(1.0 / 11)
        with pytest.raises(ValueError):
            u.float_to_twelths_frac(1.0 / 13)

        assert u.float_to_twelths_frac(0) == frac(0)
        assert u.float_to_twelths_frac(502) == frac(502)
        assert u.float_to_twelths_frac(1.0 / 12) == frac(denom=12)
        assert u.float_to_twelths_frac(-1.0 / 12) == frac(-1, 12)
        assert u.float_to_twelths_frac(501.0 / 3) == frac(167)
        assert u.float_to_twelths_frac(502.0 / 3) == frac(502, 3)

        # Precision.
        assert u.float_to_twelths_frac((1 << 55) + 1) == frac((1 << 55) + 1)
>       assert u.float_to_twelths_frac(float(1 << 55) / 3.0) == frac(1 << 55, 3)

test/cython/test_frac.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tunits/core/cython/frac.pyx:83: in tunits_core.float_to_twelths_frac
    cpdef frac float_to_twelths_frac(a) except *:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

>   raise ValueError("Not a twelfth.")
E   ValueError: Not a twelfth.

tunits/core/cython/frac.pyx:91: ValueError

This is using a fresh pyenv virtual environment, then installing dependencies using

pip install -r dev_tools/dev.env.txt

followed by running pytest. Stopping in the test function and inspecting the values, it appears that the difference between values for the case involving float(1 << 55 / 3.0) is indeed greater than the absolute tolerance specified.

I don't experience this on Linux.

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

No branches or pull requests

1 participant