Skip to content

test: migrate stats/base/dists/chi/pdf to ULP-based assertions - #14323

Merged
kgryte merged 1 commit into
developfrom
kgryte/ulp-chi-pdf
Aug 16, 2026
Merged

test: migrate stats/base/dists/chi/pdf to ULP-based assertions#14323
kgryte merged 1 commit into
developfrom
kgryte/ulp-chi-pdf

Conversation

@kgryte

@kgryte kgryte commented Aug 16, 2026

Copy link
Copy Markdown
Member

Resolves a part of #11352.

Description

What is the purpose of this pull request?

This pull request:

  • migrates the tests for stats/base/dists/chi/pdf from relative tolerance testing (delta <= tol, where tol = 140.0 * EPS * abs( expected[ i ] )) to ULP difference testing using @stdlib/assert/is-almost-same-value.

Changes are limited to test files:

  • test/test.pdf.js
  • test/test.factory.js
  • test/test.native.js

In each of the three fixture loops, the if ( y === expected[i] ) { ... } else { delta/tol ... } branch was replaced with

t.strictEqual( isAlmostSameValue( y, expected[ i ], 230 ), true, 'returns expected value' );

The @stdlib/assert/is-almost-same-value require was added, and the now-unused @stdlib/math/base/special/abs require (along with the delta and tol locals) was removed. The @stdlib/constants/float64/eps require is retained in test/test.pdf.js and test/test.factory.js, where EPS is still used to generate negative input values, and removed from test/test.native.js, where it is no longer referenced.

ULP constant

The measured minimum ULP value is 230, used in all three converted fixture loops:

File ULP
test/test.pdf.js 230
test/test.factory.js 230
test/test.native.js 230

The bound was tightened by measuring the exact worst-case ULP difference over the full Julia fixture set (decimal_decimal.json, 5000 values). The maximum observed difference is exactly 230 ULP, and the suite fails at 229 (a single failing case), so 230 is the minimum admissible integer bound.

Notably, the JavaScript implementation, the factory-generated function, and the native implementation return bit-identical results for all 5000 fixture values, so the same bound is the measured minimum for all three files. The observed ULP differences form a smooth, monotonically decaying distribution (373 cases at 1 ULP, tapering to a single case at 230 ULP), rather than a tight cluster with one outlier. For reference, the previous 140.0 * EPS relative tolerance corresponds to roughly 140–280 ULP, so the new bound is consistent with the tolerance it replaces.

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

Verification performed locally on linux/x64, Node.js v22:

  • make test TESTS_FILTER=".*/stats/base/dists/chi/pdf/.*" — 15242 assertions passing, 0 failing (test.pdf.js 5115, test.factory.js 5115, test.js 3, test.native.js 5009). The native add-on was compiled locally via node-gyp rebuild, so the test.native.js assertions actually executed rather than being skipped.
  • The full suite was run twice at the final ULP value with identical results, confirming no FMA/architecture-dependent flakiness locally.
  • make lint-javascript-tests TESTS_FILTER=".*/stats/base/dists/chi/pdf/.*" — clean.
  • The only files changed are the three test files.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

This PR was written by Claude Code running as an unattended scheduled task. The tolerance-to-ULP conversion mirrors the idiom of already-migrated packages in the same family (e.g., stats/base/dists/rayleigh/pdf and stats/base/dists/lognormal/pdf); the ULP bound search and the local verification runs were performed by the agent.


@stdlib-js/reviewers


Generated by Claude Code

@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Good First PR A pull request resolving a Good First Issue. labels Aug 16, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/chi/pdf $\\color{green}304/304$
$\\color{green}+100.00\\%$
$\\color{green}27/27$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}304/304$
$\\color{green}+100.00\\%$

The above coverage report was generated for the changes in this PR.

@kgryte kgryte added the Tests Pull requests specifically adding tests. label Aug 16, 2026
@kgryte
kgryte marked this pull request as ready for review August 16, 2026 23:14
@kgryte
kgryte requested a review from a team August 16, 2026 23:14
@kgryte
kgryte merged commit 7532132 into develop Aug 16, 2026
66 checks passed
@kgryte
kgryte deleted the kgryte/ulp-chi-pdf branch August 16, 2026 23:15
@stdlib-bot stdlib-bot added Needs Review A pull request which needs code review. and removed Needs Review A pull request which needs code review. labels Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Good First PR A pull request resolving a Good First Issue. Statistics Issue or pull request related to statistical functionality. Tests Pull requests specifically adding tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants