INNER CODE UNIT · Rust
test_out_of_space
gfx-rs/gfx · src/auxil/range-alloc/src/lib.rs:196
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)));
assert!(alloc.allocate_range(4).is_err());
alloc.free_range(0..10);
}
#[test]
fn test_dont_use_block_that_is_too_small() {
let mut alloc = RangeAllocator::new(0..10);
// Allocate three blocks then free the middle one and check for correct state
assert_eq!(alloc.allocate_range(3), Ok(0..3));
assert_eq!(alloc.allocate_range(3), Ok(3..6));
assert_eq!(alloc.allocate_range(3), Ok(6..9));
alloc.free_range(3..6);
assert_eq!(alloc.free_ranges, vec![3..6, 9..10]);