Skip to content

Expand integration & feature test coverage#27

Merged
vladiant merged 3 commits into
mainfrom
add_multi_stage_integration_tests
Apr 30, 2026
Merged

Expand integration & feature test coverage#27
vladiant merged 3 commits into
mainfrom
add_multi_stage_integration_tests

Conversation

@vladiant
Copy link
Copy Markdown
Owner

Summary

Adds three test groups around CvCascadeClassifier and CvHaarEvaluator::Feature::calc to lift coverage on previously partially-tested paths. All new tests follow the project's Arrange / Act / Assert convention with comments per step.

Changes

1. Multi-stage cascade integration test — test_integration.cpp

  • New test: CvCascadeClassifier::train with numStages=2, maxWeakCount=3, maxDepth=2, LBP / gentle boost.
  • Drives the boost outer loop for more than one stage and the recursive split path in o_cvboostree.cpp (depth > 1), plus the inter-stage sample-weight update in boost.cpp.
  • Verifies stage0.xml, cascade.xml, params.xml are produced and the cascade is loadable by the public cv::CascadeClassifier.

2. HAAR feature-set integration variants — test_integration.cpp

  • HAAR CORE mode produces a usable cascade — exercises the diagonal/centred Haar branch in CvHaarEvaluator::generateFeatures.
  • HAAR ALL mode produces a usable cascade — exercises the 45-degree rotated branch.

3. Direct CvHaarEvaluator::Feature::calc tests — test_features.cpp

  • Exposes the protected nested Feature type via a thin HaarFeatureProbe : public CvHaarEvaluator subclass.
  • upright two-rect feature on a vertical-step image — explicit numeric expectation (−3200) on a known integral image.
  • upright feature returns zero on a uniform image — sanity / balanced filter.
  • upright three-rect feature uses rect[2] when its weight is non-zero — covers the conditional third-rectangle branch in the inline calc().
  • tilted-feature branch reads the tilted integral image — drives the tilted ? _tilted : _sum branch via CV_TILTED_OFFSETS and asserts the rotated-rect area on an all-ones image (2·w·h = 32, documented in the test).
  • Adds <opencv2/imgproc.hpp> for cv::integral.

Verification

[doctest] test cases: 103 | 103 passed | 0 failed | 0 skipped
[doctest] assertions: 345 | 345 passed | 0 failed |
[doctest] Status: SUCCESS!

Test-suite runtime ~26 s (was ~17 s; the extra time is the multi-stage integration test running both numStages=2 and the two additional HAAR variants).

Coverage impact

Metric Before After
Lines 57.5% (2687 / 4676) 57.7% (2697 / 4676)
Functions 86.4% (223 / 258) 86.4% (223 / 258)
Branches 36.8% (1840 / 5006) 37.2% (1857 / 5006)

Per-file highlights:

File Before After
haarfeatures.cpp ~73% 75%
boost.cpp (boost loop) ~70% 70%
o_cvboostree.cpp (depth>1) ~41% 41%

Most of the integration changes only flip a small number of branches because the existing single-stage HAAR BASIC test already covers the bulk of haarfeatures.cpp; the direct Feature::calc tests give the largest line/branch lift in this MR.

Risk

Test-only change. No production source modified. The HaarFeatureProbe subclass merely re-exposes a protected nested type for white-box testing — it does not override any virtual methods.

Checklist

  • All 103 tests pass locally (clang 18 / Linux / OpenCV 4.6).
  • Coverage verified with gcovr against the GCC 13 instrumented build.
  • No new compiler warnings.
  • AAA-with-comments doctest pattern followed throughout.

@vladiant vladiant merged commit 9d172a2 into main Apr 30, 2026
7 checks passed
@vladiant vladiant deleted the add_multi_stage_integration_tests branch April 30, 2026 06:38
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