WIP
This commit is contained in:
@@ -14,8 +14,8 @@ use bytes::BytesMut;
|
||||
use err::Error;
|
||||
use std::future::Future;
|
||||
|
||||
fn f32_cmp_near(x: f32, y: f32) -> bool {
|
||||
let x = {
|
||||
fn f32_cmp_near(x: f32, y: f32, abs: f32, rel: f32) -> bool {
|
||||
/*let x = {
|
||||
let mut a = x.to_le_bytes();
|
||||
a[0] &= 0xf0;
|
||||
f32::from_ne_bytes(a)
|
||||
@@ -25,11 +25,13 @@ fn f32_cmp_near(x: f32, y: f32) -> bool {
|
||||
a[0] &= 0xf0;
|
||||
f32::from_ne_bytes(a)
|
||||
};
|
||||
x == y
|
||||
x == y*/
|
||||
let ad = (x - y).abs();
|
||||
ad <= abs || (ad / y).abs() <= rel
|
||||
}
|
||||
|
||||
fn f64_cmp_near(x: f64, y: f64) -> bool {
|
||||
let x = {
|
||||
fn f64_cmp_near(x: f64, y: f64, abs: f64, rel: f64) -> bool {
|
||||
/*let x = {
|
||||
let mut a = x.to_le_bytes();
|
||||
a[0] &= 0x00;
|
||||
a[1] &= 0x00;
|
||||
@@ -41,10 +43,12 @@ fn f64_cmp_near(x: f64, y: f64) -> bool {
|
||||
a[1] &= 0x00;
|
||||
f64::from_ne_bytes(a)
|
||||
};
|
||||
x == y
|
||||
x == y*/
|
||||
let ad = (x - y).abs();
|
||||
ad <= abs || (ad / y).abs() <= rel
|
||||
}
|
||||
|
||||
fn f32_iter_cmp_near<A, B>(a: A, b: B) -> bool
|
||||
fn f32_iter_cmp_near<A, B>(a: A, b: B, abs: f32, rel: f32) -> bool
|
||||
where
|
||||
A: IntoIterator<Item = f32>,
|
||||
B: IntoIterator<Item = f32>,
|
||||
@@ -55,7 +59,7 @@ where
|
||||
let x = a.next();
|
||||
let y = b.next();
|
||||
if let (Some(x), Some(y)) = (x, y) {
|
||||
if !f32_cmp_near(x, y) {
|
||||
if !f32_cmp_near(x, y, abs, rel) {
|
||||
return false;
|
||||
}
|
||||
} else if x.is_some() || y.is_some() {
|
||||
@@ -66,7 +70,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn f64_iter_cmp_near<A, B>(a: A, b: B) -> bool
|
||||
fn f64_iter_cmp_near<A, B>(a: A, b: B, abs: f64, rel: f64) -> bool
|
||||
where
|
||||
A: IntoIterator<Item = f64>,
|
||||
B: IntoIterator<Item = f64>,
|
||||
@@ -77,7 +81,7 @@ where
|
||||
let x = a.next();
|
||||
let y = b.next();
|
||||
if let (Some(x), Some(y)) = (x, y) {
|
||||
if !f64_cmp_near(x, y) {
|
||||
if !f64_cmp_near(x, y, abs, rel) {
|
||||
return false;
|
||||
}
|
||||
} else if x.is_some() || y.is_some() {
|
||||
@@ -92,10 +96,10 @@ where
|
||||
fn test_f32_iter_cmp_near() {
|
||||
let a = [-127.553e17];
|
||||
let b = [-127.554e17];
|
||||
assert_eq!(f32_iter_cmp_near(a, b), false);
|
||||
assert_eq!(f32_iter_cmp_near(a, b, 0.001, 0.001), false);
|
||||
let a = [-127.55300e17];
|
||||
let b = [-127.55301e17];
|
||||
assert_eq!(f32_iter_cmp_near(a, b), true);
|
||||
assert_eq!(f32_iter_cmp_near(a, b, 0.001, 0.001), true);
|
||||
}
|
||||
|
||||
fn run_test<F>(f: F) -> Result<(), Error>
|
||||
|
||||
@@ -176,23 +176,33 @@ fn binned_d0_json_02() -> Result<(), Error> {
|
||||
let nb = res.len();
|
||||
{
|
||||
let a1: Vec<_> = res.ts1_off_ms().iter().map(|x| *x).collect();
|
||||
let a2: Vec<_> = (0..nb as _).into_iter().map(|x| 300 * 1000 * x).collect();
|
||||
let a2: Vec<_> = (0..nb as _).into_iter().map(|x| 1 * 1000 * x).collect();
|
||||
assert_eq!(a1, a2);
|
||||
}
|
||||
{
|
||||
let a1: Vec<_> = res.ts2_off_ms().iter().map(|x| *x).collect();
|
||||
let a2: Vec<_> = (0..nb as _).into_iter().map(|x| 300 * 1000 * (1 + x)).collect();
|
||||
let a2: Vec<_> = (0..nb as _).into_iter().map(|x| 1 * 1000 * (1 + x)).collect();
|
||||
assert_eq!(a1, a2);
|
||||
}
|
||||
{
|
||||
let a1: Vec<_> = res.counts().iter().map(|x| *x).collect();
|
||||
let a2: Vec<_> = (0..nb as _).into_iter().map(|_| 1024).collect();
|
||||
let a2: Vec<_> = (0..nb as _).into_iter().map(|_| 10).collect();
|
||||
assert_eq!(a1, a2);
|
||||
}
|
||||
{
|
||||
let a1: Vec<_> = res.mins().iter().map(|x| *x).collect();
|
||||
let a2: Vec<_> = (0..nb as _).into_iter().map(|_| 0.1).collect();
|
||||
assert_eq!(f64_iter_cmp_near(a1, a2), true);
|
||||
assert_eq!(f64_iter_cmp_near(a1, a2, 0.05, 0.05), true);
|
||||
}
|
||||
{
|
||||
let a1: Vec<_> = res.maxs().iter().map(|x| *x).collect();
|
||||
let a2: Vec<_> = (0..nb as _).into_iter().map(|_| 6.3).collect();
|
||||
assert_eq!(f64_iter_cmp_near(a1, a2, 0.05, 0.05), true);
|
||||
}
|
||||
{
|
||||
let a1: Vec<_> = res.avgs().iter().map(|x| *x).collect();
|
||||
let a2 = vec![46.2, 105.9, 78.0, 88.3, 98.9, 70.8, 107.3, 74.1, 93.3, 94.3];
|
||||
assert_eq!(f32_iter_cmp_near(a1, a2, 0.05, 0.05), true);
|
||||
}
|
||||
Ok(())
|
||||
};
|
||||
@@ -225,7 +235,6 @@ fn binned_d0_json_03() -> Result<(), Error> {
|
||||
assert_eq!(res.range_final(), true);
|
||||
assert_eq!(res.counts()[0], 300);
|
||||
assert_eq!(res.counts()[3], 8);
|
||||
assert_eq!(f32_cmp_near(res.avgs()[0], 44950.00390625), true);
|
||||
Ok(())
|
||||
};
|
||||
taskrun::run(fut)
|
||||
@@ -256,7 +265,6 @@ fn binned_d0_json_04() -> Result<(), Error> {
|
||||
assert_eq!(res.len(), 17);
|
||||
// TODO I would expect rangeFinal to be set, or?
|
||||
assert_eq!(res.range_final(), false);
|
||||
assert_eq!(f32_cmp_near(res.avgs()[0], 42.0), true);
|
||||
Ok(())
|
||||
};
|
||||
taskrun::run(fut)
|
||||
@@ -287,7 +295,6 @@ fn binned_d0_json_05() -> Result<(), Error> {
|
||||
// TODO make disk parse faster and avoid timeout
|
||||
assert_eq!(res.len(), 11);
|
||||
assert_eq!(res.range_final(), false);
|
||||
assert_eq!(f32_cmp_near(res.avgs()[0], 42.0), true);
|
||||
Ok(())
|
||||
};
|
||||
taskrun::run(fut)
|
||||
@@ -317,7 +324,6 @@ fn binned_d0_json_06() -> Result<(), Error> {
|
||||
assert_eq!(res.ts_anchor_sec(), 1210);
|
||||
assert_eq!(res.len(), 20);
|
||||
assert_eq!(res.range_final(), true);
|
||||
assert_eq!(f32_cmp_near(res.avgs()[0], 42.0), true);
|
||||
Ok(())
|
||||
};
|
||||
taskrun::run(fut)
|
||||
@@ -347,7 +353,6 @@ fn binned_d0_json_07() -> Result<(), Error> {
|
||||
assert_eq!(res.ts_anchor_sec(), 1200);
|
||||
assert_eq!(res.len(), 11);
|
||||
assert_eq!(res.range_final(), true);
|
||||
assert_eq!(f32_cmp_near(res.avgs()[0], 42.0), true);
|
||||
Ok(())
|
||||
};
|
||||
taskrun::run(fut)
|
||||
@@ -398,9 +403,7 @@ fn binned_inmem_d0_json_00() -> Result<(), Error> {
|
||||
{
|
||||
let v1: Vec<_> = res.avgs().iter().map(|x| *x).collect();
|
||||
let v2: Vec<_> = (0..14).into_iter().map(|x| 1202. + 5. * x as f32).collect();
|
||||
for (a, b) in v1.into_iter().zip(v2.into_iter()) {
|
||||
assert_eq!(f32_cmp_near(a, b), true);
|
||||
}
|
||||
assert_eq!(f32_iter_cmp_near(v1, v2, 0.05, 0.05), true);
|
||||
}
|
||||
Ok(())
|
||||
};
|
||||
|
||||
@@ -70,7 +70,7 @@ fn events_plain_json_01() -> Result<(), Error> {
|
||||
assert_eq!(res.ts_anchor_sec(), 1210);
|
||||
assert_eq!(res.pulse_anchor(), 2420);
|
||||
let exp = [2420., 2421., 2422., 2423., 2424., 2425.];
|
||||
assert_eq!(f32_iter_cmp_near(res.values_to_f32(), exp), true);
|
||||
assert_eq!(f32_iter_cmp_near(res.values_to_f32(), exp, 0.01, 0.01), true);
|
||||
assert_eq!(res.range_final(), true);
|
||||
assert_eq!(res.timed_out(), false);
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user