Skip to content

Commit

Permalink
clippy on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Calum committed Jun 25, 2024
1 parent a5f1c31 commit 0f8bdd8
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 42 deletions.
2 changes: 1 addition & 1 deletion example_clients/alator/benches/sim_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async fn full_backtest_random_data() {

let simbrkr = UistBrokerBuilder::new()
.with_client(client, resp.backtest_id)
.with_trade_costs(vec![BrokerCost::Flat(1.0.into())])
.with_trade_costs(vec![BrokerCost::Flat(1.0)])
.build()
.await;

Expand Down
10 changes: 4 additions & 6 deletions example_clients/alator/src/broker/uist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,11 @@ mod tests {
let mut client = TestClient::single("Random", source);
let resp = client.init("Random".to_string()).await.unwrap();

let brkr = UistBrokerBuilder::new()
UistBrokerBuilder::new()
.with_trade_costs(vec![BrokerCost::PctOfValue(0.01)])
.with_client(client, resp.backtest_id)
.build()
.await;

brkr
.await
}

#[tokio::test]
Expand Down Expand Up @@ -667,15 +665,15 @@ mod tests {

//Missing live quote for BCD
brkr.check().await;
let value = brkr.get_position_value("BCD").unwrap_or(f64::from(0.0));
let value = brkr.get_position_value("BCD").unwrap_or(0.0);
println!("{:?}", value);
//We test against the bid price, which gives us the value exclusive of the price paid at ask
assert!(value == 10.0 * 100.0);

//BCD has quote again
brkr.check().await;

let value1 = brkr.get_position_value("BCD").unwrap_or(f64::from(0.0));
let value1 = brkr.get_position_value("BCD").unwrap_or(0.0);
println!("{:?}", value1);
assert!(value1 == 12.0 * 100.0);
}
Expand Down
62 changes: 30 additions & 32 deletions example_clients/alator/src/perf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,11 @@ mod tests {
let mut client = TestClient::single("Random", source);
let resp = client.init("Random".to_string()).await.unwrap();

let brkr = UistBrokerBuilder::new()
UistBrokerBuilder::new()
.with_client(client, resp.backtest_id)
.with_trade_costs(vec![BrokerCost::PctOfValue(0.01)])
.build()
.await;

brkr
.await
}

#[test]
Expand Down Expand Up @@ -382,52 +380,52 @@ mod tests {

let snap0 = StrategySnapshot {
date: 100.into(),
portfolio_value: 100.0.into(),
net_cash_flow: 0.0.into(),
portfolio_value: 100.0,
net_cash_flow: 0.0,
inflation: 0.0,
};
let snap1 = StrategySnapshot {
date: 101.into(),
portfolio_value: 121.0.into(),
net_cash_flow: 10.0.into(),
portfolio_value: 121.0,
net_cash_flow: 10.0,
inflation: 0.0,
};
let snap2 = StrategySnapshot {
date: 102.into(),
portfolio_value: 126.9.into(),
net_cash_flow: 30.0.into(),
portfolio_value: 126.9,
net_cash_flow: 30.0,
inflation: 0.0,
};
let snap3 = StrategySnapshot {
date: 103.into(),
portfolio_value: 150.59.into(),
net_cash_flow: 40.0.into(),
portfolio_value: 150.59,
net_cash_flow: 40.0,
inflation: 0.0,
};
let with_cash_flows = vec![snap0, snap1, snap2, snap3];

let snap3 = StrategySnapshot {
date: 100.into(),
portfolio_value: 100.0.into(),
net_cash_flow: 0.0.into(),
portfolio_value: 100.0,
net_cash_flow: 0.0,
inflation: 0.0,
};
let snap4 = StrategySnapshot {
date: 101.into(),
portfolio_value: 110.0.into(),
net_cash_flow: 0.0.into(),
portfolio_value: 110.0,
net_cash_flow: 0.0,
inflation: 0.0,
};
let snap5 = StrategySnapshot {
date: 102.into(),
portfolio_value: 99.0.into(),
net_cash_flow: 0.0.into(),
portfolio_value: 99.0,
net_cash_flow: 0.0,
inflation: 0.0,
};
let snap6 = StrategySnapshot {
date: 103.into(),
portfolio_value: 108.9.into(),
net_cash_flow: 0.0.into(),
portfolio_value: 108.9,
net_cash_flow: 0.0,
inflation: 0.0,
};
let without_cash_flows = vec![snap3, snap4, snap5, snap6];
Expand All @@ -447,20 +445,20 @@ mod tests {
fn test_that_perf_completes_with_zeros() {
let snap1 = StrategySnapshot {
date: 100.into(),
portfolio_value: 0.0.into(),
net_cash_flow: 0.0.into(),
portfolio_value: 0.0,
net_cash_flow: 0.0,
inflation: 0.0,
};
let snap2 = StrategySnapshot {
date: 101.into(),
portfolio_value: 0.0.into(),
net_cash_flow: 0.0.into(),
portfolio_value: 0.0,
net_cash_flow: 0.0,
inflation: 0.0,
};
let snap3 = StrategySnapshot {
date: 102.into(),
portfolio_value: 0.0.into(),
net_cash_flow: 0.0.into(),
portfolio_value: 0.0,
net_cash_flow: 0.0,
inflation: 0.0,
};

Expand All @@ -476,20 +474,20 @@ mod tests {
fn test_that_perf_orders_best_and_worst() {
let snap1 = StrategySnapshot {
date: 100.into(),
portfolio_value: 110.0.into(),
net_cash_flow: 0.0.into(),
portfolio_value: 110.0,
net_cash_flow: 0.0,
inflation: 0.0,
};
let snap2 = StrategySnapshot {
date: 101.into(),
portfolio_value: 90.0.into(),
net_cash_flow: 0.0.into(),
portfolio_value: 90.0,
net_cash_flow: 0.0,
inflation: 0.0,
};
let snap3 = StrategySnapshot {
date: 102.into(),
portfolio_value: 110.0.into(),
net_cash_flow: 0.0.into(),
portfolio_value: 110.0,
net_cash_flow: 0.0,
inflation: 0.0,
};

Expand Down
2 changes: 1 addition & 1 deletion rotala/src/exchange/jura_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,6 @@ mod tests {
let res = exchange.tick(source.get_quotes_unchecked(&100));

assert_eq!(res.1.len(), 3);
assert_eq!(res.1.get(0).unwrap().is_buy, false)
assert!(!(res.1.first().unwrap().is_buy));
}
}
2 changes: 1 addition & 1 deletion rotala/src/exchange/uist_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ mod tests {

assert_eq!(res.1.len(), 3);
assert_eq!(
res.1.get(0).unwrap().clone().order_type,
res.1.first().unwrap().clone().order_type,
OrderType::MarketSell
)
}
Expand Down
2 changes: 1 addition & 1 deletion rotala/src/http/uist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,6 @@ mod tests {
let resp5: TickResponse = test::call_and_read_body_json(&app, req5).await;

assert!(resp5.executed_trades.len() == 1);
assert!(resp5.executed_trades.get(0).unwrap().symbol == "ABC")
assert!(resp5.executed_trades.first().unwrap().symbol == "ABC")
}
}

0 comments on commit 0f8bdd8

Please sign in to comment.