Added dummy initial tests
This commit is contained in:
parent
9be8c2e6ff
commit
888843d853
85
src/tests.rs
Normal file
85
src/tests.rs
Normal file
@ -0,0 +1,85 @@
|
||||
mod common {
|
||||
use crate::currency::{Symbol, SymbolPair};
|
||||
use crate::models::{Position, PositionState, TradingPlatform};
|
||||
use crate::models::PositionProfitState::Loss;
|
||||
|
||||
// Generates two short positions with different profit/loss ratios. Both are position in "Loss".
|
||||
pub fn get_short_loss_positions(pair: SymbolPair) -> (Position, Position) {
|
||||
let almost_critical = Position::new(pair.clone(),
|
||||
PositionState::Open,
|
||||
-0.1,
|
||||
100.0,
|
||||
-2.0,
|
||||
-2.0,
|
||||
150.0,
|
||||
0,
|
||||
TradingPlatform::Margin,
|
||||
0.0)
|
||||
.with_profit_state(Some(Loss));
|
||||
let loss = Position::new(pair.clone(),
|
||||
PositionState::Open,
|
||||
-0.1,
|
||||
100.0,
|
||||
-1.0,
|
||||
-1.0,
|
||||
150.0,
|
||||
0,
|
||||
TradingPlatform::Margin,
|
||||
0.0)
|
||||
.with_profit_state(Some(Loss));
|
||||
|
||||
(almost_critical, loss)
|
||||
}
|
||||
|
||||
pub fn get_btcusd_pair() -> SymbolPair {
|
||||
SymbolPair::new(Symbol::BTC, Symbol::USD)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod positions {
|
||||
use crate::models::{Position, PositionState, TradingPlatform};
|
||||
use crate::models::PositionProfitState::Loss;
|
||||
use crate::tests::common::{get_btcusd_pair, get_short_loss_positions};
|
||||
|
||||
#[test]
|
||||
fn short_positions() {
|
||||
let pair = get_btcusd_pair();
|
||||
|
||||
let one = Position::new(pair.clone(),
|
||||
PositionState::Open,
|
||||
-0.1,
|
||||
100.0,
|
||||
-2.0,
|
||||
-2.0,
|
||||
150.0,
|
||||
0,
|
||||
TradingPlatform::Margin,
|
||||
0.0);
|
||||
|
||||
assert_eq!(one.pair(), &pair);
|
||||
assert_eq!(one.is_long(), false);
|
||||
assert_eq!(one.is_short(), true);
|
||||
assert_eq!(one.profit_state(), None);
|
||||
assert_eq!(one.platform(), TradingPlatform::Margin);
|
||||
assert_eq!(one.amount(), -0.1);
|
||||
assert_eq!(one.base_price(), 100.0);
|
||||
assert_eq!(one.pl(), -2.0);
|
||||
assert_eq!(one.pl_perc(), -2.0);
|
||||
assert_eq!(one.id(), 0);
|
||||
assert_eq!(one.leverage(), 0.0);
|
||||
assert_eq!(one.price_liq(), 150.0);
|
||||
assert!(one.price_liq() > one.base_price());
|
||||
|
||||
let (two, three) = get_short_loss_positions(pair);
|
||||
|
||||
assert_eq!(two.is_short(), true);
|
||||
assert_eq!(two.is_long(), false);
|
||||
assert_eq!(three.is_short(), true);
|
||||
assert_eq!(three.is_long(), false);
|
||||
assert_eq!(two.profit_state(), Some(Loss));
|
||||
assert_eq!(three.profit_state(), Some(Loss));
|
||||
|
||||
// TODO: add more test positions with and without profit states
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user