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

Convert tests from dict of dicts to list of tuples to avoid key overwrites #167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jagerber48
Copy link
Contributor

See #162.
tests object containing test cases for ufloat string formatting is currently a dict where keys are tuples of value/uncertainty pairs and values are dicts of format string/expected output pairs. Similar tests are chunked together under the same value/uncertainty pair. However, the same value/uncertainty pair appears multiple times in the top level dict. In this case only one grouping of tests is captured in the dict, and all others are overwritten.

To avoid this overwriting we can convert the dict of dicts into a list of tuples. In this case elements of the list are tuples whose first element is a value/uncertainty pair tuple and whose second element is a dict of format string/expected output pairs.

@jagerber48
Copy link
Contributor Author

Note on master commit 804adc running nosetests test_uncertainties.py reports OK but when using this change 1 failure is detected:

AssertionError: Incorrect representation '   3.14150+/-   0.00010' for format '>10f' of 3.1415+/-0.0001: '  3.141500+/-  0.000100' expected.

This corresponds to the >10f format in these tests at line 1568:

    tests = [  # (Nominal value, uncertainty): {format: result,...}

        # Usual float formatting, and individual widths, etc.:
        ((3.1415, 0.0001), {
            '*^+7.2f': '*+3.14*+/-*0.00**',
            '+07.2f': '+003.14+/-0000.00',  # 0 fill
            '>10f': '  3.141500+/-  0.000100',  # Width and align
            '11.3e': '  3.142e+00+/-  0.000e+00',  # Duplicated exponent
            '0.4e': '3.1415e+00+/-0.0000e+00'  # Forced double exponent
        }),
        ...

My expected output for that line is actually 3.1415+/- 0.0001 which is different than both the expected and actual output above. I guess the issue is the precision rather than width. Need to process what's going on here...

@jagerber48
Copy link
Contributor Author

jagerber48 commented Nov 20, 2022

I see, the f format defaults to a precision of 6 digits after the decimal place. For some reason ufloat formatting gives 5 digits after the decimal.
that is:

from uncertainties import ufloat
u = ufloat(3.1415, 0.0001)
print(f'{u:f}')
print(f'{3.1415:f}')
print(f'{0.0001:f}')

gives me

3.14150+/-0.00010
3.141500
0.000100

so something is funny with f format and default precision.
This is on python 3.9.13.

Not sure how this should be addressed within this PR since the PR is about changing unit test formatting. I could comment out the failing unit test so that the PR commit builds. Otherwise I could change the unit test result so that it passes, but that feels like cheating. The other alternative is wait for a fix to what's causing the unit test to fail for this PR to go through.

@jagerber48
Copy link
Contributor Author

jagerber48 commented Nov 20, 2022

Oh, sorry for the spam. I see what's going on. If no precision is supplied in the format string then PDG rules for sig figs on uncertainty sets precision, rather than python defaults. So I think the output from the program is correct, and the expected unit test result is wrong.

But even if I fix this one I think there are more unit test failures after this one that will appear one by one. @lebigot what should this PR, which unburies more unit tests, do wrt the unburied unit tests failing? Just go through or wait for resolutions?

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 this pull request may close these issues.

None yet

1 participant