mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 20:15:07 +08:00
tests
This commit is contained in:
parent
d3916f28aa
commit
83f50914ec
@ -198,3 +198,70 @@ impl<'a> Condition<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use serde_json::Number;
|
||||
use std::cmp::Ordering;
|
||||
|
||||
#[test]
|
||||
fn test_number_comp() {
|
||||
// test both u64
|
||||
let n1 = Number::from(1u64);
|
||||
let n2 = Number::from(2u64);
|
||||
assert_eq!(Some(Ordering::Less), compare_numbers(&n1, &n2));
|
||||
assert_eq!(Some(Ordering::Greater), compare_numbers(&n2, &n1));
|
||||
let n1 = Number::from(1u64);
|
||||
let n2 = Number::from(1u64);
|
||||
assert_eq!(Some(Ordering::Equal), compare_numbers(&n1, &n2));
|
||||
|
||||
// test both i64
|
||||
let n1 = Number::from(1i64);
|
||||
let n2 = Number::from(2i64);
|
||||
assert_eq!(Some(Ordering::Less), compare_numbers(&n1, &n2));
|
||||
assert_eq!(Some(Ordering::Greater), compare_numbers(&n2, &n1));
|
||||
let n1 = Number::from(1i64);
|
||||
let n2 = Number::from(1i64);
|
||||
assert_eq!(Some(Ordering::Equal), compare_numbers(&n1, &n2));
|
||||
|
||||
// test both f64
|
||||
let n1 = Number::from_f64(1f64).unwrap();
|
||||
let n2 = Number::from_f64(2f64).unwrap();
|
||||
assert_eq!(Some(Ordering::Less), compare_numbers(&n1, &n2));
|
||||
assert_eq!(Some(Ordering::Greater), compare_numbers(&n2, &n1));
|
||||
let n1 = Number::from_f64(1f64).unwrap();
|
||||
let n2 = Number::from_f64(1f64).unwrap();
|
||||
assert_eq!(Some(Ordering::Equal), compare_numbers(&n1, &n2));
|
||||
|
||||
// test one u64 and one f64
|
||||
let n1 = Number::from_f64(1f64).unwrap();
|
||||
let n2 = Number::from(2u64);
|
||||
assert_eq!(Some(Ordering::Less), compare_numbers(&n1, &n2));
|
||||
assert_eq!(Some(Ordering::Greater), compare_numbers(&n2, &n1));
|
||||
|
||||
// equality
|
||||
let n1 = Number::from_f64(1f64).unwrap();
|
||||
let n2 = Number::from(1u64);
|
||||
assert_eq!(Some(Ordering::Equal), compare_numbers(&n1, &n2));
|
||||
assert_eq!(Some(Ordering::Equal), compare_numbers(&n2, &n1));
|
||||
|
||||
// float is neg
|
||||
let n1 = Number::from_f64(-1f64).unwrap();
|
||||
let n2 = Number::from(1u64);
|
||||
assert_eq!(Some(Ordering::Less), compare_numbers(&n1, &n2));
|
||||
assert_eq!(Some(Ordering::Greater), compare_numbers(&n2, &n1));
|
||||
|
||||
// float is too big
|
||||
let n1 = Number::from_f64(std::f64::MAX).unwrap();
|
||||
let n2 = Number::from(1u64);
|
||||
assert_eq!(Some(Ordering::Greater), compare_numbers(&n1, &n2));
|
||||
assert_eq!(Some(Ordering::Less), compare_numbers(&n2, &n1));
|
||||
|
||||
// misc
|
||||
let n1 = Number::from_f64(std::f64::MAX).unwrap();
|
||||
let n2 = Number::from(std::u64::MAX);
|
||||
assert_eq!(Some(Ordering::Greater), compare_numbers(&n1, &n2));
|
||||
assert_eq!(Some( Ordering::Less ), compare_numbers(&n2, &n1));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user