Skip to content

fix(metrics): compile and run the metrics edge-case tests - #538

Open
EnesKartal wants to merge 1 commit into
smartcorelib:mainfrom
EnesKartal:fix/metrics-edge-case-tests
Open

EnesKartal wants to merge 1 commit into
smartcorelib:mainfrom
EnesKartal:fix/metrics-edge-case-tests

Conversation

@EnesKartal

Copy link
Copy Markdown

Fixes #535

Checklist

  • My branch is up-to-date with main branch.
  • Everything works and tested on latest stable Rust.
  • Coverage and Linting have been applied

Current behaviour

src/metrics/tests_edge_cases.rs is not declared in src/metrics/mod.rs, so its 26 tests are never built. If you declare it, it does not compile:

  • it imports MeanSquaredError, but the type is MeanSquareError;
  • the HCV tests import homogeneity_score, completeness_score and v_measure_score from metrics::cluster_hcv, but these functions are in metrics;
  • these three functions require T: Number + FloatNumber + RealNumber + Ord. FloatNumber is only on f32/f64, which are not Ord, so no type can call them.

New expected behaviour

  • mod.rs declares #[cfg(test)] mod tests_edge_cases;, and the imports are fixed.
  • homogeneity_score, completeness_score and v_measure_score now use T: Number + Ord. This is the bound of ClusterMetrics::hcv_score(), which is the only thing they call. The bounds are less strict than before, so no caller breaks, and the functions now work with integer labels (for example Vec<u32>), as the HCV edge-case tests use them.
  • cargo fmt reformatted the test file (it was never checked before, because it was not part of the crate). I also changed four x >= 0.0 && x <= 1.0 asserts to (0.0..=1.0).contains(&x) so that cargo clippy --all-targets has no warnings in the file.

Test plan

# before (main): the edge-case tests are not part of the build
$ cargo test --lib metrics
test result: ok. 54 passed; 0 failed; ...

# before, with only the `mod tests_edge_cases;` line added
error[E0432]: unresolved import `crate::metrics::mean_squared_error::MeanSquaredError`
error[E0432]: unresolved imports `crate::metrics::cluster_hcv::homogeneity_score`, ...

# after
$ cargo test --lib metrics_edge_cases
test result: ok. 26 passed; 0 failed; ...
$ cargo test --lib metrics
test result: ok. 80 passed; 0 failed; ...

cargo fmt --check and cargo clippy --all-features --all-targets -- -Drust-2018-idioms show nothing for the changed files.

Note: the other tests_edge_cases.rs files (cluster, decomposition, ensemble, linear, naive_bayes, neighbors, svm, tree) are also not declared in their mod.rs. I did not change them in this PR, to keep it focused on #535.

Change logs

Changed

  • homogeneity_score, completeness_score and v_measure_score accept T: Number + Ord labels.
  • The metrics edge-case tests are compiled and run.

src/metrics/tests_edge_cases.rs was not declared in src/metrics/mod.rs,
so its tests were never built. Declare the module and fix the imports:
the regression type is MeanSquareError, and the HCV free functions live
in crate::metrics, not in cluster_hcv.

homogeneity_score, completeness_score and v_measure_score required
T: Number + FloatNumber + RealNumber + Ord. No type meets these bounds,
so nothing could call them. They only call ClusterMetrics::hcv_score,
which needs T: Number + Ord, so use the same bounds.

Closes smartcorelib#535
@EnesKartal
EnesKartal requested a review from Mec-iS as a code owner November 14, 2026 12:10
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.

tests_edge_cases.rs in metrics is never compiled

1 participant