Skip to content

Reorganize test suite by functionality (orthogonal to source structure)#326

Merged
ocots merged 9 commits into
mainfrom
test/orthogonal-suite
Jun 14, 2026
Merged

Reorganize test suite by functionality (orthogonal to source structure)#326
ocots merged 9 commits into
mainfrom
test/orthogonal-suite

Conversation

@ocots

@ocots ocots commented Jun 13, 2026

Copy link
Copy Markdown
Member

Summary

This PR completes the full three-phase test suite overhaul for CTModels.jl, bringing all files into conformance with the testing standards, filling targeted coverage gaps, and adding contract/LSP tests.


Phase 1 — Uniform cleanup (all files, low risk) ✅

1a — Structural reorganization

Reorganizes test/suite/ from a source-aligned structure to a functionality-aligned one.

Directory Content
suite/components/ Shared types, aliases, accessors, time-dependence traits
suite/models/ Immutable Model type, readers, user-facing predicates
suite/building/ PreModel, mutators, validation, defaults, build
suite/solutions/ Solution, time grids, dual model, interpolation
suite/init/ Initial guess construction, validation, API
suite/serialization/ Import/export to disk (JLD2, JSON)
suite/display/ Pretty-printing of models and solutions
suite/extensions/ Weak-dependency extension tests (e.g. Plots)
suite/integration/ End-to-end tests spanning multiple modules
suite/meta/ Aqua.jl code-quality checks, export verification, type hierarchy
  • Removed empty shells: suite/ocp/, suite/exceptions/, suite/initial_guess/
  • Renamed 40 test files to match the new structure
  • Updated module names and entry functions in 4 files: test_components.jl, test_model_types.jl, test_solution_types.jl, test_building_exceptions.jl
  • Updated test/README.md with new directory structure and examples

1b — Submodule-qualified imports and calls

  • Imports replaced with explicit submodule imports (import CTModels.Building: Building, etc.) across all 44 files
  • All call sites converted from CTModels.foo to Submodule.foo following the canonical symbol-to-submodule map
  • Removed 36 empty placeholder testsets "Abstract Types" (noise)
  • test_plot.jl: kept import CTModels: CTModels (needed for Base.get_extension)
  • Project.toml / docs/Project.toml: widened CTBase compat to "0.18, 0.19"

Phase 2 — Coverage gaps + quality tests ✅

File What was added
building/test_dedup.jl (new) 6 direct testsets on Building._dedup_box_constraints! + build(ConstraintsDictType) unknown-type error path
components/test_components.jl Empty sentinels (EmptyControlModel, EmptyVariableModel, EmptyDefinition), StateModelSolution/ControlModelSolution accessors, time accessors, has_mayer_cost/has_lagrange_cost
models/test_model.jl is_autonomous/has_variable traits, free-time branches (scalar and vector), mayer/lagrange error stubs, get_build_examodel, missing label, @inferred and @allocated quality assertions
solutions/test_dual_model.jl Label :nonexistentIncorrectArgument error path
init/test_initial_guess_validation.jl Scalar variable on vdim=0, :variable block on problem without variable

Phase 3 — Contract/LSP tests, export verification, retro-compat ✅

File What was added
components/test_contracts.jl (new) Top-level fakes for AbstractStateModel, AbstractControlModel, AbstractVariableModel, AbstractModel; generic LSP contract checkers; mayer/lagrange/initial_time/final_time stubs on AbstractModelPreconditionError
meta/test_CTModels.jl Verify CTModels top-level exports only :CTModels (tenet #1); full list of symbols announced by Components
serialization/test_multi_grids.jl Retro-compat: JSON with legacy key time_grid_dual imported correctly as time_grid_path
display/test_print.jl Smoke tests show(Model) autonomous and with optimisation variable

Test results

  • 3614 + 237 = 3851 tests pass across all three phases — zero regressions
  • ✅ Test organization is orthogonal to the source file structure
  • ✅ All imports and call sites are submodule-qualified throughout the suite
  • ✅ Coverage gaps on Building, Solutions, Models, Init addressed
  • ✅ Quality assertions (@inferred, @allocated) added
  • ✅ Contract/LSP coverage for all abstract types
  • ✅ Export invariants verified

Rationale

The previous structure mirrored the source layout (suite/ocp/ for src/OCP/) and used bare CTModels.foo calls, both in violation of the testing standards. This PR brings the full test suite into conformance:

  • Orthogonality: tests grouped by functionality, not by source file
  • Qualified imports: every call site uses Submodule.symbol, making intent explicit and namespace ownership clear
  • Completeness: targeted gaps on risky branches, internal functions, and abstract-type contracts are now covered

ocots added 6 commits June 13, 2026 22:13
- Reorganized test/suite/ from source-aligned to functionality-aligned structure
- New directories: components/, models/, building/, solutions/, init/, serialization/, display/, extensions/, meta/, integration/
- Removed empty shells: suite/ocp/, suite/exceptions/, suite/initial_guess/
- Renamed 40 test files to match new directory structure
- Updated module names and entry functions in 4 files (test_components.jl, test_model_types.jl, test_solution_types.jl, test_building_exceptions.jl)
- Updated test/README.md with new directory structure and examples
- All 3521 tests pass
- Tests now organized by functionality rather than source file structure, improving maintainability and discoverability
- Replace `using CTModels: CTModels` + `CTModels.foo` with direct submodule imports
  (`import CTModels.Components: Components`, `import CTModels.Building: Building`, etc.)
  across all 44 test files
- Remove empty placeholder testsets "Abstract Types" (36 occurrences)
- Add `import Test: Test` (qualified import) uniformly
- Fix test_plot.jl: keep `import CTModels: CTModels` for `Base.get_extension(CTModels, ...)`
- Update Project.toml / docs/Project.toml: widen CTBase compat to "0.18, 0.19"
- All 3530 tests pass (3399 core + 131 plot), zero regressions
- test_dedup.jl (new): 6 direct testsets on Building._dedup_box_constraints!
  and build(ConstraintsDictType) unknown-type error path
- test_components.jl: empty sentinels (EmptyControlModel, EmptyVariableModel,
  EmptyDefinition), StateModelSolution/ControlModelSolution accessors, time
  accessors (Base.time, Components.name, has_* predicates), has_mayer_cost /
  has_lagrange_cost
- test_model.jl: is_autonomous/has_variable traits, free-time branches (scalar
  and vector), mayer/lagrange error stubs, get_build_examodel, missing label,
  @inferred and @allocated quality assertions
- test_dual_model.jl: label :nonexistent -> IncorrectArgument error path
- test_initial_guess_validation.jl: scalar variable on vdim=0, :variable block
  on problem without variable

3614/3614 tests pass, zero regressions
… tests

- test_contracts.jl (new): top-level fakes for AbstractStateModel,
  AbstractControlModel, AbstractVariableModel, AbstractModel; generic LSP
  contract checkers; mayer/lagrange/initial_time/final_time stubs on
  AbstractModel -> PreconditionError
- test_CTModels.jl: verify CTModels top-level exports only :CTModels (tenet #1);
  full list of symbols announced by Components
- test_multi_grids.jl: retro-compat — JSON with legacy key time_grid_dual
  imported correctly as time_grid_path
- test_print.jl: smoke tests show(Model) autonomous and with optimisation variable

237/237 tests pass. Plan elegant-milner Phases 1+2+3 complete.
- Add # Returns and # Arguments sections to all accessors in build_solution.jl (20 functions)
- Add # Returns and See also: to dual accessors in dual_model.jl (8 functions)
- Add See also: to interpolation helpers in interpolation_helpers.jl (3 functions)
- Enrich Solutions.jl module docstring with # Public API, # Dependencies, # See also sections
- Ensure all cross-references use full paths (CTModels.Solutions.*, CTModels.Models.*)
- All docstrings now conform to project standards with active descriptions and complete sections
@ocots

ocots commented Jun 14, 2026

Copy link
Copy Markdown
Member Author

Refactor docstrings for Solutions module

This commit completes the docstring refactoring for the Solutions module, following the same standards applied to Models and Serialization modules.

Changes:

  • Added # Returns and # Arguments sections to all accessors in build_solution.jl (20 functions: state, control, variable, costate, times, dimensions)
  • Added # Returns and See also: to dual accessors in dual_model.jl (8 functions)
  • Added See also: to interpolation helpers in interpolation_helpers.jl (3 functions)
  • Enriched Solutions.jl module docstring with # Public API, # Dependencies, # See also sections
  • Ensured all cross-references use full paths (CTModels.Solutions., CTModels.Models.)

Conformity:

  • All docstrings now conform to project standards with active descriptions and complete sections
  • Consistent with Models and Serialization modules
  • All tests pass (3734 tests)

ocots added 3 commits June 14, 2026 11:13
- Fixed CTModels.Components.Base.time invalid refs in accessors.jl and times_accessors.jl
- Fixed CTModels.Models.xxx → CTModels.Components.xxx refs in model.jl (23 patterns)
- Fixed CTModels.Models.xxx → CTModels.Components.xxx refs in build_solution.jl (11 patterns)
- Fixed CTModels.Components.{state,control,variable}_dimension → CTModels.Models.xxx in Building files
- Removed unresolvable module @refs in Display.jl and Init.jl
- All Cannot resolve @ref warnings now resolved
@ocots ocots merged commit 5ba4c9d into main Jun 14, 2026
4 checks passed
@ocots ocots deleted the test/orthogonal-suite branch June 14, 2026 09:53
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.

1 participant