-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitfield_test.py
75 lines (53 loc) · 1.87 KB
/
bitfield_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
"""Tests for the BitField class."""
import unittest
import bitfield
__author__ = 'Brian Landers <[email protected]>'
class BitFieldTest(unittest.TestCase):
"""Tests for the BitField class."""
def setUp(self):
self.bits = bitfield.BitField(36)
def test_constructor(self):
for i in xrange(0, 36):
self.assertFalse(self.bits.test(i))
def test_constructor_args(self):
with self.assertRaises(ValueError):
_ = bitfield.BitField(0)
with self.assertRaises(ValueError):
_ = bitfield.BitField(-1)
def test_set(self):
for i in xrange(0, 36):
self.assertFalse(self.bits.test(i))
self.bits.set(17)
for i in xrange(0, 17):
self.assertFalse(self.bits.test(i))
self.assertTrue(self.bits.test(17))
for i in xrange(18, 36):
self.assertFalse(self.bits.test(i))
def test_set_args(self):
with self.assertRaises(ValueError):
self.bits.set(-1)
with self.assertRaises(ValueError):
self.bits.set(36)
def test_clear(self):
self.bits.set(17)
self.assertTrue(self.bits.test(17))
self.bits.clear(17)
self.assertFalse(self.bits.test(17))
def test_clear_args(self):
with self.assertRaises(ValueError):
self.bits.clear(-1)
with self.assertRaises(ValueError):
self.bits.clear(36)
def test_toggle(self):
self.assertFalse(self.bits.test(17))
self.bits.toggle(17)
self.assertTrue(self.bits.test(17))
self.bits.toggle(17)
self.assertFalse(self.bits.test(17))
def test_toggle_args(self):
with self.assertRaises(ValueError):
self.bits.toggle(-1)
with self.assertRaises(ValueError):
self.bits.toggle(36)
if __name__ == '__main__':
unittest.main()