Test another claimed property of `div_255` (#1001)
And test the entire domain we claim the properties for.
diff --git a/sparse_strips/vello_cpu/src/util.rs b/sparse_strips/vello_cpu/src/util.rs
index e51d00d..c47963f 100644
--- a/sparse_strips/vello_cpu/src/util.rs
+++ b/sparse_strips/vello_cpu/src/util.rs
@@ -36,19 +36,21 @@
use crate::util::scalar::div_255;
#[test]
- fn division() {
- for i in 0_u16..=(255 * 255) {
+ fn div_255_properties() {
+ for i in 0_u16..256 * 255 {
let expected = i / 255;
let actual = div_255(i);
- let diff = expected.abs_diff(actual);
+ assert!(
+ expected <= actual,
+ "In case of a discrepancy, the division should yield a value higher than the original."
+ );
- // Rounding error shouldn't be higher than 1.
- assert!(diff <= 1);
+ let diff = expected.abs_diff(actual);
+ assert!(diff <= 1, "Rounding error shouldn't be higher than 1.");
if i % 255 == 0 {
- // Division should be accurate for multiples of 255.
- assert_eq!(diff, 0);
+ assert_eq!(diff, 0, "Division should be accurate for multiples of 255.");
}
}
}