Пример #1
0
def test_memory_manager_allocate():
    mm = MemoryManager(1)

    assert 0 == mm.allocate(0)
    assert 0 == mm.allocate(10)
    assert 10 == mm.allocate(10)
    assert 20 == mm.allocate(10)
Пример #2
0
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
Пример #3
0
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
Пример #4
0
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
Пример #5
0
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
Пример #6
0
def test_memory_manager_memory_align():
    mm = MemoryManager(8)

    assert 0 == mm.allocate(4)
    assert 8 == mm.allocate(4)
    assert 16 == mm.allocate(4)
Пример #7
0
def test_memory_manager_memory_align():
    mm = MemoryManager(64)

    assert 0 == mm.allocate(4)
    assert 64 == mm.allocate(4)
    assert 128 == mm.allocate(4)