Skip to content

test: migrate stats/base/dists/normal/median to ULP-based assertions - #15299

Merged
kgryte merged 1 commit into
developfrom
claude/great-brahmagupta-qjpxqn
Sep 18, 2026
Merged

kgryte merged 1 commit into
developfrom
claude/great-brahmagupta-qjpxqn

Conversation

@kgryte

@kgryte kgryte commented Sep 17, 2026

Copy link
Copy Markdown
Member

Resolves a part of #11352.

Description

What is the purpose of this pull request?

This pull request:

In both test/test.js and test/test.native.js, the fixture loop's delta/tol comparison is replaced with t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' );, adding the @stdlib/assert/is-almost-same-value require and dropping the now unused @stdlib/math/base/special/abs and @stdlib/constants/float64/eps requires.

Final ULP constant: 0 (both test/test.js and test/test.native.js).

How the bound was measured: starting from 64, the bound was lowered over the full 100-value fixture set (64 → 32 → 16 → 8 → 4 → 2 → 1 → 0), and all 100 values passed at every step, so 0 is the measured minimum. The suite was then run twice at the final value to confirm determinism (110/110 assertions passing on both runs).

0 is the correct bound because both lib/main.js and src/main.c return mu verbatim once the NaN/nonpositive-sigma guards are cleared; no floating-point arithmetic is performed, so the computed results are bit-identical to the Julia-generated fixture values (all 100 fixture expected values are exactly equal to the corresponding mu values). Note that isAlmostSameValue falls back to isSameValue when maxULP is 0, which distinguishes +0 from -0; no fixture value is zero, so the assertion holds.

Because test/test.native.js is skipped without a compiled add-on, the C path was verified separately by compiling src/main.c against the fixture inputs and comparing the raw bit patterns of the results to the expected values. There were zero mismatches across all 100 fixtures under -O0, -O2, -O3 -ffp-contract=fast, and -O2 -march=native, confirming that 0 is also correct for the native path and is not sensitive to FMA contraction or architecture-specific code generation.

Only the two test files are changed; no source, fixture, or documentation files were touched.

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.

The conversion mirrors the previously merged migrations for the sibling packages stats/base/dists/normal/variance (#15197) and stats/base/dists/normal/mean (#14472), whose test files are structurally identical to these.

Tests were run with make test TESTS_FILTER=".*/stats/base/dists/normal/median/.*" (110/110 passing, twice) and linting with make lint-javascript-tests TESTS_FILTER=".*/stats/base/dists/normal/median/.*" (0 errors, 0 warnings). The editorconfig pre-commit hook could not run in this environment because its checker binary cannot be downloaded here; the two changed files were instead verified manually against .editorconfig (LF endings, UTF-8, tab indentation, no trailing whitespace, final newline present).

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 authored by Claude Code running as an unattended scheduled task. It selected the package, mirrored the conversion idiom from previously merged PRs for this tracking issue, measured the minimum ULP bound empirically, and verified the tests and linting.


@stdlib-js/reviewers

🤖 Generated with Claude Code

https://claude.ai/code/session_01HF1y7YHLkTqnj6BmUMrxWp


Generated by Claude Code

Migrate the tests for `@stdlib/stats/base/dists/normal/median` from
relative tolerance testing to ULP difference testing.

In both `test/test.js` and `test/test.native.js`, replace the fixture
loop's `delta`/`tol` comparison with

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

adding the `@stdlib/assert/is-almost-same-value` require and dropping
the now unused `@stdlib/math/base/special/abs` and
`@stdlib/constants/float64/eps` requires.

The ULP bound was lowered from 64 to the measured minimum of 0 over the
full 100-value fixture set.

Ref: #11352

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

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/normal/median $\\color{green}175/175$
$\\color{green}+100.00\\%$
$\\color{green}9/9$
$\\color{green}+100.00\\%$
$\\color{green}2/2$
$\\color{green}+100.00\\%$
$\\color{green}175/175$
$\\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 18, 2026
@kgryte
kgryte marked this pull request as ready for review September 18, 2026 06:32
@kgryte
kgryte requested a review from a team September 18, 2026 06:32
@kgryte
kgryte merged commit c4244ca into develop Sep 18, 2026
66 checks passed
@kgryte
kgryte deleted the claude/great-brahmagupta-qjpxqn branch September 18, 2026 06:33
@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 18, 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