From db6971c9465f8c4822fb2ec992d67b411863546c Mon Sep 17 00:00:00 2001 From: m5l14i11 Date: Fri, 30 Jun 2023 19:48:35 +0400 Subject: [PATCH] tests --- ta_lib/momentum/src/aosc.rs | 4 +--- ta_lib/momentum/src/macd.rs | 7 +++---- ta_lib/momentum/src/rsi.rs | 3 ++- ta_lib/overlap/src/smma.rs | 3 ++- ta_lib/overlap/src/vwap.rs | 2 +- ta_lib/overlap/src/zlema.rs | 2 ++ ta_lib/patterns/src/lib.rs | 0 ta_lib/price/src/average.rs | 2 +- ta_lib/price/src/median.rs | 2 +- ta_lib/price/src/typical.rs | 2 +- 10 files changed, 14 insertions(+), 13 deletions(-) create mode 100644 ta_lib/patterns/src/lib.rs diff --git a/ta_lib/momentum/src/aosc.rs b/ta_lib/momentum/src/aosc.rs index ae58480a..aa753569 100644 --- a/ta_lib/momentum/src/aosc.rs +++ b/ta_lib/momentum/src/aosc.rs @@ -34,14 +34,12 @@ mod tests { fn test_aosc() { let high = &[3.0, 4.0, 5.0, 6.0, 7.0]; let low = &[1.0, 2.0, 3.0, 4.0, 5.0]; - let short_period = 2; let long_period = 4; + let expected_result = vec![None, None, None, Some(1.0), Some(1.0)]; let result = aosc(high, low, short_period, long_period); - let expected_result = vec![None, None, None, Some(1.0), Some(1.0)]; - assert_eq!(result, expected_result); } } diff --git a/ta_lib/momentum/src/macd.rs b/ta_lib/momentum/src/macd.rs index b0020268..91b85224 100644 --- a/ta_lib/momentum/src/macd.rs +++ b/ta_lib/momentum/src/macd.rs @@ -49,10 +49,6 @@ mod tests { let slow_period = 5; let signal_period = 4; let epsilon = 0.001; - - let (macd_line, signal_line, histogram) = - macd(&data, fast_period, slow_period, signal_period); - let expected_macd_line = vec![ None, None, @@ -90,6 +86,9 @@ mod tests { Some(-0.441714), ]; + let (macd_line, signal_line, histogram) = + macd(&data, fast_period, slow_period, signal_period); + for i in 0..data.len() { match (macd_line[i], expected_macd_line[i]) { (Some(a), Some(b)) => { diff --git a/ta_lib/momentum/src/rsi.rs b/ta_lib/momentum/src/rsi.rs index a3fb1694..5c69cedc 100644 --- a/ta_lib/momentum/src/rsi.rs +++ b/ta_lib/momentum/src/rsi.rs @@ -65,7 +65,6 @@ mod test { let data = vec![ 44.34, 44.09, 44.15, 43.61, 44.33, 44.83, 45.10, 45.42, 45.84, ]; - let result = rsi(&data, 6); let epsilon = 0.001; let expected = vec![ None, @@ -79,6 +78,8 @@ mod test { Some(84.221979), ]; + let result = rsi(&data, 6); + for i in 0..result.len() { match (result[i], expected[i]) { (Some(a), Some(b)) => { diff --git a/ta_lib/overlap/src/smma.rs b/ta_lib/overlap/src/smma.rs index 8891d852..a0f3a524 100644 --- a/ta_lib/overlap/src/smma.rs +++ b/ta_lib/overlap/src/smma.rs @@ -42,10 +42,11 @@ mod tests { #[test] fn test_smma() { let data = vec![1.0, 2.0, 3.0, 4.0, 5.0]; - let result = smma(&data, 3); let expected = vec![None, None, Some(1.888), Some(2.592), Some(3.395)]; let epsilon = 0.001; + let result = smma(&data, 3); + for i in 0..result.len() { match (result[i], expected[i]) { (Some(a), Some(b)) => { diff --git a/ta_lib/overlap/src/vwap.rs b/ta_lib/overlap/src/vwap.rs index 67f3909e..ee8f9b9d 100644 --- a/ta_lib/overlap/src/vwap.rs +++ b/ta_lib/overlap/src/vwap.rs @@ -37,8 +37,8 @@ mod tests { let low = vec![1.0, 2.0, 3.0]; let close = vec![1.5, 3.0, 4.5]; let volume = vec![100.0, 200.0, 300.0]; - let expected = vec![Some(1.5), Some(2.5), Some(3.5)]; + let result = vwap(&high, &low, &close, &volume); assert_eq!(result, expected); diff --git a/ta_lib/overlap/src/zlema.rs b/ta_lib/overlap/src/zlema.rs index 429c3544..46f2ab7d 100644 --- a/ta_lib/overlap/src/zlema.rs +++ b/ta_lib/overlap/src/zlema.rs @@ -36,7 +36,9 @@ mod tests { let close = vec![100.0, 105.0, 110.0, 115.0, 120.0]; let period = 3; let expected = vec![None, None, Some(85.0), Some(102.5), Some(113.75)]; + let result = zlema(&close, period); + assert_eq!(result, expected); } } diff --git a/ta_lib/patterns/src/lib.rs b/ta_lib/patterns/src/lib.rs new file mode 100644 index 00000000..e69de29b diff --git a/ta_lib/price/src/average.rs b/ta_lib/price/src/average.rs index f99ecb0b..7c436d7d 100644 --- a/ta_lib/price/src/average.rs +++ b/ta_lib/price/src/average.rs @@ -23,8 +23,8 @@ mod tests { let high = vec![2.0, 4.0, 6.0]; let low = vec![1.0, 2.0, 3.0]; let close = vec![1.75, 3.5, 5.25]; - let expected = vec![Some(1.5625), Some(3.125), Some(4.6875)]; + let result = average_price(&open, &high, &low, &close); assert_eq!(result, expected); diff --git a/ta_lib/price/src/median.rs b/ta_lib/price/src/median.rs index ec81e29d..a6ee73c7 100644 --- a/ta_lib/price/src/median.rs +++ b/ta_lib/price/src/median.rs @@ -19,8 +19,8 @@ mod tests { fn test_median_price() { let high = vec![1.0, 2.0, 3.0]; let low = vec![0.5, 1.0, 2.0]; - let expected = vec![Some(0.75), Some(1.5), Some(2.5)]; + let result = median_price(&high, &low); assert_eq!(result, expected); diff --git a/ta_lib/price/src/typical.rs b/ta_lib/price/src/typical.rs index 4561c709..0485eee7 100644 --- a/ta_lib/price/src/typical.rs +++ b/ta_lib/price/src/typical.rs @@ -21,8 +21,8 @@ mod tests { let high = vec![1.0, 2.0, 3.0]; let low = vec![0.5, 1.0, 1.5]; let close = vec![0.75, 1.5, 2.25]; - let expected = vec![Some(0.75), Some(1.5), Some(2.25)]; + let result = typical_price(&high, &low, &close); assert_eq!(result, expected);