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

Fix floating point errors in PDFs #717

Merged
merged 4 commits into from
Nov 10, 2021

Conversation

zakpatterson
Copy link
Collaborator

@zakpatterson zakpatterson commented Nov 10, 2021

What kind of change does this PR introduce? (delete not applicable)

  • Bugfix
  • Refactor

Rounding formatting errors are present in PDF fields with numeric values. .30000000004 style errors as well as string formatting such as 123.6 are also present.

This also refactors things somewhat so we can provide a different downloader in testing. This will also be useful in #686 where pdfs are downloaded from ustaxes.org instead of from the testing machine file system.

See 611de2a for output from failing test.

A file downloader implementation is going to vary between
desktop, web, and test implementations. So I've refactored
components that include downloading a PDF to allow this
dependency to be injected.
@codecov-commenter
Copy link

codecov-commenter commented Nov 10, 2021

Codecov Report

Merging #717 (59c124b) into master (2ed5152) will increase coverage by 4.43%.
The diff coverage is 50.00%.

❗ Current head 59c124b differs from pull request most recent head 9e36050. Consider uploading reports for the commit 9e36050 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #717      +/-   ##
==========================================
+ Coverage   65.51%   69.94%   +4.43%     
==========================================
  Files         112      113       +1     
  Lines        3744     3767      +23     
  Branches      581      584       +3     
==========================================
+ Hits         2453     2635     +182     
+ Misses       1278     1118     -160     
- Partials       13       14       +1     
Impacted Files Coverage Δ
src/components/createPDF.tsx 3.22% <0.00%> (-0.11%) ⬇️
src/irsForms/Form.ts 100.00% <ø> (ø)
src/stateForms/Form.ts 100.00% <ø> (ø)
src/stateForms/index.ts 52.63% <10.00%> (-2.93%) ⬇️
src/pdfFiller/pdfHandler.ts 30.76% <50.00%> (+25.36%) ⬆️
src/stateForms/IL/IL1040ScheduleILEIC.ts 71.19% <50.00%> (+0.05%) ⬆️
src/irsForms/index.ts 57.89% <57.89%> (+57.89%) ⬆️
src/components/Menu.tsx 93.75% <100.00%> (+0.41%) ⬆️
src/pdfFiller/Fill.ts 100.00% <100.00%> (ø)
src/stateForms/IL/IL1040.ts 83.95% <100.00%> (+0.06%) ⬆️
... and 18 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2ed5152...9e36050. Read the comment docs.

Produces failed test:

    Shrunk 0 time(s)
    Got error: Error: expect(received).toHaveLength(expected)

    Expected length: 0
    Received length: 1
    Received array:  [["2020 Schedule 8812 (Form 1040)", [[13, ["topmostSubform[0].Page1[0].f1_12[0]", "2946387.6"]]]]]

    Stack trace: Error: expect(received).toHaveLength(expected)

    Expected length: 0
    Received length: 1
    Received array:  [["2020 Schedule 8812 (Form 1040)", [[13, ["topmostSubform[0].Page1[0].f1_12[0]", "2946387.6"]]]]]

      87 |     await fc.assert(
      88 |       fc.asyncProperty(arbitraries.information, async (info) => {
    > 89 |         expect(await testEveryField(info, findBadDecimalFormat)).toHaveLength(0)
         |                                                                  ^
      90 |       }),
      91 |       {
      92 |         interruptAfterTimeLimit: 100 * 1000 // 100 seconds

      at src/tests/pdfFiller/pdfHandler.test.ts:89:66
      at AsyncProperty.run (node_modules/fast-check/lib/check/property/AsyncProperty.generic.js:41:28)
      at asyncRunIt (node_modules/fast-check/lib/check/runner/Runner.js:24:21)
      at Object.<anonymous> (src/tests/pdfFiller/pdfHandler.test.ts:87:5)
      Hint: Enable verbose mode in order to have the list of all failing values encountered during the run
      at asyncThrowIfFailed (node_modules/fast-check/lib/check/runner/utils/RunDetailsFormatter.js:133:11)

Fix comment
Either two decimal places or zero

Refactor states forms, same numeric implementation
@zakpatterson zakpatterson changed the title Fix floating point errors Fix floating point errors in PDFs Nov 10, 2021
Copy link
Collaborator

@thegrims thegrims left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@zakpatterson zakpatterson merged commit bf9bc8c into ustaxes:master Nov 10, 2021
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.

3 participants