Skip to content

Commit

Permalink
chore: simple lints
Browse files Browse the repository at this point in the history
also derives Eq for DiscreteUniform distribution
  • Loading branch information
YeungOnion committed Dec 2, 2024
1 parent b4f822e commit 2ac6ac6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/distribution/discrete_uniform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::statistics::*;
/// assert_eq!(n.mean().unwrap(), 2.5);
/// assert_eq!(n.pmf(3), 1.0 / 6.0);
/// ```
#[derive(Copy, Clone, PartialEq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct DiscreteUniform {
min: i64,
max: i64,
Expand Down
10 changes: 3 additions & 7 deletions src/distribution/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@ pub fn integral_bisection_search<K: Num + Clone, T: Num + PartialOrd>(
loop {
let mid = (lb.clone() + ub.clone()) / two.clone();
if !(f(&lb)..=f(&ub)).contains(&f(&mid)) {
// if f found not monotone on the interval
return None;
return None; // f found not monotone on interval

Check warning on line 27 in src/distribution/internal.rs

View check run for this annotation

Codecov / codecov/patch

src/distribution/internal.rs#L27

Added line #L27 was not covered by tests
} else if f(&lb) == z {
return Some(lb);
} else if f(&ub) == z {
return Some(ub);
} else if (lb.clone() + K::one()) == ub {
// no more elements to search
return Some(ub);
} else if f(&ub) == z || (lb.clone() + K::one()) == ub {
return Some(ub); // found or no more integers between
} else if f(&mid) >= z {
ub = mid;
} else {
Expand Down

0 comments on commit 2ac6ac6

Please sign in to comment.