Skip to content

Commit 0c3d81b

Browse files
committed
Add tests for impossible allocations (OOM)
1 parent bca675e commit 0c3d81b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/test.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ fn new_heap() -> Heap {
1515
heap
1616
}
1717

18+
#[test]
19+
fn empty() {
20+
let mut heap = Heap::empty();
21+
assert!(heap.allocate_first_fit(1, 1).is_none());
22+
}
23+
24+
#[test]
25+
fn oom() {
26+
let mut heap = new_heap();
27+
let size = heap.top() - heap.bottom() + 1;
28+
let addr = heap.allocate_first_fit(size, align_of::<usize>());
29+
assert!(addr.is_none());
30+
}
31+
1832
#[test]
1933
fn allocate_double_usize() {
2034
let mut heap = new_heap();

0 commit comments

Comments
 (0)