-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
78 lines (54 loc) · 1.96 KB
/
test.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from sys import maxsize
from unittest import TestCase
class ListReserveTest(TestCase):
@property
def _pointer_size(self):
return 8 if maxsize > 2 ** 32 else 4
def test_capacity(self):
from list_reserve import capacity
self.assertEqual(capacity([]), 0)
self.assertEqual(capacity([1]), 1)
def test_capacity_error(self):
from list_reserve import capacity
with self.assertRaises(TypeError):
capacity(1)
def test_reserve(self):
from list_reserve import capacity, reserve
l = [1, 2, 3]
cases = [
([], 100, 100), # (list, reserve, excepted)
([], 0, 0),
([], -1, 0),
(l, 1, capacity(l)),
(l, -10, capacity(l)),
]
for l, size, excepted in cases:
reserve(l, size)
self.assertEqual(capacity(l), excepted)
def test_reserve_error(self):
from list_reserve import reserve
with self.assertRaises(TypeError):
reserve(1, 100)
def test_shrink_to_fit(self):
from list_reserve import shrink_to_fit, capacity
l = []
l.append(1)
shrink_to_fit(l)
self.assertEqual(capacity(l), len(l))
def test_shrink_to_fit_no_action(self):
from list_reserve import shrink_to_fit, capacity
l = [1, 2, 3, 4]
shrink_to_fit(l)
self.assertEqual(capacity(l), len(l))
def test_shrink_to_fit_error(self):
from list_reserve import shrink_to_fit
with self.assertRaises(TypeError):
shrink_to_fit(1)
def test_capacity_bytes(self):
from list_reserve import allocated_bytes
self.assertEqual(allocated_bytes([]), 0 * self._pointer_size)
self.assertEqual(allocated_bytes([1]), 1 * self._pointer_size)
def test_capacity_error_bytes(self):
from list_reserve import allocated_bytes
with self.assertRaises(TypeError):
allocated_bytes(1)