diff options
Diffstat (limited to 'morphology-img/tests/integration.rs')
| -rw-r--r-- | morphology-img/tests/integration.rs | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/morphology-img/tests/integration.rs b/morphology-img/tests/integration.rs index 227e5d1..c8b60fc 100644 --- a/morphology-img/tests/integration.rs +++ b/morphology-img/tests/integration.rs @@ -536,3 +536,187 @@ fn test_progress_callback_tracking() { let final_progress = last_progress.lock().unwrap(); assert_eq!(*final_progress, (5, 5), "final progress should be 5/5"); } + +// ============================================================================ +// Batch Chunking Tests +// ============================================================================ + +#[test] +#[ignore] +fn test_batch_chunking_basic() { + // Create 25 sequences + let sequences: Vec<Sequence> = (0..25) + .map(|i| { + Sequence::new(vec![Value::new(i, 0)]) + }) + .collect(); + + let output_dir = TempDir::new().unwrap(); + let config = RenderConfig::new(output_dir.path()) + .max_batch_size(10); + + let svg_paths = render_sequences(&sequences, &config).unwrap(); + + // All 25 SVGs should be created despite batching + assert_eq!(svg_paths.len(), 25); + + // Verify all SVGs exist + for path in &svg_paths { + assert!(path.exists(), "SVG file should exist: {}", path.display()); + } +} + +#[test] +#[ignore] +fn test_batch_size_exact_match() { + // Create exactly 10 sequences with batch size 10 + let sequences: Vec<Sequence> = (0..10) + .map(|i| { + Sequence::new(vec![Value::new(i, 0)]) + }) + .collect(); + + let output_dir = TempDir::new().unwrap(); + let config = RenderConfig::new(output_dir.path()) + .max_batch_size(10); + + let svg_paths = render_sequences(&sequences, &config).unwrap(); + + assert_eq!(svg_paths.len(), 10); + for path in &svg_paths { + assert!(path.exists()); + } +} + +#[test] +#[ignore] +fn test_batch_size_larger_than_total() { + // Batch size larger than total sequences + let sequences: Vec<Sequence> = (0..5) + .map(|i| { + Sequence::new(vec![Value::new(i, 0)]) + }) + .collect(); + + let output_dir = TempDir::new().unwrap(); + let config = RenderConfig::new(output_dir.path()) + .max_batch_size(100); + + let svg_paths = render_sequences(&sequences, &config).unwrap(); + + // Should still render all 5 sequences in one batch + assert_eq!(svg_paths.len(), 5); + for path in &svg_paths { + assert!(path.exists()); + } +} + +#[test] +#[ignore] +fn test_no_batch_limit() { + // No batch limit set (None) - should render all at once + let sequences: Vec<Sequence> = (0..15) + .map(|i| { + Sequence::new(vec![Value::new(i, 0)]) + }) + .collect(); + + let output_dir = TempDir::new().unwrap(); + let config = RenderConfig::new(output_dir.path()); + // Note: not setting max_batch_size, should default to None + + let svg_paths = render_sequences(&sequences, &config).unwrap(); + + assert_eq!(svg_paths.len(), 15); + for path in &svg_paths { + assert!(path.exists()); + } +} + +#[test] +#[ignore] +fn test_batch_chunking_preserves_order() { + // Test that chunking preserves the order of sequences + let sequences: Vec<Sequence> = (0..12) + .map(|i| { + Sequence::new(vec![Value::new(i, 0), Value::new(i, 1)]) + }) + .collect(); + + let output_dir = TempDir::new().unwrap(); + let config = RenderConfig::new(output_dir.path()) + .max_batch_size(5); + + let svg_paths = render_sequences(&sequences, &config).unwrap(); + + assert_eq!(svg_paths.len(), 12); + + // Verify files are in order (sequence-00.svg through sequence-11.svg) + for (i, path) in svg_paths.iter().enumerate() { + let expected_filename = format!("sequence-{:02}.svg", i); + assert_eq!( + path.file_name().unwrap().to_str().unwrap(), + expected_filename, + "SVG files should be in order" + ); + } +} + +#[test] +#[ignore] +fn test_batch_chunking_with_progress() { + // Test that progress callback works correctly with batching + let sequences: Vec<Sequence> = (0..8) + .map(|i| { + Sequence::new(vec![Value::new(i, 0)]) + }) + .collect(); + + let progress_calls = Arc::new(Mutex::new(Vec::new())); + let progress_calls_clone = progress_calls.clone(); + + let callback: ProgressCallback = Arc::new(move |current, total| { + progress_calls_clone.lock().unwrap().push((current, total)); + }); + + let output_dir = TempDir::new().unwrap(); + let config = RenderConfig::new(output_dir.path()) + .max_batch_size(3) + .progress_callback(callback); + + let svg_paths = render_sequences(&sequences, &config).unwrap(); + + assert_eq!(svg_paths.len(), 8); + + // Progress should track within each batch + let calls = progress_calls.lock().unwrap(); + assert!(!calls.is_empty(), "Progress callback should be called"); + + // Note: Progress is per-batch, so we should see: + // Batch 1 (3 items): (1,3), (2,3), (3,3) + // Batch 2 (3 items): (1,3), (2,3), (3,3) + // Batch 3 (2 items): (1,2), (2,2) + assert_eq!(calls.len(), 8, "Should have 8 progress calls total"); +} + +#[test] +#[ignore] +fn test_batch_size_one() { + // Edge case: batch size of 1 (process one at a time) + let sequences: Vec<Sequence> = (0..3) + .map(|i| { + Sequence::new(vec![Value::new(i, 0)]) + }) + .collect(); + + let output_dir = TempDir::new().unwrap(); + let config = RenderConfig::new(output_dir.path()) + .max_batch_size(1); + + let svg_paths = render_sequences(&sequences, &config).unwrap(); + + assert_eq!(svg_paths.len(), 3); + for path in &svg_paths { + assert!(path.exists()); + } +} |