Skip to content

test: migrate stats/base/dists/beta/variance to ULP-based assertions - #14837

Draft
kgryte wants to merge 1 commit into
developfrom
kgryte/ulp-beta-variance
Draft

test: migrate stats/base/dists/beta/variance to ULP-based assertions#14837
kgryte wants to merge 1 commit into
developfrom
kgryte/ulp-beta-variance

Conversation

@kgryte

@kgryte kgryte commented Aug 31, 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/beta/variance from relative-tolerance assertions (delta <= tol, with delta = abs( y - expected[ i ] ) and tol = 1.0 * EPS * abs( expected[ i ] )) to ULP-difference assertions using @stdlib/assert/is-almost-same-value.
  • applies the same migration to both test/test.js and test/test.native.js.
  • preserves all existing test cases and non-tolerance assertions (NaN input, alpha <= 0, beta <= 0), and drops the now-unused abs and EPS requires.

ULP bound

File ULP
test/test.js 0
test/test.native.js 0

0 is the measured minimum, and is the tightest bound possible. Starting from N = 64 and tightening agentically, N = 0 still holds for every one of the 1000 entries in test/fixtures/julia/data.json: both implementations reproduce every expected value exactly, so isAlmostSameValue( actual, expected[ i ], 0 ) (same-value equality) is satisfied throughout.

This is expected for this package rather than surprising. variance( alpha, beta ) is computed as (alpha*beta) / (apb*apb*(apb+1)) with apb = alpha + beta, i.e. a short chain of exactly-rounded multiplications, one addition, and one division, with no cancellation and no series expansion. The previous 1.0 * EPS relative tolerance was already effectively an exactness check for this fixture set.

Both test/test.js and test/test.native.js were run twice at the final N to confirm deterministic passing (1014 assertions each, all passing on both runs, no FMA/architecture-dependent variation). The native add-on was built locally for this package so that test/test.native.js executes rather than skips. As an additional check against FMA contraction, src/main.c was compiled and evaluated over the full fixture set under -O0, -O2, -O3 -ffp-contract=off, and -O3 -ffp-contract=fast; all four configurations reproduce all 1000 expected values exactly, so the 0 ULP bound is not dependent on compiler flags.

Linting is clean: both files pass etc/eslint/.eslintrc.tests.js with no errors, and the repository's pre-commit lint stages (JavaScript test lint, filename lint, commit-message lint) pass. The only files changed are the two test 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 editorconfig pre-commit stage could not run in this environment because downloading the editorconfig-checker binary is blocked by the sandbox network policy. Both files were instead verified manually against .editorconfig (LF endings, UTF-8, tab indentation, no trailing whitespace, final newline present); all other pre-commit lint stages ran normally.

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 PR was authored by Claude Code: the assistant mechanically converted the tolerance-based assertions to isAlmostSameValue, agentically searched for the minimum ULP bound over the full fixture set, built the native add-on and cross-checked the C implementation under several compiler flag sets, verified determinism across two full runs of each test file, and ran the local lint and test suites before submitting.


@stdlib-js/reviewers


Generated by Claude Code

Ref: #11352

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

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/beta/variance $\\color{green}200/200$
$\\color{green}+100.00\\%$
$\\color{green}10/10$
$\\color{green}+100.00\\%$
$\\color{green}2/2$
$\\color{green}+100.00\\%$
$\\color{green}200/200$
$\\color{green}+100.00\\%$

The above coverage report was generated for the changes in this PR.

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants