Unverified Commit 6ec90142 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Expose the diff from ComparisonResult (#77014)

parent 347e77d9
......@@ -170,11 +170,15 @@ class LocalComparisonOutput {
/// [test] and [master] image bytes provided.
Future<ComparisonResult> compareLists(List<int>? test, List<int>? master) async {
if (identical(test, master))
return ComparisonResult(passed: true);
return ComparisonResult(
passed: true,
diffPercent: 0.0,
);
if (test == null || master == null || test.isEmpty || master.isEmpty) {
return ComparisonResult(
passed: false,
diffPercent: 1.0,
error: 'Pixel test failed, null image provided.',
);
}
......@@ -195,6 +199,7 @@ Future<ComparisonResult> compareLists(List<int>? test, List<int>? master) async
if (width != masterImage.width || height != masterImage.height) {
return ComparisonResult(
passed: false,
diffPercent: 1.0,
error: 'Pixel test failed, image sizes do not match.\n'
'Master Image: ${masterImage.width} X ${masterImage.height}\n'
'Test Image: ${testImage.width} X ${testImage.height}',
......@@ -240,10 +245,12 @@ Future<ComparisonResult> compareLists(List<int>? test, List<int>? master) async
}
if (pixelDiffCount > 0) {
final double diffPercent = pixelDiffCount / totalPixels;
return ComparisonResult(
passed: false,
diffPercent: diffPercent,
error: 'Pixel test failed, '
'${((pixelDiffCount/totalPixels) * 100).toStringAsFixed(2)}% '
'${(diffPercent * 100).toStringAsFixed(2)}% '
'diff detected.',
diffs: <String, Image>{
'masterImage' : masterImage,
......@@ -253,7 +260,7 @@ Future<ComparisonResult> compareLists(List<int>? test, List<int>? master) async
},
);
}
return ComparisonResult(passed: true);
return ComparisonResult(passed: true, diffPercent: 0.0);
}
/// Inverts [imageBytes], returning a new [ByteData] object.
......
......@@ -319,6 +319,7 @@ class ComparisonResult {
/// Creates a new [ComparisonResult] for the current test.
ComparisonResult({
required this.passed,
required this.diffPercent,
this.error,
this.diffs,
});
......@@ -335,4 +336,7 @@ class ComparisonResult {
/// values in the execution of the pixel test.
// TODO(jonahwilliams): fix type signature when image is updated to support web.
final Map<String, Object>? diffs;
/// The calculated percentage of pixel difference between two images.
final double diffPercent;
}
......@@ -104,7 +104,7 @@ void main() {
test('throws if local output is not awaited', () {
try {
comparator.generateFailureOutput(
ComparisonResult(passed: false),
ComparisonResult(passed: false, diffPercent: 1.0),
Uri.parse('foo_test.dart'),
Uri.parse('/foo/bar/'),
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment