1+ // Integration test for complete report generator functionality
2+ // Tests the entire report generation pipeline using generated data for fast execution
3+ use std:: fs;
4+ use std:: path:: Path ;
5+ use tempfile:: TempDir ;
6+
7+ use qqn_optimizer:: benchmarks:: evaluation:: BenchmarkConfig ;
8+ use qqn_optimizer:: experiment_runner:: { ReportGenerator , UnifiedReportTestSuite } ;
9+
10+ #[ tokio:: test]
11+ async fn test_report_generator_complete_pipeline ( ) -> anyhow:: Result < ( ) > {
12+ // Create a temporary directory for test output
13+ let temp_dir = TempDir :: new ( ) ?;
14+ let output_path = temp_dir. path ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
15+
16+ // Create test data using the existing test suite
17+ let test_data = UnifiedReportTestSuite :: create_test_data ( ) ;
18+
19+ // Verify we have test data
20+ assert ! ( !test_data. is_empty( ) , "Test data should not be empty" ) ;
21+ assert ! ( test_data. len( ) >= 3 , "Should have at least 3 test problems" ) ;
22+
23+ // Create ReportGenerator with test configuration
24+ let config = BenchmarkConfig :: default ( ) ;
25+ let report_generator = ReportGenerator :: new ( output_path. clone ( ) , config) ;
26+
27+ // Convert test data to the format expected by generate_main_report
28+ let data_refs: Vec < _ > = test_data. iter ( ) . map ( |( p, r) | ( p, r. clone ( ) ) ) . collect ( ) ;
29+
30+ // Run the complete report generation pipeline
31+ println ! ( "Generating complete report with generated data..." ) ;
32+ report_generator
33+ . generate_main_report ( & data_refs, false )
34+ . await ?;
35+
36+ // Verify that the main output directory structure was created
37+ let output_dir = Path :: new ( & output_path) ;
38+ assert ! ( output_dir. exists( ) , "Output directory should exist" ) ;
39+
40+ // Check for expected subdirectories
41+ let expected_dirs = [ "reports" , "data" , "convergence" , "plots" , "latex" ] ;
42+ for dir_name in & expected_dirs {
43+ let dir_path = output_dir. join ( dir_name) ;
44+ assert ! (
45+ dir_path. exists( ) ,
46+ "Directory '{}' should be created" ,
47+ dir_name
48+ ) ;
49+ }
50+
51+ // List all generated files for inspection
52+ fn list_files ( dir : & std:: path:: Path , indent : usize ) -> anyhow:: Result < ( ) > {
53+ if dir. is_dir ( ) {
54+ for entry in fs:: read_dir ( dir) ? {
55+ let entry = entry?;
56+ let path = entry. path ( ) ;
57+ println ! ( "{}{}" , " " . repeat( indent) , path. file_name( ) . unwrap( ) . to_string_lossy( ) ) ;
58+ if path. is_dir ( ) {
59+ list_files ( & path, indent + 1 ) ?;
60+ }
61+ }
62+ }
63+ Ok ( ( ) )
64+ }
65+
66+ println ! ( "Generated files structure:" ) ;
67+ list_files ( output_dir, 0 ) ?;
68+
69+ // Verify unified reports were generated in multiple formats
70+ let unified_dir = output_dir. join ( "unified_reports" ) ;
71+ assert ! (
72+ unified_dir. exists( ) ,
73+ "Unified reports directory should exist"
74+ ) ;
75+
76+ // Check that at least some unified reports exist
77+ let html_dir = unified_dir. join ( "html" ) ;
78+ let csv_dir = unified_dir. join ( "csv" ) ;
79+ let latex_dir = unified_dir. join ( "latex" ) ;
80+ let markdown_dir = unified_dir. join ( "markdown" ) ;
81+
82+ assert ! ( html_dir. exists( ) , "HTML reports directory should exist" ) ;
83+ assert ! ( csv_dir. exists( ) , "CSV reports directory should exist" ) ;
84+ assert ! ( latex_dir. exists( ) , "LaTeX reports directory should exist" ) ;
85+ assert ! ( markdown_dir. exists( ) , "Markdown reports directory should exist" ) ;
86+
87+ // Check specific report files exist in HTML format
88+ let html_summary = html_dir. join ( "summary_statistics.html" ) ;
89+ assert ! ( html_summary. exists( ) , "HTML summary statistics should exist" ) ;
90+
91+ let html_performance = html_dir. join ( "performance_table.html" ) ;
92+ assert ! ( html_performance. exists( ) , "HTML performance table should exist" ) ;
93+
94+ // Check CSV format files
95+ let csv_summary = csv_dir. join ( "summary_statistics.csv" ) ;
96+ assert ! ( csv_summary. exists( ) , "CSV summary statistics should exist" ) ;
97+
98+ // Validate HTML content
99+ let html_content = fs:: read_to_string ( html_summary) ?;
100+ assert ! (
101+ html_content. contains( "<!DOCTYPE html>" ) ,
102+ "HTML should contain proper DOCTYPE"
103+ ) ;
104+ assert ! (
105+ html_content. len( ) > 500 ,
106+ "HTML should have substantial content"
107+ ) ;
108+
109+ // Validate CSV content
110+ let csv_content = fs:: read_to_string ( csv_summary) ?;
111+ assert ! (
112+ csv_content. contains( "Problem_Family" ) || csv_content. contains( "Optimizer" ) ,
113+ "CSV should contain expected headers"
114+ ) ;
115+ assert ! (
116+ csv_content. lines( ) . count( ) > 1 ,
117+ "CSV should have header plus data rows"
118+ ) ;
119+
120+ // Verify report index was created
121+ let index_file = output_dir. join ( "report_index.html" ) ;
122+ assert ! ( index_file. exists( ) , "Report index.html should be created" ) ;
123+
124+ // Check that the index file has reasonable content
125+ let index_content = fs:: read_to_string ( index_file) ?;
126+ assert ! (
127+ index_content. contains( "<!DOCTYPE html>" ) ,
128+ "Index should be valid HTML"
129+ ) ;
130+ assert ! (
131+ index_content. len( ) > 500 ,
132+ "Index should have substantial content"
133+ ) ;
134+
135+ // Verify legacy reports exist
136+ let benchmark_report = output_dir. join ( "benchmark_report.md" ) ;
137+ assert ! ( benchmark_report. exists( ) , "Benchmark report should exist" ) ;
138+
139+ // Verify data files exist
140+ let data_dir = output_dir. join ( "data" ) ;
141+ let detailed_results = data_dir. join ( "detailed_results.csv" ) ;
142+ assert ! ( detailed_results. exists( ) , "Detailed results CSV should exist" ) ;
143+
144+ let summary_stats = data_dir. join ( "summary_statistics.csv" ) ;
145+ assert ! ( summary_stats. exists( ) , "Summary statistics CSV should exist" ) ;
146+
147+ // Verify LaTeX files exist
148+ let latex_dir = output_dir. join ( "latex" ) ;
149+ let comprehensive_tex = latex_dir. join ( "comprehensive_benchmark_report.tex" ) ;
150+ assert ! ( comprehensive_tex. exists( ) , "Comprehensive LaTeX report should exist" ) ;
151+
152+ println ! ( "✓ All expected directories created" ) ;
153+ println ! ( "✓ Report files generated successfully" ) ;
154+ println ! ( "✓ Directory structure created correctly" ) ;
155+ println ! ( "✓ Complete report generation pipeline test passed" ) ;
156+
157+ Ok ( ( ) )
158+ }
159+
160+ #[ tokio:: test]
161+ async fn test_report_generator_with_family_mode ( ) -> anyhow:: Result < ( ) > {
162+ // Test the family optimization mode as well
163+ let temp_dir = TempDir :: new ( ) ?;
164+ let output_path = temp_dir. path ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
165+
166+ let test_data = UnifiedReportTestSuite :: create_test_data ( ) ;
167+ let config = BenchmarkConfig :: default ( ) ;
168+ let report_generator = ReportGenerator :: new ( output_path. clone ( ) , config) ;
169+ let data_refs: Vec < _ > = test_data. iter ( ) . map ( |( p, r) | ( p, r. clone ( ) ) ) . collect ( ) ;
170+
171+ // Run with family optimization enabled
172+ report_generator
173+ . generate_main_report ( & data_refs, true )
174+ . await ?;
175+
176+ let output_dir = Path :: new ( & output_path) ;
177+ assert ! ( output_dir. exists( ) , "Output directory should exist" ) ;
178+
179+ // Verify the same basic structure exists
180+ let index_file = output_dir. join ( "report_index.html" ) ;
181+ assert ! ( index_file. exists( ) , "Report index.html should be created" ) ;
182+
183+ // Verify unified reports directory exists
184+ let unified_dir = output_dir. join ( "unified_reports" ) ;
185+ assert ! ( unified_dir. exists( ) , "Unified reports directory should exist" ) ;
186+
187+ println ! ( "✓ Family mode report generation test passed" ) ;
188+
189+ Ok ( ( ) )
190+ }
191+
192+ #[ test]
193+ fn test_report_generator_creation ( ) {
194+ // Test basic ReportGenerator creation
195+ let config = BenchmarkConfig :: default ( ) ;
196+ let _report_generator = ReportGenerator :: new ( "test_output" . to_string ( ) , config) ;
197+
198+ // This is a simple validation that the struct can be created
199+ // More detailed testing happens in the async tests above
200+ // Note: output_dir field is private, so we just test successful creation
201+ }
0 commit comments