Skip to content

Commit fb58b5d

Browse files
Add tolerance to jpeg serialization test (#53)
1 parent 54789dc commit fb58b5d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/io/img.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ pub fn serialize_img(tex: &Texture2D, path: &Path) -> Result<RawAssets> {
198198

199199
#[cfg(test)]
200200
mod test {
201+
use cgmath::AbsDiffEq;
202+
201203
fn tex() -> crate::Texture2D {
202204
crate::Texture2D {
203205
data: crate::TextureData::RgbaU8(vec![
@@ -219,10 +221,10 @@ mod test {
219221
if format == "jpeg" || format == "jpg" {
220222
if let crate::TextureData::RgbU8(data) = tex.data {
221223
// Jpeg is not lossless
222-
assert_eq!(
223-
data,
224-
vec![[48, 0, 17], [227, 0, 14], [0, 244, 0], [16, 36, 253]]
225-
);
224+
assert!(data
225+
.iter()
226+
.zip(vec![[48, 0, 17], [227, 0, 14], [0, 244, 0], [16, 36, 253]].iter())
227+
.all(|(data_pixel, test_pixel)| data_pixel.abs_diff_eq(test_pixel, 2)));
226228
} else {
227229
panic!("Wrong texture data: {:?}", tex.data)
228230
}

0 commit comments

Comments
 (0)