Skip to content

Commit

Permalink
fix partial_min bug
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Apr 27, 2020
1 parent ea06578 commit ff08c8a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion geo/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,26 @@ pub fn partial_max<T: PartialOrd>(a: T, b: T) -> T {

// The Rust standard library has `min` for `Ord`, but not for `PartialOrd`
pub fn partial_min<T: PartialOrd>(a: T, b: T) -> T {
if a > b {
if a < b {
a
} else {
b
}
}

#[cfg(test)]
mod test {
use super::{partial_max, partial_min};

#[test]
fn test_partial_max() {
assert_eq!(5, partial_max(5, 4));
assert_eq!(5, partial_max(5, 5));
}

#[test]
fn test_partial_min() {
assert_eq!(4, partial_min(5, 4));
assert_eq!(4, partial_min(4, 4));
}
}

0 comments on commit ff08c8a

Please sign in to comment.