Skip to content

test: migrate stats/base/dists/lognormal/mode to ULP-based assertions - #15309

Merged
kgryte merged 2 commits into
developfrom
philipp/ulp-lognormal-mode
Sep 18, 2026
Merged

kgryte merged 2 commits into
developfrom
philipp/ulp-lognormal-mode

Conversation

@Planeshifter

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/lognormal/mode from computed relative-tolerance comparisons (delta = abs( y - expected[ i ] ) / tol = N * EPS * abs( expected[ i ] ), asserted via t.ok( delta <= tol, ... )) to ULP-difference assertions using @stdlib/assert/is-almost-same-value.
  • applies the migration to the two tolerance-based assertion sites in the package: one each in test/test.js and test/test.native.js. Both iterate over the same test/fixtures/julia/data.json fixture (110 points, some null/skipped).
  • collapses the if ( y === expected[i] ) { ... } else { ... } branch at each site into a single ULP assertion via a named ULP constant, and standardizes the assertion message to 'returns expected value'.
  • removes the now-unused @stdlib/math/base/special/abs and @stdlib/constants/float64/eps requires and the delta and tol variable declarations.

The remaining assertions in these files are exact comparisons (NaN propagation for NaN and non-positive sigma, and function type), which are correct as-is and are left unchanged.

Only test files are changed; no implementation, fixture, or documentation changes are included.

ULP bounds

File Implementation Previous tolerance ULP bound
test/test.js JavaScript, main export 1.0 * EPS * abs( expected ) 0
test/test.native.js C 18.0 * EPS * abs( expected ) 0

0 is the minimum integer bound N such that isAlmostSameValue( y, expected[ i ], N ) holds at every non-null element of the fixture. It was determined by computing mode( mu[i], sigma[i] ) for all fixture points outside the test harness (via both lib/main.js and, after building the native add-on with node-gyp rebuild, lib/native.js) and comparing directly against expected[i] using @stdlib/number/float64/base/ulp-difference: the maximum observed ULP difference across the full fixture set was 0 for both implementations, so a 0-ULP (exact) bound is both sufficient and necessary — no looser bound would be tighter.

node test/test.js and node test/test.native.js were each run twice at the final bound with identical results on both runs (110/110 and 111/111 assertions passing, respectively), ruling out flakiness on this platform. npx eslint is clean for both changed files.

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 resulting diff mirrors the already-merged migrations for sibling distribution "mean"/"mode" packages with the same test structure, e.g. stats/base/dists/f/mean (#15233) and stats/base/dists/hypergeometric/mean (#15235).

Two environment notes, neither of which affected verification:

  • make install-node-modules initially failed with ETARGET for es-object-atoms@^1.1.2. The local npm packument cache was stale and served a filtered view of the registry; after npm cache clean --force, the install and make init completed and the full toolchain was available for this PR.
  • The pre-commit hook's lint-editorconfig-files step could not run, because it downloads the editorconfig-checker binary from a GitHub release that this environment cannot reach. The commit was made with SKIP_LINT_EDITORCONFIG=1 (a flag the hook itself exposes for this purpose), and the changed files were instead checked manually against .editorconfig: tabs for indentation, no trailing whitespace, and a 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 written primarily by Claude Code, running as an unattended scheduled task. It selected the package, studied previously migrated packages in the same family to match the established idiom, performed the migration, built the native add-on to verify both implementations empirically, and determined the minimum passing ULP bound over the full fixture set.


@stdlib-js/reviewers

🤖 Generated with Claude Code

https://claude.ai/code/session_01KaEmx8PGodkbJvH7CcTJpR


Generated by Claude Code

Ref: #11352

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

---
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: passed
  - 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 Good First PR A pull request resolving a Good First Issue. Statistics Issue or pull request related to statistical functionality. labels Sep 17, 2026
@stdlib-bot

stdlib-bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/lognormal/mode $\\color{green}176/176$
$\\color{green}+0.00\\%$
$\\color{green}9/9$
$\\color{green}+0.00\\%$
$\\color{green}2/2$
$\\color{green}+0.00\\%$
$\\color{green}176/176$
$\\color{green}+0.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:27
@kgryte
kgryte requested a review from a team September 18, 2026 06:27
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Sep 18, 2026
Comment thread lib/node_modules/@stdlib/stats/base/dists/lognormal/mode/test/test.js Outdated
Comment thread lib/node_modules/@stdlib/stats/base/dists/lognormal/mode/test/test.js Outdated
Comment thread lib/node_modules/@stdlib/stats/base/dists/lognormal/mode/test/test.js Outdated
Comment thread lib/node_modules/@stdlib/stats/base/dists/lognormal/mode/test/test.native.js Outdated
Comment thread lib/node_modules/@stdlib/stats/base/dists/lognormal/mode/test/test.native.js Outdated
Comment thread lib/node_modules/@stdlib/stats/base/dists/lognormal/mode/test/test.native.js Outdated
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
@kgryte
kgryte merged commit 2f4fe5a into develop Sep 18, 2026
12 checks passed
@kgryte
kgryte deleted the philipp/ulp-lognormal-mode branch September 18, 2026 06:32
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label 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.

4 participants