Skip to content

test: migrate stats/base/dists/triangular/logpdf to ULP-based assertions - #16007

Merged
kgryte merged 1 commit into
developfrom
kgryte/ulp-triangular-logpdf
Oct 11, 2026
Merged

kgryte merged 1 commit into
developfrom
kgryte/ulp-triangular-logpdf

Conversation

@kgryte

@kgryte kgryte commented Oct 9, 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/triangular/logpdf from relative tolerance testing to ULP difference testing.
  • replaces the if ( y === expected[i] ) { ... } else { delta/tol ... } branches and the t.ok( delta <= tol, ... ) assertions with t.strictEqual( isAlmostSameValue( y, expected[ i ], N ), true, 'returns expected value' );.
  • adds a @stdlib/assert/is-almost-same-value import and removes the now unused @stdlib/math/base/special/abs and @stdlib/constants/float64/eps imports. The @stdlib/math/base/special/ln import is retained, as it is still used by the x = c test.

Final ULP constants

Each of the three fixture sets (small_range.json, medium_range.json, large_range.json, 1000 values each) is asserted with its own bound. Starting from a high bound and tightening, the measured minimum per fixture set and per test file is:

File small range medium range large range
test/test.logpdf.js 55 52 83
test/test.factory.js 55 76 83
test/test.native.js 39 76 83

Every one of these nine bounds is the measured minimum: decrementing any one of them by 1 causes exactly one assertion in that fixture set to fail. The bounds are comparatively large because the fixture values are logarithms close to zero (the worst cases sit near ±0.007), so the pre-existing 40/60/50 * EPS relative tolerances already corresponded to tens of ULP at that magnitude.

The bounds differ slightly between the JS main export, the factory-created function, and the C implementation. This mirrors other migrated distribution packages where the JS and C results differ for the same inputs (e.g. stats/base/dists/betaprime/logcdf, stats/base/dists/f/quantile, stats/base/dists/gamma/quantile), per the FAQ.

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 locally:

  • make test TESTS_FILTER=".*/stats/base/dists/triangular/logpdf/.*" → 9067 passing, 0 failing, run twice at the final bounds with identical per-file counts, to confirm determinism.
  • The native add-on was built locally for this package so that test/test.native.js executed rather than being skipped; its bounds were therefore measured, not assumed. The build artifacts were removed before committing.
  • eslint -c etc/eslint/.eslintrc.tests.js on the three changed files → clean.
  • Only the three test files are changed; no implementation, fixture, docs, or package metadata files are touched.

The idiom follows the already-converted sibling package stats/base/dists/triangular/logcdf, which has the identical test-file layout.

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. The migration mirrors the idiom established in the sibling package stats/base/dists/triangular/logcdf, and every ULP bound was measured empirically over the full fixture set (and shown to be minimal) rather than assumed.


@stdlib-js/reviewers

…tions

Replace the computed relative-tolerance comparisons in the fixture loops
with `@stdlib/assert/is-almost-same-value`, using the minimum ULP bound
which still passes over the full fixture set.

Ref: #11352

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

---
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 Oct 9, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/triangular/logpdf $\\color{green}355/355$
$\\color{green}+100.00\\%$
$\\color{green}39/39$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}355/355$
$\\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 Oct 11, 2026
@kgryte
kgryte marked this pull request as ready for review October 11, 2026 12:40
@kgryte
kgryte requested a review from a team October 11, 2026 12:40
@kgryte
kgryte merged commit c5d712e into develop Oct 11, 2026
70 checks passed
@kgryte
kgryte deleted the kgryte/ulp-triangular-logpdf branch October 11, 2026 12:41
@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 Oct 11, 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