Skip to content

test: migrate stats/base/dists/chisquare/cdf to ULP-based assertions - #15392

Merged
Planeshifter merged 2 commits into
developfrom
kgryte/ulp-chisquare-cdf
Sep 22, 2026
Merged

Planeshifter merged 2 commits into
developfrom
kgryte/ulp-chisquare-cdf

Conversation

@kgryte

@kgryte kgryte commented Sep 21, 2026

Copy link
Copy Markdown
Member

Resolves a part of #11352.

Description

What is the purpose of this pull request?

This pull request:

The following test files are updated; no other files are touched:

  • test/test.cdf.js
  • test/test.factory.js
  • test/test.native.js

In each file, var abs = require( '@stdlib/math/base/special/abs' ); and var EPS = require( '@stdlib/constants/float64/eps' ); are replaced by var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );, the delta/tol computation is removed, and the if ( y === expected[i] ) { ... } else { t.ok( delta <= tol, ... ); } block is replaced by a single t.strictEqual( isAlmostSameValue( y, expected[ i ], N ), true, 'returns expected value' );.

ULP constant

There is a single fixture-driven test block per file, all three of which are backed by the same 5000-element fixture set:

Fixture ULP constant Previous tolerance
test/fixtures/julia/decimal_decimal.json 76 40.0 * EPS * abs( expected[i] )

76 is the measured minimum, not a rounded-up bound:

  • The maximum observed ULP difference over all 5000 fixture values is exactly 76, for x = 0.05304959964595124, k = 17.630144352098277.
  • Running the suite at 75 fails, with exactly one failing assertion (that same value); running at 76 passes.
  • The suite was run twice at 76 to confirm determinism; both runs were identical, with no arch/FMA-dependent variation.

The native add-on was built locally so that test/test.native.js was actually exercised rather than skipped. The C implementation reproduces the JavaScript results bit-for-bit across all 5000 fixtures (0 differing values), and its measured maximum ULP difference is likewise 76, so test/test.native.js uses the same constant.

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.

Test results on this branch (make test TESTS_FILTER=".*/stats/base/dists/chisquare/cdf/.*"):

  • test/test.cdf.js: 5015 passing, 0 failing
  • test/test.factory.js: 5015 passing, 0 failing
  • test/test.js: 3 passing, 0 failing (unchanged; contains no tolerance-based assertions)
  • test/test.native.js: 5009 passing, 0 failing (with the add-on built locally)

ESLint is clean for the three changed files against etc/eslint/.eslintrc.tests.js. The EditorConfig check could not be run in this environment, because editorconfig-checker downloads its binary from GitHub releases and that download was blocked; the changed files were instead verified by hand to use LF endings, tab indentation, no trailing whitespace, and a final newline, and git diff --check reports no whitespace errors.

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, which studied the migrations in already-converted packages in the same family (e.g. stats/base/dists/cauchy/cdf, stats/base/dists/gamma/cdf) to match the established idiom, applied the same mechanical transformation here, and determined the ULP constant empirically by measuring the maximum ULP difference over the fixture set and confirming that the next-lower integer fails.


@stdlib-js/reviewers

🤖 Generated with Claude Code

https://claude.ai/code/session_018DyJPRsZzRLQLN4sSHtZjY


Generated by Claude Code

Migrates the tests for `stats/base/dists/chisquare/cdf` from relative
tolerance testing to ULP difference testing.

The ULP constant is the measured minimum over the full 5000-element
`decimal_decimal.json` fixture set:

-   `decimal_decimal.json`: 76 (was `40.0 * EPS * abs( expected[i] )`)

The native add-on was built locally and reproduces the JavaScript
results bit-for-bit across all 5000 fixtures, so `test/test.native.js`
uses the same constant.

Ref: #11352

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018DyJPRsZzRLQLN4sSHtZjY

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: skipped
  - task: lint_markdown_pkg_readmes
    status: na
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@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 Sep 21, 2026
@stdlib-bot

stdlib-bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/chisquare/cdf $\\color{green}241/241$
$\\color{green}+0.00\\%$
$\\color{green}7/7$
$\\color{green}+0.00\\%$
$\\color{green}3/3$
$\\color{green}+0.00\\%$
$\\color{green}241/241$
$\\color{green}+0.00\\%$

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

@Planeshifter
Planeshifter marked this pull request as ready for review September 22, 2026 04:13
@Planeshifter
Planeshifter requested a review from a team September 22, 2026 04:13
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Sep 22, 2026
@Planeshifter

Copy link
Copy Markdown
Member

/stdlib merge

@stdlib-bot stdlib-bot added the bot: In Progress Pull request is currently awaiting automation. label Sep 22, 2026

@Planeshifter Planeshifter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@stdlib-bot stdlib-bot removed the bot: In Progress Pull request is currently awaiting automation. label Sep 22, 2026
@Planeshifter
Planeshifter merged commit 71cf6bd into develop Sep 22, 2026
15 checks passed
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Sep 22, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants