From e37f7ba671f3e80396e7a4ac3a461365bd0ca78a Mon Sep 17 00:00:00 2001 From: jacksonfu14 Date: Mon, 17 Nov 2025 08:49:07 +0100 Subject: feature: ly processing batch chunking --- morphology-img/tests/config.rs | 57 +++++++++++ morphology-img/tests/integration.rs | 184 ++++++++++++++++++++++++++++++++++++ 2 files changed, 241 insertions(+) (limited to 'morphology-img/tests') diff --git a/morphology-img/tests/config.rs b/morphology-img/tests/config.rs index 9b47ed5..6302cb0 100644 --- a/morphology-img/tests/config.rs +++ b/morphology-img/tests/config.rs @@ -183,3 +183,60 @@ fn test_new_is_equivalent_to_default_with_custom_output() { assert_eq!(config_new.keep_temp_files, config_default.keep_temp_files); assert_eq!(config_new.lilypond_binary, config_default.lilypond_binary); } + +#[test] +fn test_default_max_batch_size_is_none() { + let config = RenderConfig::default(); + assert_eq!(config.max_batch_size, None); +} + +#[test] +fn test_builder_max_batch_size() { + let config = RenderConfig::new("output") + .max_batch_size(50); + + assert_eq!(config.max_batch_size, Some(50)); + assert_eq!(config.output_dir, PathBuf::from("output")); +} + +#[test] +fn test_builder_max_batch_size_various_values() { + let config1 = RenderConfig::new("output").max_batch_size(1); + let config10 = RenderConfig::new("output").max_batch_size(10); + let config100 = RenderConfig::new("output").max_batch_size(100); + + assert_eq!(config1.max_batch_size, Some(1)); + assert_eq!(config10.max_batch_size, Some(10)); + assert_eq!(config100.max_batch_size, Some(100)); +} + +#[test] +fn test_builder_with_all_options_including_max_batch_size() { + let config = RenderConfig::new("my-output") + .keep_temp_files(true) + .lilypond_binary("/usr/bin/lilypond") + .max_batch_size(25); + + assert_eq!(config.output_dir, PathBuf::from("my-output")); + assert!(config.keep_temp_files); + assert_eq!(config.lilypond_binary, PathBuf::from("/usr/bin/lilypond")); + assert_eq!(config.max_batch_size, Some(25)); +} + +#[test] +fn test_builder_max_batch_size_overwrites() { + let config = RenderConfig::new("output") + .max_batch_size(10) + .max_batch_size(20); // Override previous value + + assert_eq!(config.max_batch_size, Some(20)); +} + +#[test] +fn test_max_batch_size_field_is_public() { + let config = RenderConfig::new("output").max_batch_size(15); + + // Should be able to access field directly + let _batch_size = config.max_batch_size; + assert_eq!(_batch_size, Some(15)); +} 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 = (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 = (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 = (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 = (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 = (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 = (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 = (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()); + } +} -- cgit v1.2.3