use proptest::prelude::*;
use snid::Snid;
proptest! {
#[test]
fn prop_bytes_roundtrip(timestamp_ms in 0u64..(1u64 << 48)) {
let hash = [0u8; 32];
let id1 = Snid::from_hash_with_timestamp(timestamp_ms, &hash);
let bytes_repr = id1.to_bytes();
let id2 = Snid::from_bytes(bytes_repr);
prop_assert_eq!(id1, id2);
}
#[test]
fn prop_id_length(timestamp_ms in 0u64..(1u64 << 48)) {
let hash = [0u8; 32];
let id1 = Snid::from_hash_with_timestamp(timestamp_ms, &hash);
let bytes_repr = id1.to_bytes();
prop_assert_eq!(bytes_repr.len(), 16);
}
#[test]
fn prop_version_bits(timestamp_ms in 0u64..(1u64 << 48)) {
let hash = [0u8; 32];
let id1 = Snid::from_hash_with_timestamp(timestamp_ms, &hash);
let bytes_repr = id1.to_bytes();
let version = (bytes_repr[6] >> 4) & 0x0F;
prop_assert_eq!(version, 0x7);
}
#[test]
fn prop_variant_bits(timestamp_ms in 0u64..(1u64 << 48)) {
let hash = [0u8; 32];
let id1 = Snid::from_hash_with_timestamp(timestamp_ms, &hash);
let bytes_repr = id1.to_bytes();
let variant = (bytes_repr[8] >> 6) & 0b11;
prop_assert_eq!(variant, 0b10);
}
}