Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
Test that the dezoomed image actually has the expected pixels
  • Loading branch information
lovasoa committed Apr 12, 2020
1 parent cb0d27b commit 44d7b48
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/test_local_dezoomifying.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use dezoomify_rs::{Arguments, dezoomify, ZoomError};
use std::default::Default;
use image::{self, DynamicImage, GenericImageView};

/// Dezoom a file locally
#[tokio::test(threaded_scheduler)]
Expand All @@ -16,6 +17,17 @@ async fn custom_size_local_zoomify_tiles() -> Result<(), ZoomError> {
args.outfile = Some(out.clone());
dezoomify(&args).await?;

assert!(out.exists());
let actual = image::open(&out)?;
let expected = image::open("testdata/zoomify/test_custom_size/expected_result.jpg")?;
assert_images_equal(actual, expected);
Ok(())
}

fn assert_images_equal(a: DynamicImage, b: DynamicImage) {
assert_eq!(a.dimensions(), b.dimensions(), "image dimensions should match");
for ((_, _, a), (_, _, b)) in a.pixels().zip(b.pixels()) {
for (&pa, &pb) in a.0.iter().zip(b.0.iter()) {
assert!(pa.max(pb) - pa.min(pb) < 10);
}
}
}

0 comments on commit 44d7b48

Please sign in to comment.