Commit 3647171e authored by David Michael Barr's avatar David Michael Barr
Browse files

Add tests for bexp64 and blog64

parent 4acf9df9
......@@ -293,3 +293,32 @@ impl RCState {
QuantizerParameters::new_from_log_q((log_q + log_dc_q + 1) / 2, bit_depth)
}
}
#[cfg(test)]
mod test {
use super::{bexp64, blog64};
#[test]
fn blog64_vectors() -> () {
assert!(blog64(1793) == 0x159dc71e24d32daf);
assert!(blog64(0x678dde6e5fd29f05) == 0x7d6373ad151ca685);
}
#[test]
fn bexp64_vectors() -> () {
assert!(bexp64(0x159dc71e24d32daf) == 1793);
assert!((bexp64(0x7d6373ad151ca685) - 0x678dde6e5fd29f05).abs() < 29);
}
#[test]
fn blog64_bexp64_round_trip() {
for a in 1..=std::u16::MAX as i64 {
let b = std::i64::MAX / a;
let (log_a, log_b, log_ab) = (blog64(a), blog64(b), blog64(a * b));
assert!((log_a + log_b - log_ab).abs() < 4);
assert!(bexp64(log_a) == a);
assert!((bexp64(log_b) - b).abs() < 128);
assert!((bexp64(log_ab) - a * b).abs() < 128);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment