def test_memory_manager_free_first_allocated(): mm = MemoryManager() assert 0 == mm.allocate(10) assert 10 == mm.allocate(10) assert 3 == len(mm.node_list) mm.free(0) assert 3 == len(mm.node_list) assert mm.node_list[0].is_free is True assert mm.node_list[1].is_free is False assert mm.node_list[2].is_free is True
def test_memory_manager_max_allocated(): mm = MemoryManager() assert 0 == mm.allocate(10) assert 10 == mm.allocate(10) assert 20 == mm.allocate(10) assert 30 == mm.allocate(10) assert 40 == mm.allocate(10) assert 6 == len(mm.node_list) mm.free(0) mm.free(20) mm.free(10) assert mm.max_allocated() == 50
def test_memory_manager_free_middle_allocated(): mm = MemoryManager() assert 0 == mm.allocate(10) assert 10 == mm.allocate(10) assert 20 == mm.allocate(10) assert 30 == mm.allocate(10) assert 40 == mm.allocate(10) assert 6 == len(mm.node_list) mm.free(10) assert 6 == len(mm.node_list) assert mm.node_list[0].is_free is False assert mm.node_list[1].is_free is True assert mm.node_list[2].is_free is False assert mm.node_list[3].is_free is False assert mm.node_list[4].is_free is False
def test_memory_manager_free_first_free(): mm = MemoryManager(1) assert 0 == mm.allocate(10) assert 10 == mm.allocate(10) assert 20 == mm.allocate(10) assert 30 == mm.allocate(10) assert 40 == mm.allocate(10) assert 6 == len(mm.node_list) mm.free(10) mm.free(0) assert 5 == len(mm.node_list) assert mm.node_list[0].is_free is True assert mm.node_list[1].is_free is False assert mm.node_list[2].is_free is False assert mm.node_list[3].is_free is False
def test_memory_manager_bad_free(): mm = MemoryManager() with pytest.raises(RuntimeError): mm.free(10)