Skip to content

Raise test coverage to 99% and fix a constant-value regression - #54

Merged
saudzahirr merged 1 commit into
masterfrom
test/raise-coverage
Aug 15, 2026
Merged

Raise test coverage to 99% and fix a constant-value regression#54
saudzahirr merged 1 commit into
masterfrom
test/raise-coverage

Conversation

@saudzahirr

Copy link
Copy Markdown
Collaborator

Coverage had fallen to 76% because most of the library was never exercised: umath was at 54% with nearly every trigonometric, hyperbolic and special function untested, and the operator overloads, the distribution constructors and the printed reports were largely untouched. The new tests take the package to 99%.

  • test_umath_functions.py parametrizes all 39 unary functions plus the stepwise, power and binary ones, checking each twice: once with a plain float and once with an uncertain input. Reference values come from the standard library, so a wrong derivative shows up as a mismatch instead of agreeing with itself. umath goes from 54% to 100%.
  • test_uncertain_function.py covers every operator, the derivative accessors, and all four combinations of error_components.
  • test_method_of_moments.py covers the standardization helpers, the argument checks, the printed report and raw2central.
  • test_distributions.py covers all eleven constructors against their closed-form mean and variance, plus every parameter-validation path.
  • test_uncertain_variable.py gains the setters and the plotting paths.

Writing them surfaced a real regression from the FORTRAN port: a constant UncertainFunction has no input variables, so the kernel was handed zero-length arrays and f2py raised

ValueError: unexpected array size: new_size=1, got array with arr_size=0

The Python loops it replaced simply iterated zero times, so str(UncertainFunction(4.0)) used to work and had stopped. rawmoment, variance_components and soerp_numeric now short-circuit when there are no variables, which is also what to_uncertain_func needs for a plain number.

Coverage is now reported against src/soerp rather than site-packages. The package carries a compiled extension so it cannot be imported from the source tree, and without [tool.coverage.paths] the results do not line up with the repository. matplotlib joins the test group so the optional plotting path is exercised rather than skipped.

Two small things left uncovered deliberately: the PackageNotFoundError fallback in init, which needs the package reloaded to reach, and the defensive else branches in the error_components report, which cannot be reached because the dictionaries are built from the same variable list they are then looked up in.

Coverage had fallen to 76% because most of the library was never
exercised: umath was at 54% with nearly every trigonometric, hyperbolic
and special function untested, and the operator overloads, the
distribution constructors and the printed reports were largely untouched.
The new tests take the package to 99%.

- test_umath_functions.py parametrizes all 39 unary functions plus the
  stepwise, power and binary ones, checking each twice: once with a plain
  float and once with an uncertain input. Reference values come from the
  standard library, so a wrong derivative shows up as a mismatch instead
  of agreeing with itself. umath goes from 54% to 100%.
- test_uncertain_function.py covers every operator, the derivative
  accessors, and all four combinations of error_components.
- test_method_of_moments.py covers the standardization helpers, the
  argument checks, the printed report and raw2central.
- test_distributions.py covers all eleven constructors against their
  closed-form mean and variance, plus every parameter-validation path.
- test_uncertain_variable.py gains the setters and the plotting paths.

Writing them surfaced a real regression from the FORTRAN port: a constant
UncertainFunction has no input variables, so the kernel was handed
zero-length arrays and f2py raised

    ValueError: unexpected array size: new_size=1, got array with arr_size=0

The Python loops it replaced simply iterated zero times, so
str(UncertainFunction(4.0)) used to work and had stopped. rawmoment,
variance_components and soerp_numeric now short-circuit when there are no
variables, which is also what to_uncertain_func needs for a plain number.

Coverage is now reported against src/soerp rather than site-packages.
The package carries a compiled extension so it cannot be imported from
the source tree, and without [tool.coverage.paths] the results do not line
up with the repository. matplotlib joins the test group so the optional
plotting path is exercised rather than skipped.

Two small things left uncovered deliberately: the PackageNotFoundError
fallback in __init__, which needs the package reloaded to reach, and the
defensive else branches in the error_components report, which cannot be
reached because the dictionaries are built from the same variable list
they are then looked up in.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: codex <267193182+codex@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: gemini-code-assist <gemini-code-assist@users.noreply.github.com>
Co-authored-by: Junie <junie@jetbrains.com>
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: kilocode-bot <github-actions@github.com>
@saudzahirr saudzahirr self-assigned this Aug 15, 2026
@sonarqubecloud

Copy link
Copy Markdown

@saudzahirr
saudzahirr merged commit 83606b6 into master Aug 15, 2026
8 checks passed
@saudzahirr
saudzahirr deleted the test/raise-coverage branch August 15, 2026 11:45
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants