-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_pointer_tests.py
61 lines (50 loc) · 1.81 KB
/
file_pointer_tests.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# jamb, rusch 2017
import unittest
import random
from ordered_file_maintenance import OrderedFile, FilePointer
class TestFilePointer(unittest.TestCase):
def setUp(self):
self.file = FilePointer()
"""
TO TEST:
read_at_finger
one element, many elements
increment_finger
nothing after, one thing after, many things after
decrement_finger
nothing before, one thing before, many things before
insert_after_finger
finger at beginning, middle, end of array
"""
def test_insert_to_empty(self):
self.file.insert_after_finger(1)
self.assertEqual(self.file.read_at_finger(), 1)
def test_insert_more(self):
for i in range(20):
self.file.insert_after_finger(i)
self.assertEqual(self.file.read_at_finger(), i)
def test_incr_decr(self):
for i in range(20):
self.file.insert_after_finger(i)
self.assertEqual(self.file.read_at_finger(), i)
for i in range(20):
self.assertEqual(self.file.read_at_finger(), 19-i)
self.file.decrement_finger()
self.file.decrement_finger()
self.assertEqual(self.file.read_at_finger(), 0)
for i in range(20):
self.assertEqual(self.file.read_at_finger(), i)
self.file.increment_finger()
self.file.increment_finger()
self.assertEqual(self.file.read_at_finger(), 19)
def test_different_order(self):
self.file.insert_after_finger(-1)
for i in range(20):
self.file.insert_after_finger(i)
self.file.decrement_finger()
for i in range(20):
self.file.increment_finger()
self.assertEqual(self.file.read_at_finger(), 19-i)
if __name__ == '__main__':
test_suite = TestFilePointer
unittest.main()