INNER CODE UNIT · Rust
test_basic_allocation
gfx-rs/gfx · src/auxil/range-alloc/src/lib.rs:183
fn test_basic_allocation() {
let mut alloc = RangeAllocator::new(0..10);
// Test if an allocation works
assert_eq!(alloc.allocate_range(4), Ok(0..4));
assert!(alloc.allocated_ranges().eq(std::iter::once(0..4)));
// Free the prior allocation
alloc.free_range(0..4);
// Make sure the free actually worked
assert_eq!(alloc.free_ranges, vec![0..10]);
assert!(alloc.allocated_ranges().eq(std::iter::empty()));
}
#[test]
fn test_out_of_space() {
let mut alloc = RangeAllocator::new(0..10);
// Test if the allocator runs out of space correctly
assert_eq!(alloc.allocate_range(10), Ok(0..10));
assert!(alloc.allocated_ranges().eq(std::iter::once(0..10)));