tests: move common stuff into a common mod

This commit is contained in:
Ivan Smirnov 2022-01-05 17:17:10 +03:00
parent 432f9d3af6
commit 8c7b78a97f
2 changed files with 15 additions and 12 deletions

12
tests/common.rs Normal file
View file

@ -0,0 +1,12 @@
#[allow(unused)]
pub fn hash<const N: usize>(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
}

View file

@ -1,3 +1,5 @@
mod common;
use bytemuck::{cast_slice, Pod}; use bytemuck::{cast_slice, Pod};
use qoi_fast::consts::{ use qoi_fast::consts::{
@ -6,18 +8,7 @@ use qoi_fast::consts::{
}; };
use qoi_fast::{decode_to_vec, encode_to_vec}; use qoi_fast::{decode_to_vec, encode_to_vec};
#[allow(unused)] use self::common::hash;
fn hash<const N: usize>(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
}
fn test_chunk<P, E, const N: usize>(pixels: P, expected: E) fn test_chunk<P, E, const N: usize>(pixels: P, expected: E)
where where