use memkit::{MkAllocator, MkConfig};
use std::time::Duration;
#[test]
fn test_allocator_phases() {
let alloc = MkAllocator::new(MkConfig::default());
alloc.begin_frame();
let phase = alloc.begin_phase("Physics");
let _box1 = alloc.frame_box(1u32).unwrap();
let _box2 = alloc.frame_box(2u32).unwrap();
std::thread::sleep(Duration::from_millis(50));
let report = phase.end();
assert_eq!(report.name, "Physics");
assert!(report.duration >= Duration::from_millis(50));
assert_eq!(report.alloc_count, 2);
assert_eq!(report.bytes_allocated, std::mem::size_of::<u32>() * 2);
alloc.end_frame();
}
#[test]
fn test_nested_phases_simulation() {
let alloc = MkAllocator::new(MkConfig::default());
alloc.begin_frame();
let outer = alloc.begin_phase("Outer");
let _ = alloc.frame_box(1u64).unwrap();
{
let inner = alloc.begin_phase("Inner");
let _ = alloc.frame_vec::<u8>(10).unwrap(); let inner_report = inner.end();
assert_eq!(inner_report.alloc_count, 1);
assert_eq!(inner_report.bytes_allocated, 10);
}
let outer_report = outer.end();
assert_eq!(outer_report.alloc_count, 2);
assert_eq!(outer_report.bytes_allocated, 18);
alloc.end_frame();
}