1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#[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");
}
}