1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 04:52:26 -05:00

add unit test

This commit is contained in:
Hajime-san 2024-09-08 20:24:00 +09:00
parent 1f7524a47c
commit 98e9304f2a

View file

@ -595,3 +595,51 @@ pub(crate) fn to_srgb_from_icc_profile(
},
}
}
#[cfg(test)]
mod tests {
use super::*;
use image::Rgba;
#[test]
fn test_premultiply_alpha() {
let rgba = Rgba::<u8>([255, 128, 0, 128]);
let rgba = rgba.premultiply_alpha();
assert_eq!(rgba, Rgba::<u8>([128, 64, 0, 128]));
let rgba = Rgba::<u8>([255, 255, 255, 255]);
let rgba = rgba.premultiply_alpha();
assert_eq!(rgba, Rgba::<u8>([255, 255, 255, 255]));
}
#[test]
fn test_unpremultiply_alpha() {
let rgba = Rgba::<u8>([127, 0, 0, 127]);
let rgba = rgba.unpremultiply_alpha();
assert_eq!(rgba, Rgba::<u8>([255, 0, 0, 127]));
}
#[test]
fn test_apply_conversion_matrix_srgb_to_display_p3() {
let (r, g, b) = apply_conversion_matrix_srgb_to_display_p3(255_u8, 0, 0);
assert_eq!(r, 234);
assert_eq!(g, 51);
assert_eq!(b, 35);
let (r, g, b) = apply_conversion_matrix_srgb_to_display_p3(0_u8, 255, 0);
assert_eq!(r, 117);
assert_eq!(g, 251);
assert_eq!(b, 76);
let (r, g, b) = apply_conversion_matrix_srgb_to_display_p3(0_u8, 0, 255);
assert_eq!(r, 0);
assert_eq!(g, 0);
assert_eq!(b, 245);
let (r, g, b) =
apply_conversion_matrix_srgb_to_display_p3(255_u8, 255, 255);
assert_eq!(r, 255);
assert_eq!(g, 255);
assert_eq!(b, 255);
}
}