#![cfg(test)]
use super::naive;
#[cfg(all(
feature = "opt-dist-qratios-table",
not(feature = "opt-dist-qratios-table-double")
))]
use super::QRatiosDistanceTableType;
#[cfg(feature = "opt-dist-qratios-table-double")]
use super::QRatiosDistanceTableType2;
#[test]
fn arithmetic_correctness_naive() {
assert!(0x08u32
.checked_sub(1)
.and_then(|x| x.checked_mul(2))
.and_then(|x| x.checked_mul(qratio_mult!()))
.is_some());
}
#[cfg(all(
feature = "opt-dist-qratios-table",
not(feature = "opt-dist-qratios-table-double")
))]
#[test]
fn table_consistency()
where
QRatiosDistanceTableType: From<u8>,
u32: From<QRatiosDistanceTableType>,
{
let dist = QRatiosDistanceTableType::from(0x08u8);
assert!(dist
.checked_sub(1)
.and_then(|x| x.checked_mul(qratio_mult!()))
.is_some());
}
#[cfg(feature = "opt-dist-qratios-table-double")]
#[test]
fn table_consistency_double()
where
QRatiosDistanceTableType2: From<u8>,
u32: From<QRatiosDistanceTableType2>,
{
let dist = QRatiosDistanceTableType2::from(0x08u8);
assert!(dist
.checked_sub(1)
.and_then(|x| x.checked_mul(2))
.and_then(|x| x.checked_mul(qratio_mult!()))
.is_some());
}
#[test]
fn equivalence_optimized_impl() {
for qratios2 in u8::MIN..=u8::MAX {
for qratios1 in u8::MIN..=u8::MAX {
assert_eq!(
super::distance(qratios1, qratios2),
naive::distance(qratios1, qratios2)
);
}
}
}