INNER CODE UNIT · Rust
test_dont_use_block_that_is_too_small
gfx-rs/gfx · src/auxil/range-alloc/src/lib.rs:206
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]);
assert_eq!(
alloc.allocated_ranges().collect::<Vec<Range<i32>>>(),
vec![0..3, 6..9]
);
// Now request space that the middle block can fill, but the end one can't.
assert_eq!(alloc.allocate_range(3), Ok(3..6));
}
#[test]
fn test_free_blocks_in_middle() {