From 8c7b78a97f359501434ca6d5b5ef34df10bf5aea Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Wed, 5 Jan 2022 17:17:10 +0300 Subject: [PATCH] tests: move common stuff into a `common` mod --- tests/common.rs | 12 ++++++++++++ tests/test_chunks.rs | 15 +++------------ 2 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 tests/common.rs diff --git a/tests/common.rs b/tests/common.rs new file mode 100644 index 0000000..cc1eff1 --- /dev/null +++ b/tests/common.rs @@ -0,0 +1,12 @@ +#[allow(unused)] +pub fn hash(px: [u8; N]) -> u8 { + let r = px[0]; + let g = px[1]; + let b = px[2]; + let a = if N >= 4 { px[3] } else { 0xff }; + let rm = r.wrapping_mul(3); + let gm = g.wrapping_mul(5); + let bm = b.wrapping_mul(7); + let am = a.wrapping_mul(11); + rm.wrapping_add(gm).wrapping_add(bm).wrapping_add(am) % 64 +} diff --git a/tests/test_chunks.rs b/tests/test_chunks.rs index beeffe4..391ba53 100644 --- a/tests/test_chunks.rs +++ b/tests/test_chunks.rs @@ -1,3 +1,5 @@ +mod common; + use bytemuck::{cast_slice, Pod}; use qoi_fast::consts::{ @@ -6,18 +8,7 @@ use qoi_fast::consts::{ }; use qoi_fast::{decode_to_vec, encode_to_vec}; -#[allow(unused)] -fn hash(px: [u8; N]) -> u8 { - let r = px[0]; - let g = px[1]; - let b = px[2]; - let a = if N >= 4 { px[3] } else { 0xff }; - let rm = r.wrapping_mul(3); - let gm = g.wrapping_mul(5); - let bm = b.wrapping_mul(7); - let am = a.wrapping_mul(11); - rm.wrapping_add(gm).wrapping_add(bm).wrapping_add(am) % 64 -} +use self::common::hash; fn test_chunk(pixels: P, expected: E) where