mirror of
https://github.com/sile/hls_m3u8.git
synced 2024-11-22 07:10:59 +00:00
improve code coverage of (U)Float
This commit is contained in:
parent
5972216323
commit
e1c10d27f7
2 changed files with 73 additions and 6 deletions
|
@ -177,6 +177,7 @@ impl ::core::hash::Hash for Float {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use core::hash::{Hash, Hasher};
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
|
@ -202,6 +203,29 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hash() {
|
||||
let mut hasher_left = std::collections::hash_map::DefaultHasher::new();
|
||||
let mut hasher_right = std::collections::hash_map::DefaultHasher::new();
|
||||
|
||||
assert_eq!(
|
||||
Float::new(0.0).hash(&mut hasher_left),
|
||||
Float::new(-0.0).hash(&mut hasher_right)
|
||||
);
|
||||
|
||||
assert_eq!(hasher_left.finish(), hasher_right.finish());
|
||||
|
||||
let mut hasher_left = std::collections::hash_map::DefaultHasher::new();
|
||||
let mut hasher_right = std::collections::hash_map::DefaultHasher::new();
|
||||
|
||||
assert_eq!(
|
||||
Float::new(1.0).hash(&mut hasher_left),
|
||||
Float::new(1.0).hash(&mut hasher_right)
|
||||
);
|
||||
|
||||
assert_eq!(hasher_left.finish(), hasher_right.finish());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_eq() {
|
||||
struct _AssertEq
|
||||
|
@ -213,6 +237,7 @@ mod tests {
|
|||
fn test_partial_eq() {
|
||||
assert_eq!(Float::new(1.0).eq(&Float::new(1.0)), true);
|
||||
assert_eq!(Float::new(1.0).eq(&Float::new(33.3)), false);
|
||||
assert_eq!(Float::new(1.1), 1.1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -188,6 +188,7 @@ impl ::core::hash::Hash for UFloat {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use core::hash::{Hash, Hasher};
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
|
@ -213,6 +214,49 @@ mod tests {
|
|||
assert!(UFloat::from_str("-inf").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hash() {
|
||||
let mut hasher_left = std::collections::hash_map::DefaultHasher::new();
|
||||
let mut hasher_right = std::collections::hash_map::DefaultHasher::new();
|
||||
|
||||
assert_eq!(
|
||||
UFloat::new(1.0).hash(&mut hasher_left),
|
||||
UFloat::new(1.0).hash(&mut hasher_right)
|
||||
);
|
||||
|
||||
assert_eq!(hasher_left.finish(), hasher_right.finish());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ord() {
|
||||
assert_eq!(UFloat::new(1.1).cmp(&UFloat::new(1.1)), Ordering::Equal);
|
||||
assert_eq!(UFloat::new(1.1).cmp(&UFloat::new(2.1)), Ordering::Less);
|
||||
assert_eq!(UFloat::new(1.1).cmp(&UFloat::new(0.1)), Ordering::Greater);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_partial_ord() {
|
||||
assert_eq!(
|
||||
UFloat::new(1.1).partial_cmp(&UFloat::new(1.1)),
|
||||
Some(Ordering::Equal)
|
||||
);
|
||||
assert_eq!(
|
||||
UFloat::new(1.1).partial_cmp(&UFloat::new(2.1)),
|
||||
Some(Ordering::Less)
|
||||
);
|
||||
assert_eq!(
|
||||
UFloat::new(1.1).partial_cmp(&UFloat::new(0.1)),
|
||||
Some(Ordering::Greater)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_partial_eq() {
|
||||
assert_eq!(UFloat::new(1.0).eq(&UFloat::new(1.0)), true);
|
||||
assert_eq!(UFloat::new(1.0).eq(&UFloat::new(33.3)), false);
|
||||
assert_eq!(UFloat::new(1.1), 1.1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic = "float must be positive: `-1.1`"]
|
||||
fn test_new_negative() { UFloat::new(-1.1); }
|
||||
|
@ -233,11 +277,6 @@ mod tests {
|
|||
#[should_panic = "float must not be `NaN`"]
|
||||
fn test_new_nan() { UFloat::new(::core::f32::NAN); }
|
||||
|
||||
#[test]
|
||||
fn test_partial_eq() {
|
||||
assert_eq!(UFloat::new(1.1), 1.1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_as_f32() {
|
||||
assert_eq!(UFloat::new(1.1).as_f32(), 1.1_f32);
|
||||
|
@ -253,7 +292,10 @@ mod tests {
|
|||
fn test_try_from() {
|
||||
assert_eq!(UFloat::try_from(1.1_f32).unwrap(), UFloat::new(1.1));
|
||||
|
||||
assert!(UFloat::try_from(-1.1_f32).is_err());
|
||||
assert_eq!(
|
||||
UFloat::try_from(-1.1_f32),
|
||||
Err(Error::custom("float must be positive: `-1.1`"))
|
||||
);
|
||||
assert!(UFloat::try_from(::core::f32::INFINITY).is_err());
|
||||
assert!(UFloat::try_from(::core::f32::NAN).is_err());
|
||||
assert!(UFloat::try_from(::core::f32::NEG_INFINITY).is_err());
|
||||
|
|
Loading…
Reference in a new issue