| 2cd40ea1 Andy McCall ↶ |
1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
pub mod algorithm; |
| 6 |
pub mod consts; |
| 7 |
pub mod utils; |
| 8 |
|
| 9 |
#[cfg(test)] |
| 10 |
mod property_tests { |
| 11 |
use crate::test::miri_compatible_proptest_config; |
| 12 |
use crate::{checksum, CrcAlgorithm}; |
| 13 |
use proptest::prelude::*; |
| 14 |
|
| 15 |
proptest! { |
| 16 |
#![proptest_config(miri_compatible_proptest_config())] |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#[test] |
| 24 |
fn prop_crc64_compatibility(data in proptest::collection::vec(any::<u8>(), 0..1024)) { |
| 25 |
use crate::test::consts::{RUST_CRC64_NVME, RUST_CRC64_XZ, RUST_CRC64_ECMA_182, RUST_CRC64_GO_ISO}; |
| 26 |
|
| 27 |
|
| 28 |
let our_nvme = checksum(CrcAlgorithm::Crc64Nvme, &data); |
| 29 |
let ref_nvme = RUST_CRC64_NVME.checksum(&data); |
| 30 |
prop_assert_eq!( |
| 31 |
our_nvme, ref_nvme, |
| 32 |
"CRC-64/NVME mismatch for {} bytes: our=0x{:016X}, ref=0x{:016X}", |
| 33 |
data.len(), our_nvme, ref_nvme |
| 34 |
); |
| 35 |
|
| 36 |
|
| 37 |
let our_xz = checksum(CrcAlgorithm::Crc64Xz, &data); |
| 38 |
let ref_xz = RUST_CRC64_XZ.checksum(&data); |
| 39 |
prop_assert_eq!( |
| 40 |
our_xz, ref_xz, |
| 41 |
"CRC-64/XZ mismatch for {} bytes: our=0x{:016X}, ref=0x{:016X}", |
| 42 |
data.len(), our_xz, ref_xz |
| 43 |
); |
| 44 |
|
| 45 |
|
| 46 |
let our_ecma = checksum(CrcAlgorithm::Crc64Ecma182, &data); |
| 47 |
let ref_ecma = RUST_CRC64_ECMA_182.checksum(&data); |
| 48 |
prop_assert_eq!( |
| 49 |
our_ecma, ref_ecma, |
| 50 |
"CRC-64/ECMA-182 mismatch for {} bytes: our=0x{:016X}, ref=0x{:016X}", |
| 51 |
data.len(), our_ecma, ref_ecma |
| 52 |
); |
| 53 |
|
| 54 |
|
| 55 |
let our_go_iso = checksum(CrcAlgorithm::Crc64GoIso, &data); |
| 56 |
let ref_go_iso = RUST_CRC64_GO_ISO.checksum(&data); |
| 57 |
prop_assert_eq!( |
| 58 |
our_go_iso, ref_go_iso, |
| 59 |
"CRC-64/GO-ISO mismatch for {} bytes: our=0x{:016X}, ref=0x{:016X}", |
| 60 |
data.len(), our_go_iso, ref_go_iso |
| 61 |
); |
| 62 |
} |
| 63 |
} |
| 64 |
} |