Skip to content

Extend CvDTree branch coverage (regression / 2-D / pruning / sampleIdx)#28

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

Extend CvDTree branch coverage (regression / 2-D / pruning / sampleIdx)#28
vladiant merged 1 commit into
mainfrom
extend_branch_test_coverage

Conversation

@vladiant
Copy link
Copy Markdown
Owner

Summary

Adds 4 direct unit tests for CvDTree::train that drive code paths the cascade trainer never touches (it always runs depth-1 classification without surrogates, regression, or CV folds). All tests follow the project's Arrange / Act / Assert convention with comments per step.

Changes

Modified: test_dtree.cpp

# Test case Drives
1 regression mode learns a step-function on a 1-D dataset varType = (ORDERED, ORDERED) + regression_accuracy = 0.01find_split_ord_reg, regression branch of calc_node_value
2 2-D classification picks an axis-aligned split 2 ordered features + 1 categorical response → multi-variable scan in find_best_split (DTreeBestSplitFinder)
3 cv_folds pruning produces a usable tree on a noisy dataset 60 samples, cv_folds = 3, use_1se_rule = true, truncate_pruned_tree = trueprune_cv / free_prune_data / fold-allocation paths
4 sampleIdx mask trains on the selected subset only 8U mask of length sample_count (selects 6 / 10 rows) → sample-mask preprocessing in CvDTreeTrainData::set_data

No production source modified.

Verification

[doctest] test cases: 107 | 107 passed | 0 failed | 0 skipped
[doctest] assertions: 360 | 360 passed | 0 failed |
[doctest] Status: SUCCESS!

Coverage impact

Metric Before After Δ
Lines 57.7% (2697 / 4676) 62.3% (2912 / 4676) +4.6 pp
Functions 86.4% (223 / 258) 88.0% (227 / 258) +1.6 pp
Branches 37.2% (1857 / 5006) 40.7% (2037 / 5006) +3.5 pp

Net gain: +215 lines and +180 branches covered, concentrated in the previously cold legacy CART machinery:

File Before After
o_cvdtree.cpp ~34% (improved)
o_cvdtreetraindata.cpp ~57% (improved)
o_cvboostree.cpp ~41% (improved)
o_cvcascadeboosttree.cpp ~51% (improved)

(Per-file deltas: regression test alone exercises the regression branch of calc_node_value and find_split_ord_reg; the cv_folds test exercises the prune / fold-allocation paths; the sampleIdx mask test exercises the sample-preprocessing branch in set_data.)

Risk

Test-only change. No production source modified.

Notes

  • CvDTreeTrainData rejects cv_folds when per-fold sample count is too low — pruning test uses 60 samples / 3 folds for that reason (documented inline).
  • sampleIdx test uses an 8U mask rather than a 32S index array; both paths were considered, the mask form additionally walks the mask-expansion branch in set_data.

Checklist

  • All 107 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 c4f9ef2 into main Apr 30, 2026
7 checks passed
@vladiant vladiant deleted the extend_branch_test_coverage branch April 30, 2026 06:58
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