Skip to content

Add direct CvDTree / CvDTreeTrainData unit tests#26

Merged
vladiant merged 1 commit into
mainfrom
add_cvdtree_train_tests
Apr 30, 2026
Merged

Add direct CvDTree / CvDTreeTrainData unit tests#26
vladiant merged 1 commit into
mainfrom
add_cvdtree_train_tests

Conversation

@vladiant
Copy link
Copy Markdown
Owner

Summary

Adds 8 direct unit tests for the legacy decision-tree implementation (CvDTree, CvDTreeTrainData) — the two largest uncovered files in TrainCascadeLib. Tests use tiny in-memory cv::Mat datasets and exercise both the high-level train(cv::Mat, ...) entry point and the shared-data overload train(CvDTreeTrainData*, ...) that CvBoostTree / CvCascadeBoostTree use internally.

Motivation

Coverage analysis identified o_cvdtree.cpp (10%) and o_cvdtreetraindata.cpp (cold) as the largest remaining gaps. The cascade trainer drives these classes only indirectly through the boosting layer, so prior end-to-end tests left their core data-prep / split / predict paths largely untouched.

Changes

New file: test_dtree.cpp

Group Test cases
CvDTree::train(cv::Mat ...) trains on 1-D separable dataset and builds a root; classifies every training point correctly; generalises to held-out points on each side of the margin; clear() drops the trained tree; re-training on the same instance produces a fresh tree
CvDTree::train(CvDTreeTrainData*) trains successfully against an externally-built CvDTreeTrainData
CvDTreeTrainData reports correct is_classifier / sample_count / var_count / get_num_classes() / get_var_type() after set_data; clear() is safe on a default-constructed instance

Helpers (file-local):

  • makeOneDimSeparableDataset() — 10 samples, 2 classes, clean margin at x = 0.5.
  • makeTinyParams()max_depth = 3, min_sample_count = 1, no surrogates / CV-folds (required for tiny datasets).
  • sample1D(value) — 1×1 CV_32F row for predict().

All tests follow the project's Arrange / Act / Assert convention with comments per step.

Updated: CMakeLists.txt — registers test/test_dtree.cpp in the test_traincascade target.

Verification

[doctest] test cases:  96 |  96 passed | 0 failed | 0 skipped
[doctest] assertions: 321 | 321 passed | 0 failed |
[doctest] Status: SUCCESS!

Test-suite runtime unchanged (~17 s).

Coverage impact

Metric Before After Δ
Lines 44.4% (2077 / 4676) 57.5% (2687 / 4676) +13.1 pp
Functions 79.1% (204 / 258) 86.4% (223 / 258) +7.3 pp
Branches 28.8% (1443 / 5006) 36.8% (1840 / 5006) +8.0 pp

Single largest coverage uplift in the test-suite history — activates ~610 previously-uncovered lines across o_cvdtree.cpp and o_cvdtreetraindata.cpp.

Risk

Test-only change. No production source modified.

Checklist

  • All 96 tests pass locally (clang 18, Linux, OpenCV 4.6).
  • Coverage verified with gcovr against the GCC 13 instrumented build.
  • No new compiler warnings.
  • Follows existing AAA-with-comments doctest pattern used elsewhere in test.

@vladiant vladiant merged commit 7901351 into main Apr 30, 2026
7 checks passed
@vladiant vladiant deleted the add_cvdtree_train_tests branch April 30, 2026 06:04
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