Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Jun 30, 2023
1 parent e5ba77b commit db6971c
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 13 deletions.
4 changes: 1 addition & 3 deletions ta_lib/momentum/src/aosc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
7 changes: 3 additions & 4 deletions ta_lib/momentum/src/macd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)) => {
Expand Down
3 changes: 2 additions & 1 deletion ta_lib/momentum/src/rsi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)) => {
Expand Down
3 changes: 2 additions & 1 deletion ta_lib/overlap/src/smma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) => {
Expand Down
2 changes: 1 addition & 1 deletion ta_lib/overlap/src/vwap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions ta_lib/overlap/src/zlema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Empty file added ta_lib/patterns/src/lib.rs
Empty file.
2 changes: 1 addition & 1 deletion ta_lib/price/src/average.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ta_lib/price/src/median.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ta_lib/price/src/typical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit db6971c

Please sign in to comment.