sorting-race 0.2.0

Terminal-based sorting algorithm race visualization tool with real-time metrics
Documentation
#[cfg(test)]
mod memory_display_tests {
    use super::*;
    
    /// Contract test for memory value retrieval
    /// 
    /// From interactive_interface.md:
    /// Function: get_memory_display_values()
    /// Input: Vec<AlgorithmInstance>
    /// Output: Vec<(AlgorithmType, MemoryDisplayValue)>
    /// 
    /// Contract:
    ///   - For each active algorithm → call algorithm.get_memory_usage()
    ///   - Convert bytes to human-readable format (B, KB, MB)
    ///   - If algorithm inactive or error → display "N/A"
    ///   - Values update in real-time during race execution
    #[test]
    fn test_memory_display_values_for_active_algorithms() {
        // TODO: Uncomment when memory display functionality is implemented
        // let mut algorithm_instances = Vec::new();
        // 
        // // Create mock active algorithms with different memory usage
        // let mut bubble_sort = AlgorithmInstance::new(AlgorithmType::BubbleSort);
        // bubble_sort.set_memory_usage(1024); // 1 KB
        // bubble_sort.set_active(true);
        // algorithm_instances.push(bubble_sort);
        // 
        // let mut quick_sort = AlgorithmInstance::new(AlgorithmType::QuickSort);
        // quick_sort.set_memory_usage(2048); // 2 KB
        // quick_sort.set_active(true);
        // algorithm_instances.push(quick_sort);
        // 
        // let memory_values = get_memory_display_values(&algorithm_instances);
        // 
        // assert_eq!(memory_values.len(), 2);
        // 
        // // Find bubble sort entry
        // let bubble_entry = memory_values.iter()
        //     .find(|(alg_type, _)| *alg_type == AlgorithmType::BubbleSort)
        //     .expect("Bubble sort should be in memory values");
        // assert_eq!(bubble_entry.1, MemoryDisplayValue::Bytes(1024));
        // 
        // // Find quick sort entry  
        // let quick_entry = memory_values.iter()
        //     .find(|(alg_type, _)| *alg_type == AlgorithmType::QuickSort)
        //     .expect("Quick sort should be in memory values");
        // assert_eq!(quick_entry.1, MemoryDisplayValue::Bytes(2048));
        
        // For TDD: This test must fail until implementation exists
        panic!("get_memory_display_values() function and AlgorithmInstance not yet implemented - this test should fail until T019-T020 are complete");
    }
    
    #[test]
    fn test_memory_display_values_for_inactive_algorithms() {
        // Contract: If algorithm inactive or error → display "N/A"
        
        // TODO: Uncomment when memory display functionality is implemented
        // let mut algorithm_instances = Vec::new();
        // 
        // // Create inactive algorithm
        // let mut bubble_sort = AlgorithmInstance::new(AlgorithmType::BubbleSort);
        // bubble_sort.set_active(false);
        // algorithm_instances.push(bubble_sort);
        // 
        // // Create algorithm with error
        // let mut merge_sort = AlgorithmInstance::new(AlgorithmType::MergeSort);
        // merge_sort.set_error(true);
        // algorithm_instances.push(merge_sort);
        // 
        // let memory_values = get_memory_display_values(&algorithm_instances);
        // 
        // assert_eq!(memory_values.len(), 2);
        // 
        // // Both should show N/A
        // for (_, display_value) in memory_values {
        //     assert_eq!(display_value, MemoryDisplayValue::NotAvailable);
        // }
        
        // For TDD: This test must fail until implementation exists
        panic!("get_memory_display_values() function and AlgorithmInstance not yet implemented - this test should fail until T019-T020 are complete");
    }
    
    #[test]
    fn test_memory_display_calls_get_memory_usage() {
        // Contract: For each active algorithm → call algorithm.get_memory_usage()
        
        // TODO: Uncomment when memory display functionality is implemented
        // let mut algorithm_instances = Vec::new();
        // 
        // // Create mock algorithm that tracks if get_memory_usage was called
        // let mut tracked_algorithm = MockAlgorithmInstance::new(AlgorithmType::HeapSort);
        // tracked_algorithm.set_active(true);
        // tracked_algorithm.set_memory_usage(4096);
        // algorithm_instances.push(tracked_algorithm);
        // 
        // let memory_values = get_memory_display_values(&algorithm_instances);
        // 
        // // Verify get_memory_usage was called
        // assert!(algorithm_instances[0].was_get_memory_usage_called());
        // assert_eq!(memory_values.len(), 1);
        // assert_eq!(memory_values[0].1, MemoryDisplayValue::Bytes(4096));
        
        // For TDD: This test must fail until implementation exists
        panic!("get_memory_display_values() function and MockAlgorithmInstance not yet implemented - this test should fail until T019-T020 are complete");
    }
    
    #[test]
    fn test_memory_values_convert_to_human_readable() {
        // Contract: Convert bytes to human-readable format (B, KB, MB)
        
        // TODO: Uncomment when memory display functionality is implemented
        // let mut algorithm_instances = Vec::new();
        // 
        // // Test different memory sizes
        // let test_cases = vec![
        //     (512, "512 B"),           // Bytes
        //     (1024, "1.0 KB"),         // 1 KB
        //     (1536, "1.5 KB"),         // 1.5 KB
        //     (1048576, "1.0 MB"),      // 1 MB
        //     (1572864, "1.5 MB"),      // 1.5 MB
        // ];
        // 
        // for (i, (bytes, expected_format)) in test_cases.iter().enumerate() {
        //     let mut algorithm = AlgorithmInstance::new(
        //         AlgorithmType::from_index(i % 7) // Cycle through algorithm types
        //     );
        //     algorithm.set_memory_usage(*bytes);
        //     algorithm.set_active(true);
        //     algorithm_instances.push(algorithm);
        // }
        // 
        // let memory_values = get_memory_display_values(&algorithm_instances);
        // 
        // for (i, (_, display_value)) in memory_values.iter().enumerate() {
        //     let expected_format = test_cases[i].1;
        //     assert_eq!(display_value.to_string(), expected_format);
        // }
        
        // For TDD: This test must fail until implementation exists
        panic!("get_memory_display_values() function and human-readable formatting not yet implemented - this test should fail until T019-T020 are complete");
    }
    
    #[test]
    fn test_memory_values_update_in_real_time() {
        // Contract: Values update in real-time during race execution
        
        // TODO: Uncomment when memory display functionality is implemented
        // let mut algorithm_instances = Vec::new();
        // 
        // let mut algorithm = AlgorithmInstance::new(AlgorithmType::BubbleSort);
        // algorithm.set_memory_usage(1024);
        // algorithm.set_active(true);
        // algorithm_instances.push(algorithm);
        // 
        // // Get initial memory values
        // let initial_values = get_memory_display_values(&algorithm_instances);
        // assert_eq!(initial_values[0].1, MemoryDisplayValue::Bytes(1024));
        // 
        // // Simulate algorithm using more memory
        // algorithm_instances[0].set_memory_usage(2048);
        // 
        // // Get updated memory values
        // let updated_values = get_memory_display_values(&algorithm_instances);
        // assert_eq!(updated_values[0].1, MemoryDisplayValue::Bytes(2048));
        // 
        // // Values should be different (real-time update)
        // assert_ne!(initial_values[0].1, updated_values[0].1);
        
        // For TDD: This test must fail until implementation exists
        panic!("get_memory_display_values() function and real-time updates not yet implemented - this test should fail until T019-T020 are complete");
    }
    
    #[test]
    fn test_memory_display_handles_all_algorithm_types() {
        // Verify all 7 algorithm types can be handled
        
        // TODO: Uncomment when memory display functionality is implemented
        // let algorithm_types = vec![
        //     AlgorithmType::BubbleSort,
        //     AlgorithmType::SelectionSort,
        //     AlgorithmType::InsertionSort,
        //     AlgorithmType::MergeSort,
        //     AlgorithmType::QuickSort,
        //     AlgorithmType::HeapSort,
        //     AlgorithmType::ShellSort,
        // ];
        // 
        // let mut algorithm_instances = Vec::new();
        // 
        // for (i, alg_type) in algorithm_types.iter().enumerate() {
        //     let mut algorithm = AlgorithmInstance::new(*alg_type);
        //     algorithm.set_memory_usage((i + 1) * 512); // Different memory for each
        //     algorithm.set_active(true);
        //     algorithm_instances.push(algorithm);
        // }
        // 
        // let memory_values = get_memory_display_values(&algorithm_instances);
        // 
        // assert_eq!(memory_values.len(), 7);
        // 
        // // Verify all algorithm types are present
        // for alg_type in algorithm_types {
        //     assert!(memory_values.iter().any(|(t, _)| *t == alg_type));
        // }
        
        // For TDD: This test must fail until implementation exists
        panic!("get_memory_display_values() function and AlgorithmType handling not yet implemented - this test should fail until T019-T020 are complete");
    }
}