Skip to content

Test failure in test_frac.py for function float_to_twelths_frac #14

@mhucka

Description

@mhucka

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions