From 13ed1b96a2a4743ebbcc6aa515ebed0cb55012e5 Mon Sep 17 00:00:00 2001 From: m5l14i11 Date: Sat, 1 Jul 2023 16:42:08 +0400 Subject: [PATCH] fix test --- ta_lib/volatility/src/atr.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ta_lib/volatility/src/atr.rs b/ta_lib/volatility/src/atr.rs index e5b489eb..30d46af6 100644 --- a/ta_lib/volatility/src/atr.rs +++ b/ta_lib/volatility/src/atr.rs @@ -28,11 +28,20 @@ mod tests { let low = vec![1.0, 2.0, 3.0]; let close = vec![1.5, 3.0, 4.5]; let period = 3; + let epsilon = 0.001; let smothing = Some("SMMA"); let expected = vec![None, None, Some(1.5555)]; let result = atr(&high, &low, &close, period, smothing); - assert_eq!(result, expected); + for i in 0..high.len() { + match (result[i], expected[i]) { + (Some(a), Some(b)) => { + assert!((a - b).abs() < epsilon, "at position {}: {} != {}", i, a, b) + } + (None, None) => {} + _ => panic!("at position {}: {:?} != {:?}", i, result[i], expected[i]), + } + } } }