Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1131 +/- ##
==========================================
- Coverage 94.38% 93.82% -0.57%
==========================================
Files 48 52 +4
Lines 6665 6491 -174
==========================================
- Hits 6291 6090 -201
- Misses 374 401 +27 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| if n < k { | ||
| return 0; | ||
| } | ||
| // Same algorithm as `checked_binomial` in `src/adaptors/mod.rs`. |
There was a problem hiding this comment.
If it's the same algorithm, can't we just call checked_binomial?
There was a problem hiding this comment.
Because checked_binomial is pub(crate) inside the private adaptors module, it isn't visible to the integration test crates in tests/.
If you'd prefer to share the implementation across tests rather than keeping the local helper, I can expose it with #[doc(hidden)] pub use crate::adaptors::checked_binomial; in lib.rs and call it here as itertools::checked_binomial(n, k).unwrap_or(0). Would you like me to do that?
There was a problem hiding this comment.
If it's really supposed to be the same code. I very much prefer this.
Or, alternatively, move the tests to src. I do not even know if we have a good reason to keep them under a separate directory, especially if we have [test] within src already.
@jswrenn opinions on this?
There was a problem hiding this comment.
Addressed in e6fce47: both integration-test helpers now reuse checked_binomial through a #[doc(hidden)] re-export. All 656 integration/doc tests passed, along with the helper unit test, no_std checks, docs, and formatting. Strict Clippy reports the same four pre-existing question_mark warnings as the previous PR head.
The naive product-then-divide binomial helper overflowed usize (C(27, 7) on 32-bit, C(21, 19) even on 64-bit). Use the same overflow-safe algorithm as checked_binomial.
30a5656 to
3de7650
Compare
Fixes #995.
combinations_inexact_size_hintspanics on 32-bit because the test helper computes binomial coefficients with a naive product-then-divide. That overflowsusizeeven when the result fits (C(27, 7)on 32-bit;C(21, 19)even on 64-bit).Both integration-test helpers now call the existing
checked_binomialimplementation through a#[doc(hidden)]re-export, as requested in review. The overflow regression remains in place. The wrappers useunwrap()so an actually unrepresentable coefficient still fails the test rather than silently becoming zero.Verification
On macOS aarch64 with Rust 1.98.1:
cargo test --all-features --quiet: 446 integration tests and 210 documentation tests passed.cargo test --lib --all-features test_checked_binomial --quiet: passed.cargo check --no-default-features --quiet: passed.cargo check --no-default-features --features use_alloc --quiet: passed.RUSTDOCFLAGS=-Dwarnings cargo doc --all-features --no-deps --quiet: passed.cargo fmt --all -- --checkandgit diff --check: passed.Strict Clippy (
RUSTFLAGS="--deny warnings" cargo clippy --all-targets --all-features --quiet) reports four existingclippy::question_markwarnings outside the changed code. Reproduced the same four warnings on the previous PR head,3de765066ea0fbfa770bb5d609f722588e981c43; this follow-up does not modify unrelated code or suppress those lints.32-bit execution, Rust 1.63 MSRV, and Miri were not run locally.