Ran cargo fmt on the code base, looks better

cargo test passes
This commit is contained in:
Nathan Fiedler
2018-10-06 15:37:17 -07:00
parent 8a4fced836
commit bd34f145a2
9 changed files with 363 additions and 228 deletions

View File

@ -16,14 +16,14 @@
extern crate magick_rust;
use magick_rust::{MagickWand, magick_wand_genesis, PixelWand, bindings};
use magick_rust::{bindings, magick_wand_genesis, MagickWand, PixelWand};
use magick_rust::ToMagick;
use std::error::Error;
use std::fs::File;
use std::io::Read;
use std::path::Path;
use std::sync::{Once, ONCE_INIT};
use magick_rust::ToMagick;
// Used to make sure MagickWand is initialized exactly once. Note that we
// do not bother shutting down, we simply exit when the tests are done.
@ -48,11 +48,11 @@ fn test_resize_image() {
assert_eq!(384, wand.get_image_height());
let halfwidth = match wand.get_image_width() {
1 => 1,
width => width / 2
width => width / 2,
};
let halfheight = match wand.get_image_height() {
1 => 1,
height => height / 2
height => height / 2,
};
wand.resize_image(halfwidth, halfheight, bindings::FilterType_LanczosFilter);
assert_eq!(256, wand.get_image_width());
@ -69,12 +69,12 @@ fn test_read_from_blob() {
let path = Path::new("tests/data/IMG_5745.JPG");
let mut file = match File::open(&path) {
Err(why) => panic!("couldn't open file: {}", Error::description(&why)),
Ok(file) => file
Ok(file) => file,
};
let mut data: Vec<u8> = Vec::new();
match file.read_to_end(&mut data) {
Err(why) => panic!("couldn't read file: {}", Error::description(&why)),
Ok(_) => ()
Ok(_) => (),
};
assert!(wand.read_image_blob(&data).is_ok());
assert_eq!(512, wand.get_image_width());
@ -186,7 +186,8 @@ fn test_compare_images() {
assert!(wand2.read_image("tests/data/IMG_5745_rotl.JPG").is_ok());
wand2.auto_orient();
let (distortion, diff) = wand1.compare_images(&wand2, bindings::MetricType_RootMeanSquaredErrorMetric);
let (distortion, diff) =
wand1.compare_images(&wand2, bindings::MetricType_RootMeanSquaredErrorMetric);
assert!(distortion < 0.01);
assert!(diff.is_some());
}
@ -225,21 +226,32 @@ fn test_transform_image_colorspace() {
});
let wand = MagickWand::new();
assert!(wand.read_image("tests/data/IMG_5745.JPG").is_ok());
assert_eq!(wand.get_image_colorspace(), bindings::ColorspaceType_sRGBColorspace);
assert_eq!(
wand.get_image_colorspace(),
bindings::ColorspaceType_sRGBColorspace
);
let pixel_color = wand.get_image_pixel_color(10, 10).unwrap();
assert_ne!(pixel_color.get_hsl().hue, 0.0);
assert!(wand.transform_image_colorspace(bindings::ColorspaceType_GRAYColorspace).is_ok());
assert_eq!(wand.get_image_colorspace(), bindings::ColorspaceType_GRAYColorspace);
assert!(
wand.transform_image_colorspace(bindings::ColorspaceType_GRAYColorspace)
.is_ok()
);
assert_eq!(
wand.get_image_colorspace(),
bindings::ColorspaceType_GRAYColorspace
);
let pixel_grayscale = wand.get_image_pixel_color(10, 10).unwrap();
assert_eq!(pixel_grayscale.get_hsl().hue, 0.0);
/* The output of `export_image_pixels` should match
* `convert -type Grayscale tests/data/IMG_5745.JPG[2x2+0+0] txt:` */
assert_eq!(wand.export_image_pixels(0, 0, 2, 2, "I").unwrap(),
vec![212, 212, 210, 210])
assert_eq!(
wand.export_image_pixels(0, 0, 2, 2, "I").unwrap(),
vec![212, 212, 210, 210]
)
}
#[test]
@ -254,17 +266,27 @@ fn test_color_reduction() {
let image_colors = wand.get_image_colors();
assert!(image_colors > 38000 || image_colors < 40000);
assert!(wand.quantize_image(6, bindings::ColorspaceType_RGBColorspace, 1,
bindings::DitherMethod_UndefinedDitherMethod, false.to_magick()).is_ok());
assert!(
wand.quantize_image(
6,
bindings::ColorspaceType_RGBColorspace,
1,
bindings::DitherMethod_UndefinedDitherMethod,
false.to_magick()
).is_ok()
);
assert_eq!(6, wand.get_image_colors());
let histogram = wand.get_image_histogram().unwrap();
assert_eq!(6, histogram.len());
assert_eq!(wand.get_image_width() * wand.get_image_height(),
histogram.iter().fold(0, |total_colors, wand| total_colors + wand.get_color_count()));
assert_eq!(
wand.get_image_width() * wand.get_image_height(),
histogram.iter().fold(0, |total_colors, wand| total_colors
+ wand.get_color_count())
);
}
#[test]
#[test]
fn test_set_image_background_color() {
START.call_once(|| {
magick_wand_genesis();
@ -274,7 +296,8 @@ fn test_set_image_background_color() {
let mut pw = PixelWand::new();
pw.set_color("#0000FF").unwrap();
wand.set_image_background_color(&pw).unwrap();
wand.set_image_alpha_channel(bindings::AlphaChannelOption_RemoveAlphaChannel).unwrap();
wand.set_image_alpha_channel(bindings::AlphaChannelOption_RemoveAlphaChannel)
.unwrap();
let blob = wand.write_image_blob("rgb").unwrap();
assert_eq!(0u8, blob[0]);
assert_eq!(0u8, blob[1]);