Skip to content

Commit

Permalink
Add tests for ChromaSamplings FromPrimitive impl
Browse files Browse the repository at this point in the history
  • Loading branch information
FreezyLemon committed Mar 10, 2024
1 parent 75c9a93 commit c845344
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/pixel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,29 @@ impl ChromaSampling {
}
}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn chroma_sampling_from_int() {
let expected = [
(-1, None),
(0, Some(ChromaSampling::Cs420)),
(1, Some(ChromaSampling::Cs422)),
(2, Some(ChromaSampling::Cs444)),
(3, Some(ChromaSampling::Cs400)),
(4, None),
];

for (int, chroma_sampling) in expected {
let converted = ChromaSampling::from_i32(int);
assert_eq!(chroma_sampling, converted);

let converted_uint = ChromaSampling::from_u32(int as u32);
assert_eq!(chroma_sampling, converted_uint, "FromPrimitive does not return the same result for i32 and u32");
}
}
}

0 comments on commit c845344

Please sign in to comment.