diff options
| author | jacksonfu14 <jackson@fashionunited.com> | 2025-11-17 06:56:09 +0100 |
|---|---|---|
| committer | Jackson Moore <jacksonmoore@tuta.io> | 2025-11-17 06:56:09 +0100 |
| commit | a20f9a327c4d9e5ac8f42db4e2e9fb29770c3d37 (patch) | |
| tree | 568c2650e8bf015b896f86297176a485b9bb5c08 /morphology-img/tests/integration.rs | |
| parent | 3077c7af770b055804d5cf48994a4e4cf6d31146 (diff) | |
feature: generate and process ly files
Diffstat (limited to 'morphology-img/tests/integration.rs')
| -rw-r--r-- | morphology-img/tests/integration.rs | 365 |
1 files changed, 365 insertions, 0 deletions
diff --git a/morphology-img/tests/integration.rs b/morphology-img/tests/integration.rs new file mode 100644 index 0000000..e6db544 --- /dev/null +++ b/morphology-img/tests/integration.rs @@ -0,0 +1,365 @@ +use morphology_img::{render_sequences, RenderConfig}; +use morphology::{Sequence, Value}; +use tempfile::TempDir; +use std::fs; + +/// Test the complete pipeline with basic configuration +#[test] +#[ignore] +fn test_render_sequences_basic() { + // Create test sequences + let sequences = vec![ + Sequence::new(vec![Value::origin()]), + Sequence::new(vec![Value::new(1, 0)]), + ]; + + // Use temp directory for output + let output_dir = TempDir::new().unwrap(); + let config = RenderConfig::new(output_dir.path()); + + // Render sequences + let svg_paths = render_sequences(&sequences, &config).unwrap(); + + // Verify correct number of SVGs + assert_eq!(svg_paths.len(), 2, "should generate 2 SVG files"); + + // Verify all SVGs exist + for svg_path in &svg_paths { + assert!(svg_path.exists(), "SVG should exist: {}", svg_path.display()); + + // Verify SVG has content + let content = fs::read_to_string(svg_path).unwrap(); + assert!(content.contains("<svg"), "should contain SVG markup"); + assert!(!content.is_empty(), "SVG should not be empty"); + } + + // Verify SVGs are in output directory + for svg_path in &svg_paths { + assert!(svg_path.starts_with(output_dir.path())); + } +} + +/// Test with the example sequence from preliminary overview +#[test] +#[ignore] +fn test_render_sequences_example() { + let sequences = vec![ + Sequence::new(vec![ + Value::new(1, 0), + Value::new(-1, 1), + Value::new(-1, 0), + Value::new(0, 0), + ]), + ]; + + let output_dir = TempDir::new().unwrap(); + let config = RenderConfig::new(output_dir.path()); + + let svg_paths = render_sequences(&sequences, &config).unwrap(); + + assert_eq!(svg_paths.len(), 1); + assert!(svg_paths[0].exists()); + + // Verify substantial content + let content = fs::read_to_string(&svg_paths[0]).unwrap(); + assert!(content.len() > 1000, "should have substantial SVG content"); +} + +/// Test with empty sequence list +#[test] +#[ignore] +fn test_render_sequences_empty() { + let sequences: Vec<Sequence> = vec![]; + + let output_dir = TempDir::new().unwrap(); + let config = RenderConfig::new(output_dir.path()); + + let svg_paths = render_sequences(&sequences, &config).unwrap(); + + assert_eq!(svg_paths.len(), 0, "should return empty vector for empty input"); +} + +/// Test with single sequence +#[test] +#[ignore] +fn test_render_sequences_single() { + let sequences = vec![Sequence::new(vec![Value::origin()])]; + + let output_dir = TempDir::new().unwrap(); + let config = RenderConfig::new(output_dir.path()); + + let svg_paths = render_sequences(&sequences, &config).unwrap(); + + assert_eq!(svg_paths.len(), 1); + assert!(svg_paths[0].exists()); +} + +/// Test with many sequences +#[test] +#[ignore] +fn test_render_sequences_many() { + // Create 10 sequences + 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()); + + let svg_paths = render_sequences(&sequences, &config).unwrap(); + + assert_eq!(svg_paths.len(), 10); + + // Verify all exist and have content + for svg_path in &svg_paths { + assert!(svg_path.exists()); + let content = fs::read_to_string(svg_path).unwrap(); + assert!(content.contains("<svg")); + } +} + +/// Test that temporary files are cleaned up by default +#[test] +#[ignore] +fn test_render_sequences_temp_cleanup() { + let sequences = vec![Sequence::new(vec![Value::origin()])]; + + let output_dir = TempDir::new().unwrap(); + let config = RenderConfig::new(output_dir.path()); + + let _svg_paths = render_sequences(&sequences, &config).unwrap(); + + // Temporary files should not be visible after function returns + // (they're cleaned up automatically) + // We can't directly test this without implementation details, + // but we can verify the function completed successfully +} + +/// Test with custom LilyPond binary path +#[test] +#[ignore] +fn test_render_sequences_custom_binary() { + let sequences = vec![Sequence::new(vec![Value::origin()])]; + + let output_dir = TempDir::new().unwrap(); + let config = RenderConfig::new(output_dir.path()) + .lilypond_binary("lilypond"); // Use system lilypond + + let svg_paths = render_sequences(&sequences, &config).unwrap(); + + assert_eq!(svg_paths.len(), 1); + assert!(svg_paths[0].exists()); +} + +/// Test that output directory is created if it doesn't exist +#[test] +#[ignore] +fn test_render_sequences_creates_output_dir() { + let sequences = vec![Sequence::new(vec![Value::origin()])]; + + let temp_base = TempDir::new().unwrap(); + let output_dir = temp_base.path().join("nested").join("output"); + + assert!(!output_dir.exists(), "output directory should not exist yet"); + + let config = RenderConfig::new(&output_dir); + + let svg_paths = render_sequences(&sequences, &config).unwrap(); + + assert!(output_dir.exists(), "output directory should be created"); + assert_eq!(svg_paths.len(), 1); + assert!(svg_paths[0].exists()); +} + +/// Test SVG filenames match expected pattern +#[test] +#[ignore] +fn test_render_sequences_filenames() { + let sequences = vec![ + Sequence::new(vec![Value::origin()]), + Sequence::new(vec![Value::new(1, 0)]), + Sequence::new(vec![Value::new(2, 0)]), + ]; + + let output_dir = TempDir::new().unwrap(); + let config = RenderConfig::new(output_dir.path()); + + let svg_paths = render_sequences(&sequences, &config).unwrap(); + + // With 3 sequences, we should have sequence-0.svg, sequence-1.svg, sequence-2.svg + assert_eq!(svg_paths[0].file_name().unwrap().to_str().unwrap(), "sequence-0.svg"); + assert_eq!(svg_paths[1].file_name().unwrap().to_str().unwrap(), "sequence-1.svg"); + assert_eq!(svg_paths[2].file_name().unwrap().to_str().unwrap(), "sequence-2.svg"); +} + +/// Test that sequences are rendered in order +#[test] +#[ignore] +fn test_render_sequences_preserves_order() { + let sequences = vec![ + Sequence::new(vec![Value::new(5, 0)]), + Sequence::new(vec![Value::new(3, 0)]), + Sequence::new(vec![Value::new(1, 0)]), + ]; + + let output_dir = TempDir::new().unwrap(); + let config = RenderConfig::new(output_dir.path()); + + let svg_paths = render_sequences(&sequences, &config).unwrap(); + + // Verify order is preserved + assert_eq!(svg_paths.len(), 3); + assert_eq!(svg_paths[0].file_name().unwrap().to_str().unwrap(), "sequence-0.svg"); + assert_eq!(svg_paths[1].file_name().unwrap().to_str().unwrap(), "sequence-1.svg"); + assert_eq!(svg_paths[2].file_name().unwrap().to_str().unwrap(), "sequence-2.svg"); +} + +/// Test with different sequence lengths +#[test] +#[ignore] +fn test_render_sequences_different_lengths() { + let sequences = vec![ + Sequence::new(vec![Value::origin()]), // length 1 + Sequence::new(vec![Value::origin(), Value::new(1, 0)]), // length 2 + Sequence::new(vec![Value::origin(), Value::new(1, 0), Value::new(2, 0)]), // length 3 + ]; + + let output_dir = TempDir::new().unwrap(); + let config = RenderConfig::new(output_dir.path()); + + let svg_paths = render_sequences(&sequences, &config).unwrap(); + + assert_eq!(svg_paths.len(), 3); + + // All should be rendered successfully + for svg_path in &svg_paths { + assert!(svg_path.exists()); + let content = fs::read_to_string(svg_path).unwrap(); + assert!(content.contains("<svg")); + } +} + +/// Test that each SVG has unique content +#[test] +#[ignore] +fn test_render_sequences_unique_content() { + let sequences = vec![ + Sequence::new(vec![Value::origin()]), + Sequence::new(vec![Value::new(1, 0)]), + ]; + + let output_dir = TempDir::new().unwrap(); + let config = RenderConfig::new(output_dir.path()); + + let svg_paths = render_sequences(&sequences, &config).unwrap(); + + let content1 = fs::read_to_string(&svg_paths[0]).unwrap(); + let content2 = fs::read_to_string(&svg_paths[1]).unwrap(); + + // Contents should be different + assert_ne!(content1, content2, "each SVG should have unique content"); +} + +/// Test complete pipeline with complex sequences +#[test] +#[ignore] +fn test_render_sequences_complex() { + let sequences = vec![ + Sequence::new(vec![ + Value::new(1, 0), + Value::new(-1, 1), + Value::new(-1, 0), + Value::new(0, 0), + ]), + Sequence::new(vec![ + Value::new(2, 0), + Value::new(-2, 0), + ]), + Sequence::new(vec![ + Value::origin(), + Value::new(1, 0), + Value::new(2, 0), + Value::new(3, 0), + ]), + ]; + + let output_dir = TempDir::new().unwrap(); + let config = RenderConfig::new(output_dir.path()); + + let svg_paths = render_sequences(&sequences, &config).unwrap(); + + assert_eq!(svg_paths.len(), 3); + + // Verify all have substantial content + for svg_path in &svg_paths { + let content = fs::read_to_string(svg_path).unwrap(); + assert!(content.len() > 1000, "SVG should have substantial content"); + assert!(content.contains("<svg")); + assert!(content.contains("</svg>")); + } +} + +/// Test that function returns error if LilyPond is not available +#[test] +fn test_render_sequences_requires_lilypond() { + let sequences = vec![Sequence::new(vec![Value::origin()])]; + + let output_dir = TempDir::new().unwrap(); + + // Use a non-existent binary + let config = RenderConfig::new(output_dir.path()) + .lilypond_binary("/this/does/not/exist/lilypond"); + + let result = render_sequences(&sequences, &config); + + // Should fail with LilyPondNotFound or execution error + assert!(result.is_err(), "should fail when LilyPond is not available"); +} + +/// Integration test: Complete realistic workflow +#[test] +#[ignore] +fn test_render_sequences_realistic_workflow() { + // Create a realistic set of sequences + let sequences: Vec<Sequence> = vec![ + Sequence::new(vec![Value::origin()]), + Sequence::new(vec![Value::new(1, 0), Value::new(-1, 0)]), + Sequence::new(vec![Value::new(2, 0), Value::origin(), Value::new(-2, 0)]), + Sequence::new(vec![ + Value::new(1, 0), + Value::new(-1, 1), + Value::new(-1, 0), + Value::new(0, 0), + ]), + ]; + + let output_dir = TempDir::new().unwrap(); + let config = RenderConfig::new(output_dir.path()); + + // Render all sequences + let svg_paths = render_sequences(&sequences, &config).unwrap(); + + // Verify results + assert_eq!(svg_paths.len(), 4, "should generate 4 SVGs"); + + // Verify all files exist and are valid + for (i, svg_path) in svg_paths.iter().enumerate() { + assert!(svg_path.exists(), "SVG {} should exist", i); + + // Verify in correct directory + assert!(svg_path.starts_with(output_dir.path())); + + // Verify content is valid SVG + let content = fs::read_to_string(svg_path).unwrap(); + assert!(content.contains("<svg"), "SVG {} should have svg tag", i); + assert!(content.contains("</svg>"), "SVG {} should have closing tag", i); + assert!(content.contains("xmlns"), "SVG {} should have XML namespace", i); + + // Verify substantial content + assert!(content.len() > 500, "SVG {} should have substantial content", i); + } + + // Verify correct filenames + assert_eq!(svg_paths[0].file_name().unwrap().to_str().unwrap(), "sequence-0.svg"); + assert_eq!(svg_paths[3].file_name().unwrap().to_str().unwrap(), "sequence-3.svg"); +} |