Skip to content

Consolidation of Test Mock Types and Helpers - #184

Open
vp314 wants to merge 3 commits into
mainfrom
vp/test-refactor
Open

Consolidation of Test Mock Types and Helpers#184
vp314 wants to merge 3 commits into
mainfrom
vp/test-refactor

Conversation

@vp314

@vp314 vp314 commented Jul 6, 2026

Copy link
Copy Markdown
Member

Consolidates the test suite's shared infrastructure to reduce duplication in mock definitions and test helpers.

Description

Refactors the test suite's shared infrastructure to reduce duplication of structs and functionality defined specifically for testing purposes. Not all structs and functionality were consolidated as this would require rewriting tests, which can be
done in the future.

Related changes:

  1. Replaced the shared ApproxTol module with per-file constants. The global ATOL = 1e-10 module was removed in favor of a local const ATOL = 1e-10 in the two files that actually used it (randsvd.jl,rangefinder.jl). Removed using ..ApproxTol from every test file.
  2. Reworked the field-test macros. @test_projection_solver was split/generalized into @test_solver (checks the common SolverRecipe interface: compressor, log, error, compressed_mat, mat_view, solution_vec) and @test_sub_solver (checks SubSolverRecipe's A field). Supertype checks now use <: instead of == to allow parametric recipe types.

Motivation and Context

Many tests defined their own near-identical mock structs creating unnecessary code duplication. Centralizing the mocks makes the common recipe interfaces explicit in one place and reduces boilerplate across ~30 test files.

How has this been tested

The entire test suite was run using Julia's testing interface. All tests passed.

Types of changes

  • CI
  • Docs
  • Feature
  • Fix
  • Performance
  • Refactor
  • Style
  • Test
  • Other (use sparingly):

Checklists:

Code and Comments
If this PR includes modification to the code base, please select all that apply.

  • My code follows the code style of this project.
  • I have updated all package dependencies (if any).
  • I have included all relevant files to realize the functionality of the PR.
  • I have exported relevant functionality (if any).

API Documentation

  • For every exported function (if any), I have included a detailed docstring.
  • I have checked the spelling and grammar of all docstring updates through an external tool.
  • I have checked that the docstring's function signature is correctly formatted and has all arguments.
  • I have checked that the docstring's list of arguments, fields, or return values match the function.
  • I have compiled the docs locally and read through all docstring updates to check for errors.

Manual Documentation

  • I have checked the spelling and grammar of all manual updates through an external tool.
  • Any code included in the docstring is tested using doc tests to ensure consistency.
  • I have compiled the docs locally and read through all manual updates to check for errors.

Testing

  • I have added unit tests to cover my changes. (For Macros, be sure to check
    @code_lowered and
    @code_typed)
  • All new and existing tests passed.
  • I have achieved sufficient code coverage.

vp314 and others added 3 commits June 3, 2026 10:29
…stants and refactor field macros

- Delete `test_helpers/approx_tol.jl`; add `const ATOL = 1e-10` locally in
  the two files that actually use it (randsvd.jl, rangefinder.jl)
- Remove unused `using ..ApproxTol` from all ~23 other test files
- Rename `@test_projection_solver` → `@test_solver` with corrected common
  SolverRecipe fields (compressor/log/error/compressed_mat/mat_view/solution_vec,
  fixing incorrect field names S and update_vec from the old version)
- Add `@test_sub_solver` macro for validating SubSolverRecipe field conformance

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add test/test_helpers/mock_types.jl with canonical, reusable mock type
definitions, eliminating ~50 redundant struct definitions across 16 test files:

- TestCompressor, TestApproximator, TestSolver: minimal stubs for type
  hierarchy tests
- TestCompressorRecipe (n_rows, n_cols, status superset), TestApproximatorRecipe
  (n_rows, n_cols, code superset), TestSolverRecipe (code): cover all abstract
  interface test scenarios via a single shared type with multi-arg constructors
- TestFullCompressor / TestFullCompressorRecipe: unified compressor mock with
  both 2-arg (Right/approximator) and 3-arg (Left/solver) complete_compressor
  overloads plus Left and Right mul! implementations

Note: mul!, rapproximate!, complete_approximator, complete_solver, and
rsolve! are intentionally absent from MockTypes — abstract-type error-phase
tests require those functions to throw before any implementation exists.
Files that define these methods locally extend MockTypes types explicitly
(import ..MockTypes: TypeName) to satisfy Julia 1.12 qualification rules.

Known: complete_approximator(::MockTypes.TestApproximator, A) is defined in
both approximators_abstract_types and rapproximate_abstract_interface;
Julia emits a method-overwrite warning. Tests pass. To be resolved in a
follow-up.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Route the remaining per-file "Group 1" test mocks through shared
MockTypes definitions, removing duplicated struct/method definitions.

- Compressor mocks in randsvd.jl, rangefinder.jl, and
  range_finder_helpers.jl now reuse the existing (previously unused)
  TestFullCompressor / TestFullCompressorRecipe.
- The divergent local TestSolverRecipe definitions in the ErrorMethods
  tests are replaced by a new shared TestFullSolverRecipe (a superset of
  the fields the compute_error routines read), with an all-optional
  keyword constructor so each test populates only what it exercises.

Group 2 mocks (e.g. TestRangeApproximatorRecipe, TestSolverError) are
intentionally left local for a follow-up.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vp314
vp314 requested a review from nathanielpritchard July 6, 2026 23:45
@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@nathanielpritchard nathanielpritchard left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything seems to look good although the '@solver' macro checks for structures that are not necessarily in every solver. I believe that this macro should continue to be only for projection_solvers

Comment on lines +72 to +94
@test_solver(type)

Macro for testing solver recipe types, such as `KaczmarzRecipe` and `IHSRecipe`. It checks
that every `SolverRecipe` includes the common interface fields `compressor::CompressorRecipe`,
`log::LoggerRecipe`, `error::SolverErrorRecipe`, `compressed_mat::AbstractMatrix`,
`mat_view::SubArray`, and `solution_vec::AbstractVector`.
"""
macro test_solver(type)
expr = quote
@testset verbose = true "Solver: $(string($(esc(type))))" begin
# Test the super type
@test supertype($(esc(type))) <: SolverRecipe

# Test the field names and types
for (fname, ftype) in SolverFields
@test fname in fieldnames($(esc(type)))
@test fieldtype($(esc(type)), fname) <: ftype
end
end
end

return expr
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that different solvers will not necessarily always feature these fields so we need to be more specific as to what types of solvers this macro is applied.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still prefer the projection_solver version.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants