Skip to content

Commit

Permalink
test: ease float equality asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
sgt0 committed Jul 19, 2024
1 parent 8b9abe0 commit 0639535
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
26 changes: 20 additions & 6 deletions src/cambi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,8 @@ mod tests {

use super::*;

const EPISILON: f32 = 0.000000000001;

#[test]
fn test_get_mask_index() {
assert_eq!(get_mask_index(3840, 2160, 7), 24);
Expand All @@ -794,7 +796,7 @@ mod tests {
0,
1,
);
assert_relative_eq!(c_value, 2.6666667);
assert_relative_eq!(c_value, 2.6666667, epsilon = EPISILON);

diff_weights[0] = 4;
diff_weights[1] = 5;
Expand All @@ -808,7 +810,7 @@ mod tests {
0,
1,
);
assert_relative_eq!(c_value, 6.6666667);
assert_relative_eq!(c_value, 6.6666667, epsilon = EPISILON);

let value = 4;
let c_value = c_value_pixel(
Expand All @@ -827,10 +829,22 @@ mod tests {
#[test]
fn test_spatial_pooling() {
let mut arr = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 10.0, 7.0, 8.0, 9.0, 6.0, 11.0];
assert_relative_eq!(spatial_pooling(&mut arr, 0.0, 4, 3), 11.0);
assert_relative_eq!(spatial_pooling(&mut arr, 0.1, 4, 3), 11.0);
assert_relative_eq!(spatial_pooling(&mut arr, 0.2, 4, 3), 10.5);
assert_relative_eq!(spatial_pooling(&mut arr, 1.0, 4, 3), 5.5);
assert_relative_eq!(
spatial_pooling(&mut arr, 0.0, 4, 3),
11.0,
epsilon = f64::from(EPISILON)
);
assert_relative_eq!(
spatial_pooling(&mut arr, 0.1, 4, 3),
11.0,
epsilon = f64::from(EPISILON)
);
assert_relative_eq!(
spatial_pooling(&mut arr, 0.2, 4, 3),
10.5,
epsilon = f64::from(EPISILON)
);
assert_relative_eq!(spatial_pooling(&mut arr, 1.0, 4, 3), 5.5, epsilon = f64::from(EPISILON));
}

#[test]
Expand Down
20 changes: 12 additions & 8 deletions src/luminance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ mod tests {

use super::*;

const EPISILON: f64 = 0.000000000001;

#[test]
fn test_luma_range() {
assert_eq!(LumaRange::new(8, VSColorRange::VSC_RANGE_LIMITED), (16, 235));
Expand All @@ -81,28 +83,30 @@ mod tests {

#[test]
fn test_bt1886_eof() {
assert_relative_eq!(Bt1886.eotf(0.5), 58.716634039821685);
assert_relative_eq!(Bt1886.eotf(0.1), 1.5766526614315794);
assert_relative_eq!(Bt1886.eotf(0.9), 233.81950301956385);
assert_relative_eq!(Bt1886.eotf(0.5), 58.716634039821685, epsilon = EPISILON);
assert_relative_eq!(Bt1886.eotf(0.1), 1.5766526614315794, epsilon = EPISILON);
assert_relative_eq!(Bt1886.eotf(0.9), 233.81950301956385, epsilon = EPISILON);
}

#[test]
fn test_pq_eof() {
assert_relative_eq!(Pq.eotf(0.0), 0.0);
assert_relative_eq!(Pq.eotf(0.1), 0.3245655914644875);
assert_relative_eq!(Pq.eotf(0.3), 10.038226310511204);
assert_relative_eq!(Pq.eotf(0.8), 1555.1783642892847);
assert_relative_eq!(Pq.eotf(0.1), 0.3245655914644875, epsilon = EPISILON);
assert_relative_eq!(Pq.eotf(0.3), 10.038226310511204, epsilon = EPISILON);
assert_relative_eq!(Pq.eotf(0.8), 1555.1783642892847, epsilon = EPISILON);
}

#[test]
fn test_get_luminance() {
assert_relative_eq!(
get_luminance(400, &LumaRange::new(10, VSColorRange::VSC_RANGE_LIMITED), &Bt1886),
31.68933962217197
31.68933962217197,
epsilon = EPISILON
);
assert_relative_eq!(
get_luminance(400, &LumaRange::new(10, VSColorRange::VSC_RANGE_FULL), &Bt1886),
33.13300375755777
33.13300375755777,
epsilon = EPISILON
);
}
}

0 comments on commit 0639535

Please sign in to comment.