use super::{
LocalityDomainId, MemoryTier, NumaBucketIndex, NumaNodeId, PlacementHint, TopologyEpoch,
WorkerId,
};
#[test]
fn typed_ids_preserve_values() {
assert_eq!(NumaNodeId::new(7).get(), 7);
assert_eq!(NumaNodeId::new(7).index(), 7);
assert_eq!(NumaNodeId::new(19).bucket_index::<16>().index(), 3);
assert_eq!(
NumaNodeId::new(19)
.bucket_index::<16>()
.wrapping_add(15)
.index(),
2
);
assert_eq!(WorkerId::new(3).get(), 3);
assert_eq!(WorkerId::new(3).index(), 3);
assert_eq!(LocalityDomainId::new(11).get(), 11);
assert_eq!(TopologyEpoch::new(19).get(), 19);
assert_eq!(TopologyEpoch::new(19).next().get(), 20);
assert_eq!(TopologyEpoch::new(u64::MAX).next().get(), 0);
assert!(NumaNodeId::new(7).is_valid());
assert!(!NumaNodeId::INVALID.is_valid());
assert!(WorkerId::new(3).is_valid());
assert!(!WorkerId::INVALID.is_valid());
assert!(LocalityDomainId::new(11).is_valid());
assert!(!LocalityDomainId::INVALID.is_valid());
}
#[test]
fn default_placement_is_current_dram() {
assert_eq!(PlacementHint::default(), PlacementHint::Current);
assert_eq!(MemoryTier::default(), MemoryTier::Dram);
}
macro_rules! bucket_index_properties {
($mod_name:ident, $buckets:literal) => {
mod $mod_name {
#![allow(clippy::modulo_one)]
use super::NumaBucketIndex;
proptest::proptest! {
#[test]
fn new_is_always_in_range(raw in 0u32..=u32::MAX) {
let idx = NumaBucketIndex::<$buckets>::new(raw as usize);
proptest::prop_assert!(idx.index() < $buckets);
}
#[test]
fn new_matches_modulo_reference(raw in 0usize..1_000_000) {
let idx = NumaBucketIndex::<$buckets>::new(raw);
proptest::prop_assert_eq!(idx.index(), raw % $buckets);
}
#[test]
fn wrapping_add_matches_modulo_reference(
raw in 0usize..1_000_000,
offset in 0usize..1_000_000,
) {
let start = NumaBucketIndex::<$buckets>::new(raw);
let advanced = start.wrapping_add(offset);
proptest::prop_assert!(advanced.index() < $buckets);
proptest::prop_assert_eq!(advanced.index(), (start.index() + offset) % $buckets);
}
#[test]
fn wrapping_add_full_cycle_is_identity(raw in 0usize..1_000_000) {
let start = NumaBucketIndex::<$buckets>::new(raw);
proptest::prop_assert_eq!(start.wrapping_add($buckets).index(), start.index());
}
}
}
};
}
bucket_index_properties!(buckets_1, 1);
bucket_index_properties!(buckets_7, 7);
bucket_index_properties!(buckets_16, 16);