Skip to content

Commit 37dd14e

Browse files
committed
tests: Print a basic table of differences->outliers for failing image tests
1 parent 6e9dc29 commit 37dd14e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/framework/src/runner/image_test.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ pub fn test(
152152
&difference_image,
153153
ImageFormat::Png,
154154
)?;
155+
print_outlier_table(&difference_data);
155156
}
156157

157158
if is_alpha_different {
@@ -191,6 +192,36 @@ pub fn test(
191192
Ok(())
192193
}
193194

195+
fn print_outlier_table(difference_data: &[u8]) {
196+
let mut count_per_differences = [0usize; 256];
197+
let mut total_differences = 0;
198+
199+
for difference in difference_data {
200+
if *difference > 0 {
201+
total_differences += 1;
202+
count_per_differences[*difference as usize] += 1;
203+
}
204+
}
205+
206+
println!("-- Color Differences --");
207+
println!("Total > 0: {total_differences}");
208+
println!("difference | amount | percent | withPriors | remaining");
209+
let total = total_differences as f64;
210+
let mut prior_count = 0;
211+
for (i, count) in count_per_differences.iter().enumerate() {
212+
if *count > 0 {
213+
prior_count += count;
214+
let pct = *count as f64 / total * 100.0;
215+
let pct_inc_below = prior_count as f64 / total * 100.0;
216+
let remaining = total_differences - prior_count;
217+
println!(
218+
"{i:>10} | {count:>10} | {pct:>6.2}% | {pct_inc_below:>9.2}% | {remaining:>9}"
219+
);
220+
}
221+
}
222+
println!("-----");
223+
}
224+
194225
fn calculate_difference_data(
195226
actual_image: &image::RgbaImage,
196227
expected_image: &image::RgbaImage,

0 commit comments

Comments
 (0)