-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_disk.py
35 lines (30 loc) · 1.04 KB
/
test_disk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import unittest
from structures import Disk
from utils import *
class TestDisk(unittest.TestCase):
def test_disk(self):
self.assertEqual(Disk.next_free_idx, 1)
self.assertEqual(len(Disk.free_queue), 0)
idx = Disk.get_next_free()
block = Disk.read_block(idx)
block.bytes[0] = 10
Disk.write_block(idx, block)
self.assertEqual(block, Disk.read_block(idx))
idx = Disk.get_next_free()
self.assertEqual(idx, 2)
idx = Disk.get_next_free()
self.assertEqual(idx, 3)
Disk.deallocate(1)
self.assertEqual(len(Disk.free_queue), 1)
idx = Disk.get_next_free()
self.assertEqual(idx, 1)
self.assertEqual(len(Disk.free_queue), 0)
idx = Disk.get_next_free()
self.assertEqual(idx, 4)
Disk.deallocate(4)
Disk.deallocate(2)
self.assertEqual(len(Disk.free_queue), 2)
idx = Disk.get_next_free()
self.assertEqual(idx, 4)
idx = Disk.get_next_free()
self.assertEqual(idx, 2)