Skip to content

test: migrate stats/base/dists/weibull/mode to ULP-based assertions - #15513

Merged
kgryte merged 1 commit into
developfrom
kgryte/ulp-stats-base-dists-weibull-mode
Sep 24, 2026
Merged

kgryte merged 1 commit into
developfrom
kgryte/ulp-stats-base-dists-weibull-mode

Conversation

@kgryte

@kgryte kgryte commented Sep 24, 2026

Copy link
Copy Markdown
Member

Resolves a part of #11352.

Description

What is the purpose of this pull request?

This pull request:

Both test/test.js and test/test.native.js previously compared against a computed relative tolerance:

delta = abs( y - expected[ i ] );
tol = 1.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. ...' );

and now assert:

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

ULP constant: 1 in both test/test.js and test/test.native.js.

This is the measured minimum over the full 500-value Julia fixture set. Measuring the ULP distance between each computed value and its reference value directly:

implementation fixtures exact (SameValue) matches max ULP difference
JavaScript (lib/main.js) 500 499 1
C (src/main.c, via lib/native.js) 500 499 1

1 was confirmed to be the tightest passing bound: re-running both files at 0 fails with exactly one failing assertion in each (k = 15.188796105541709, lambda = 10.351582224226767, computed 10.305270420548517 vs. expected 10.305270420548515), while 1 passes in full.

A single-ULP discrepancy is expected here rather than a sign of an implementation problem. Both implementations evaluate the mode as

lambda * pow( ( k-1.0 ) / k, 1.0/k )

so a result depends on three separately rounded operations feeding a transcendental pow evaluation, and the reference values are computed in Julia. One ULP of disagreement on 1 of 500 fixtures is consistent with correctly rounded inputs to an inexact pow.

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:

  • make test TESTS_FILTER=".*/stats/base/dists/weibull/mode/.*" → 516 passing, 0 failing.
  • make eslint-tests TESTS_FILTER=".*/stats/base/dists/weibull/mode/.*" → clean for both files.
  • The native add-on was built locally (make install-node-addons NODE_ADDONS_PATTERN="mode") so that test/test.native.js actually executes rather than being skipped; it reports 516 passing assertions, confirming the fixture loop was not skipped.
  • Both files were run twice at the final ULP value, with identical results both times, to confirm there is no FMA/architecture-dependent flakiness.
  • Only the two test files are modified.

Note for reviewers: the pre-commit hook could not run lint-editorconfig-files in this environment, as it attempts to download the editorconfig-checker binary from GitHub releases and that request was blocked. The two changed files were instead verified manually against .editorconfig (LF line endings, UTF-8, tab indentation, no trailing whitespace, single final newline).

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

This PR was authored by Claude Code running as an unattended scheduled task. It studied the already-merged conversions in this family (stats/base/dists/weibull/skewness, stats/base/dists/geometric/mean) to match the established idiom, then determined the ULP bound empirically by measuring the maximum ULP difference over the fixture set for both the JavaScript and C implementations, and re-ran the suite at 0 and at 1 to confirm minimality and determinism.


@stdlib-js/reviewers

🤖 Generated with Claude Code

https://claude.ai/code/session_01QMCnXVwjZRfgDEQ4Z47WVx


Generated by Claude Code

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

The ULP bound is `1` in both `test/test.js` and `test/test.native.js`,
which is the measured minimum over the full 500-value Julia fixture set
for both the JavaScript and C implementations.

Ref: #11352

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

Copy link
Copy Markdown
Contributor

Hello! 👋

We've noticed that you've been opening a number of PRs addressing good first issues. Thank you for your interest and enthusiasm!

Now that you've made a few contributions, we suggest no longer working on good first issues. Instead, we encourage you to prioritize cleaning up any PRs which have yet to be merged and then proceed to work on more involved tasks.

Not only does this ensure that other new contributors can work on things and get ramped up on all things stdlib, it also ensures that you can spend your time on more challenging problems. 🚀

For ideas for future PRs, feel free to search the codebase for TODOs and FIXMEs and be sure to check out other open issues on the issue tracker. Cheers!

@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/weibull/mode $\\color{green}199/199$
$\\color{green}+100.00\\%$
$\\color{green}12/12$
$\\color{green}+100.00\\%$
$\\color{green}2/2$
$\\color{green}+100.00\\%$
$\\color{green}199/199$
$\\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 24, 2026
@kgryte
kgryte marked this pull request as ready for review September 24, 2026 23:52
@kgryte
kgryte requested a review from a team September 24, 2026 23:52
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Sep 24, 2026
@kgryte
kgryte merged commit 8617b66 into develop Sep 24, 2026
82 checks passed
@kgryte
kgryte deleted the kgryte/ulp-stats-base-dists-weibull-mode branch September 24, 2026 23:53
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Sep 24, 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