Skip to content

test: migrate stats/base/dists/normal/pdf to ULP-based assertions - #15437

Merged
kgryte merged 1 commit into
developfrom
kgryte/ulp-normal-pdf
Sep 23, 2026
Merged

kgryte merged 1 commit into
developfrom
kgryte/ulp-normal-pdf

Conversation

@kgryte

@kgryte kgryte commented Sep 22, 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/normal/pdf from relative tolerance assertions to ULP difference assertions using @stdlib/assert/is-almost-same-value.
  • updates test/test.pdf.js, test/test.factory.js, and test/test.native.js, replacing the delta/tol comparison against 5300.0 * EPS * abs( expected[i] ) with t.strictEqual( isAlmostSameValue( y, expected[ i ], 250 ), true, 'returns expected value' ); and dropping the now-unused abs and EPS requires.

test/test.js only asserts the shape of the main export and contains no tolerance comparisons, so it is left unchanged.

ULP bound

The ULP constant for all three test files is 250, which is the measured minimum over the full R fixture set (1000 cases):

Implementation N = 249 N = 250
JavaScript (main) 1 failure 0 failures
JavaScript (factory) 1 failure 0 failures
C (native) 1 failure 0 failures

The JavaScript and C implementations return bit-identical results for all 1000 fixture cases, so a single bound applies to all three test files.

The worst case is x = -78.37837837837837, mu = 5.455455455455455, sigma = 2.3000000000000003, where the returned value 5.557011046698957e-290 differs from the expected 5.557011046698672e-290 by 250 ULP. This case is far out in the tail (z ≈ -36.45), where the relative error in z^2 / 2 ≈ 664 is amplified by exp, so a bound of this magnitude is expected; the previous relative tolerance of 5300 * EPS was roughly 21x looser.

The native addon was compiled locally so that test/test.native.js executed against the C implementation rather than being skipped. The suite was run twice at N = 250 to confirm determinism (3068 passing assertions across the four test files on each run, no failures).

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.

Only the three test files are changed. make test TESTS_FILTER=".*/stats/base/dists/normal/pdf/.*" is green, and all three files lint cleanly under etc/eslint/.eslintrc.tests.js. The EditorConfig linter could not be run in this environment because its binary could not be downloaded, so EditorConfig compliance (LF line endings, UTF-8, tab indentation, no trailing whitespace, final newline) was verified manually instead.

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 primarily by Claude Code, which also measured the minimum ULP bound empirically against the fixture set and ran the test suite.


@stdlib-js/reviewers


Generated by Claude Code

Migrate the tests for `stats/base/dists/normal/pdf` from relative
tolerance assertions to ULP difference assertions using
`@stdlib/assert/is-almost-same-value`.

Ref: #11352

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFE6m4JZPfvHrCqv6553Sp
@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 22, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/normal/pdf $\\color{green}306/306$
$\\color{green}+100.00\\%$
$\\color{green}25/25$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}306/306$
$\\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 Sep 23, 2026
@kgryte
kgryte marked this pull request as ready for review September 23, 2026 05:47
@kgryte
kgryte requested a review from a team September 23, 2026 05:47
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Sep 23, 2026
@kgryte
kgryte merged commit 9944bb4 into develop Sep 23, 2026
82 checks passed
@kgryte
kgryte deleted the kgryte/ulp-normal-pdf branch September 23, 2026 05:48
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Sep 23, 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.

2 participants