Files
foxhunt/ml/src/test_common.rs
jgrusewski 6bd5b18465 🔧 Wave 33: Test Compilation Improvements - 57 errors remaining
**Progress: 1,178 → 57 test errors (95% reduction)**

## Status Summary
-  Production code: Compiles cleanly (0 errors)
- ⚠️  Test code: 57 errors remain (massive improvement)
- ⚙️  All services build successfully
- 📊 Warning count: 253 (target: <20) - AGENTS WILL FIX

## Remaining Test Errors (57 total)
### Primary Issues:
1. 23× E0308 mismatched types
2. 17× E0433 undeclared Decimal
3. 15× E0433 compliance module not found
4. 6× E0624 private method access
5. Various import and type issues

## Next Phase: Wave 33-2
Launch 10+ parallel agents to:
- Fix remaining 57 test compilation errors
- Reduce 253 warnings to <20
- Achieve 95% test coverage
- Ensure all tests pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-01 21:24:28 +02:00

79 lines
2.1 KiB
Rust

//! Common test utilities and imports for ML crate tests
//!
//! This module provides a centralized location for common test imports,
//! reducing boilerplate across test modules.
//!
//! # Usage
//!
//! ```rust,ignore
//! #[cfg(test)]
//! mod tests {
//! use super::*;
//! use crate::test_common::prelude::*;
//!
//! #[test]
//! fn my_test() -> TestResult {
//! let device = Device::Cpu;
//! // ... test code
//! Ok(())
//! }
//! }
//! ```
#[cfg(test)]
pub mod prelude {
//! Common imports for ML tests
// Re-export candle core types commonly needed in tests
pub use candle_core::{DType, Device, Tensor};
// Re-export standard library types
pub use std::fs::File;
pub use std::io::{Read, Write};
pub use std::path::PathBuf;
// Re-export tempfile for temporary test directories
pub use tempfile::{tempdir, TempDir};
// Re-export common types from parent crate
pub use crate::{MLError, MarketRegime};
// Type alias for test results
pub type TestResult = Result<(), Box<dyn std::error::Error>>;
}
#[cfg(test)]
pub mod helpers {
//! Test helper functions
use super::prelude::*;
/// Create a test device (CPU for consistency)
pub fn test_device() -> Device {
Device::Cpu
}
/// Create a test tensor with given shape
pub fn test_tensor(shape: &[usize]) -> Result<Tensor, Box<dyn std::error::Error>> {
let data: Vec<f32> = (0..shape.iter().product::<usize>())
.map(|i| i as f32)
.collect();
Ok(Tensor::from_vec(data, shape, &test_device())?)
}
/// Create a temporary directory for tests and return its path
pub fn test_temp_dir() -> Result<TempDir, Box<dyn std::error::Error>> {
Ok(tempdir()?)
}
/// Alias for test_device() - returns a mock device for testing
pub fn mock_device() -> Device {
test_device()
}
/// Alias for test_tensor() - creates a test tensor with random data
pub fn create_test_tensor(shape: &[usize]) -> Result<Tensor, Box<dyn std::error::Error>> {
test_tensor(shape)
}
}