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
#![deny(clippy::all)]
use std::path::{Path, PathBuf};
pub use parameterized::ide;
pub use parameterized::parameterized as pm;
#[macro_export]
macro_rules! approx_eq_f32 {
($input:expr, $expected:expr) => {
assert!(($input - $expected).abs() <= std::f32::EPSILON);
};
}
#[macro_export]
macro_rules! out_ {
($path:expr) => {
&[env!("CARGO_MANIFEST_DIR"), "/../../target/", $path].concat()
};
}
#[macro_export]
macro_rules! in_ {
($path:expr) => {
&[env!("CARGO_MANIFEST_DIR"), "/../../resources/", $path].concat()
};
}
pub fn setup_test_image(test_image_path: &str) -> PathBuf {
Path::new("").join(in_!(test_image_path))
}
pub fn setup_output_path(test_output_path: &str) -> PathBuf {
Path::new("").join(out_!(test_output_path))
}
pub fn clean_up_output_path(test_output_path: &str) {
std::fs::remove_file(setup_output_path(test_output_path))
.expect("Unable to remove file after test.");
}
pub fn open_test_image<P: AsRef<Path>>(path: P) -> sic_core::image::DynamicImage {
sic_core::image::open(path.as_ref()).unwrap()
}
pub fn image_eq<T: Into<sic_core::image::DynamicImage>>(left: T, right: T) -> bool {
use sic_core::image::GenericImageView;
let left = left.into();
let right = right.into();
left.dimensions() == right.dimensions()
&& left
.pixels()
.zip(right.pixels())
.all(|(l, r)| l.0 == r.0 && l.1 == r.1 && l.2 == r.2)
}