Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Aug 8, 2023
1 parent dffd9f8 commit f5c0bcf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ta_lib/strategies/base/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Price for OHLCVSeries {
}
}

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum TradeAction {
GoLong(f64),
GoShort(f64),
Expand Down
27 changes: 27 additions & 0 deletions ta_lib/strategies/trend_follow/src/cross_ma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl Strategy for MACrossStrategy {
#[cfg(test)]
mod tests {
use super::*;
use base::base::TradeAction;

#[test]
fn test_macrossstrategy_new() {
Expand All @@ -72,4 +73,30 @@ mod tests {
assert_eq!(params.get("short_period"), Some(&50));
assert_eq!(params.get("long_period"), Some(&100));
}

#[test]
fn test_macrossstrategy_next_do_nothing() {
let mut strat = MACrossStrategy::new(50, 100);

for _i in 0..100 {
strat.next(OHLCV {
open: 2.0,
high: 3.0,
low: 2.0,
close: 3.0,
volume: 2000.0,
});
}

let result = strat.next(OHLCV {
open: 1.0,
high: 1.0,
low: 1.0,
close: 1.0,
volume: 20.0,
});

assert_eq!(strat.can_process(), true);
assert_eq!(result, TradeAction::DoNothing);
}
}

0 comments on commit f5c0bcf

Please sign in to comment.