Files
foxhunt/crates/ml/tests/hyperopt_kelly_params_test.rs
jgrusewski db6462ba7a fix(clippy): resolve all clippy warnings across entire workspace (--all-targets)
Systematic fix of 360+ clippy errors across 37+ crates covering lib,
test, bench, and example targets. Key changes:

- Add targeted #[allow(...)] on #[cfg(test)] modules for test-only lints
  (assertions_on_result_states, float_cmp, str_to_string, indexing, etc.)
- Feature-gate broken integration tests behind __<crate>_integration flags
  where public APIs changed (trading-service, backtesting-service, etc.)
- Remove dead [[test]] entries from Cargo.toml files pointing to deleted files
- Fix production code: field_reassign_with_default, manual_range_contains,
  assert!(false) → panic!(), format!("{}") simplification, len() > 0 → !is_empty()
- Delete truly unused code (Order struct, unused methods/fields/variants)
- Convert sqlx::query!() to sqlx::query() for SQLX_OFFLINE compatibility

Result: cargo clippy --workspace --all-targets -- -D warnings = 0 errors, 0 warnings

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 10:18:35 +01:00

151 lines
5.0 KiB
Rust

#![allow(
clippy::assertions_on_constants,
clippy::assertions_on_result_states,
clippy::clone_on_copy,
clippy::decimal_literal_representation,
clippy::doc_markdown,
clippy::empty_line_after_doc_comments,
clippy::field_reassign_with_default,
clippy::get_unwrap,
clippy::identity_op,
clippy::inconsistent_digit_grouping,
clippy::indexing_slicing,
clippy::integer_division,
clippy::len_zero,
clippy::let_underscore_must_use,
clippy::manual_div_ceil,
clippy::manual_let_else,
clippy::manual_range_contains,
clippy::modulo_arithmetic,
clippy::needless_range_loop,
clippy::non_ascii_literal,
clippy::redundant_clone,
clippy::shadow_reuse,
clippy::shadow_same,
clippy::shadow_unrelated,
clippy::single_match_else,
clippy::str_to_string,
clippy::string_slice,
clippy::tests_outside_test_module,
clippy::too_many_lines,
clippy::unnecessary_wraps,
clippy::unseparated_literal_suffix,
clippy::use_debug,
clippy::useless_vec,
clippy::wildcard_enum_match_arm,
clippy::else_if_without_else,
clippy::expect_used,
clippy::missing_const_for_fn,
clippy::similar_names,
clippy::type_complexity,
clippy::collapsible_else_if,
clippy::doc_lazy_continuation,
clippy::items_after_test_module,
clippy::map_clone,
clippy::multiple_unsafe_ops_per_block,
clippy::unwrap_or_default,
clippy::assign_op_pattern,
clippy::needless_borrow,
clippy::println_empty_string,
clippy::unnecessary_cast,
clippy::used_underscore_binding,
clippy::create_dir,
clippy::implicit_saturating_sub,
clippy::exit,
clippy::expect_fun_call,
clippy::too_many_arguments,
clippy::unnecessary_map_or,
clippy::unwrap_used,
dead_code,
unused_imports,
unused_variables,
clippy::cloned_ref_to_slice_refs,
clippy::neg_multiply,
clippy::while_let_loop,
clippy::bool_assert_comparison,
clippy::excessive_precision,
clippy::trivially_copy_pass_by_ref,
clippy::op_ref,
clippy::redundant_closure,
clippy::unnecessary_lazy_evaluations,
clippy::if_then_some_else_none,
clippy::unnecessary_to_owned,
clippy::single_component_path_imports,
)]
#[cfg(test)]
mod hyperopt_kelly_params_tests {
use ml::hyperopt::adapters::dqn::DQNParams;
use ml::hyperopt::traits::ParameterSpace;
#[test]
fn test_search_space_has_22_dimensions() {
let bounds = DQNParams::continuous_bounds();
assert_eq!(bounds.len(), 22, "Search space should be 22D after adding Kelly params");
}
#[test]
fn test_kelly_fractional_bounds() {
let bounds = DQNParams::continuous_bounds();
let (min, max) = bounds[18]; // Kelly fractional at index 18
assert_eq!(min, 0.25, "Kelly fractional min should be 0.25 (quarter-Kelly)");
assert_eq!(max, 1.0, "Kelly fractional max should be 1.0 (full-Kelly)");
}
#[test]
fn test_kelly_max_fraction_bounds() {
let bounds = DQNParams::continuous_bounds();
let (min, max) = bounds[19];
assert_eq!(min, 0.1, "Kelly max_fraction min should be 0.1 (10%)");
assert_eq!(max, 0.5, "Kelly max_fraction max should be 0.5 (50%)");
}
#[test]
fn test_kelly_min_trades_bounds() {
let bounds = DQNParams::continuous_bounds();
let (min, max) = bounds[20];
assert_eq!(min, 10.0, "Kelly min_trades min should be 10");
assert_eq!(max, 50.0, "Kelly min_trades max should be 50");
}
#[test]
fn test_volatility_window_bounds() {
let bounds = DQNParams::continuous_bounds();
let (min, max) = bounds[21];
assert_eq!(min, 10.0, "Volatility window min should be 10");
assert_eq!(max, 30.0, "Volatility window max should be 30");
}
#[test]
fn test_from_continuous_accepts_22d() {
let x = vec![
// Existing 18 params (use mid-range values)
(-4.5_f64).ln(), 112.0, 0.97, (75000.0_f64).ln(),
1.5, 6.0, (25.0_f64).ln(), 0.05, 1.25, 0.6, 0.4,
-2.0, 2.0, (0.5_f64).ln(), 320.0, 3.0, 126.0, 1.55,
// New Kelly params
0.5, 0.25, 30.0, 20.0
];
let result = DQNParams::from_continuous(&x);
assert!(result.is_ok(), "Should accept 22D parameter vector");
let params = result.unwrap();
assert!((params.kelly_fractional - 0.5).abs() < 0.01);
assert!((params.kelly_max_fraction - 0.25).abs() < 0.01);
assert_eq!(params.kelly_min_trades, 30);
assert_eq!(params.volatility_window, 20);
}
#[test]
fn test_from_continuous_rejects_18d() {
let x = vec![
(-4.5_f64).ln(), 112.0, 0.97, (75000.0_f64).ln(),
1.5, 6.0, (25.0_f64).ln(), 0.05, 1.25, 0.6, 0.4,
-2.0, 2.0, (0.5_f64).ln(), 320.0, 3.0, 126.0, 1.55,
];
let result = DQNParams::from_continuous(&x);
assert!(result.is_err(), "Should reject old 18D parameter vector");
}
}