Skip to content

test: migrate stats/base/dists/binomial/variance to ULP-based assertions - #15614

Merged
kgryte merged 1 commit into
developfrom
kgryte/ulp-binomial-variance
Sep 28, 2026
Merged

kgryte merged 1 commit into
developfrom
kgryte/ulp-binomial-variance

Conversation

@kgryte

@kgryte kgryte commented Sep 28, 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/binomial/variance from relative tolerance assertions to ULP difference assertions using @stdlib/assert/is-almost-same-value.
  • updates test/test.native.js, replacing the if ( y === expected[i] ) { ... } else { delta/tol } branch against 2.0 * EPS * abs( expected[ i ] ) with t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' ); and dropping the now-unused abs and EPS requires.

test/test.js is not modified: its fixture loop already performs an exact comparison (t.strictEqual( y, expected[i], ... )) and contains no computed tolerance, so there is nothing to migrate there.

ULP bound

The ULP constant is 0, which is the measured minimum over the full Julia fixture set (200 cases):

Implementation Max observed ULP difference N = 0
JavaScript 0 0 failures
C (native) 0 0 failures

Every one of the 200 fixture values is returned bit-identically by both implementations, so 0 is the tightest achievable bound and the 2.0 * EPS slack in the previous assertion was never exercised. This is expected from the implementations: both lib/main.js and src/main.c evaluate the same expression, n * p * ( 1.0 - p ), which contains no fused-multiply-add contraction opportunity and is therefore reproducible across platforms.

The native addon was compiled locally (npx node-gyp rebuild) so that test/test.native.js executed against the C implementation rather than being skipped — the native file reports 207 passing assertions (200 fixtures plus 7 argument-validation assertions), which confirms the fixture loop ran and was not skipped. The suite was run twice at N = 0 to confirm determinism: 214 passing assertions in test/test.js and 207 in test/test.native.js on both runs, with no failures and no skips.

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 test/test.native.js is changed. make test TESTS_FILTER=".*/stats/base/dists/binomial/variance/.*" is green, and make lint-javascript-tests TESTS_FILTER=".*/stats/base/dists/binomial/variance/.*" is clean. The conversion mirrors the idiom used in the sibling package stats/base/dists/binomial/skewness (#15427) and, for the N = 0 case specifically, stats/base/dists/invgamma/mode (#15502).

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 performed the mechanical tolerance-to-ULP conversion, measured the minimum ULP bound empirically against the fixture set, built the native addon, and ran the tests and test linter locally.


@stdlib-js/reviewers

🤖 Generated with Claude Code

https://claude.ai/code/session_01H6PY1ZMhsqMSqnD3RU5UcY


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 Sep 28, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/binomial/variance $\\color{green}176/176$
$\\color{green}+100.00\\%$
$\\color{green}12/12$
$\\color{green}+100.00\\%$
$\\color{green}2/2$
$\\color{green}+100.00\\%$
$\\color{green}176/176$
$\\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 28, 2026
@kgryte
kgryte marked this pull request as ready for review September 28, 2026 03:11
@kgryte
kgryte requested a review from a team September 28, 2026 03:11
@kgryte
kgryte merged commit f73d703 into develop Sep 28, 2026
66 checks passed
@kgryte
kgryte deleted the kgryte/ulp-binomial-variance branch September 28, 2026 03:12
@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 Sep 28, 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