-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_binaryStream.py
100 lines (79 loc) · 3.23 KB
/
test_binaryStream.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from io import BytesIO
from unittest import TestCase
from binarystream import BinaryStream
__author__ = 'Peter Hofmann'
class DefaultSetup(TestCase):
"""
@type object: BinaryStream
"""
def __init__(self, methodName='runTest'):
super(DefaultSetup, self).__init__(methodName)
self.object = None
def setUp(self):
self.object = BinaryStream(BytesIO())
def tearDown(self):
self.object = None
class TestBinaryStream(DefaultSetup):
# def test_write(self):
# expected_result
# self.fail()
def test_write_bool(self):
expected_result = True
self.object.write_bool(expected_result)
self.object.seek(0)
self.assertEqual(expected_result, self.object.read_bool())
def test_write_byte(self):
expected_result = 111
self.object.write_byte(expected_result)
self.object.seek(0)
self.assertEqual(expected_result, self.object.read_byte())
def test_write_int16(self):
expected_result = 16384
self.object.write_int16(expected_result)
self.object.seek(0)
self.assertEqual(expected_result, self.object.read_int16())
def test_write_int16_unassigned(self):
expected_result = 16384
self.object.write_int16_unassigned(expected_result)
self.object.seek(0)
self.assertEqual(expected_result, self.object.read_int16_unassigned())
def test_write_int32(self):
expected_result = 536870912
self.object.write_int32(expected_result)
self.object.seek(0)
self.assertEqual(expected_result, self.object.read_int32())
def test_write_int32_unassigned(self):
expected_result = 536870912
self.object.write_int32_unassigned(expected_result)
self.object.seek(0)
self.assertEqual(expected_result, self.object.read_int32_unassigned())
def test_write_int64(self):
expected_result = 24294198314
self.object.write_int64(expected_result)
self.object.seek(0)
self.assertEqual(expected_result, self.object.read_int64())
def test_write_int64_unassigned(self):
expected_result = 24294198314
self.object.write_int64_unassigned(expected_result)
self.object.seek(0)
self.assertEqual(expected_result, self.object.read_int64_unassigned())
def test_write_float(self):
expected_result = 123123.1
self.object.write_float(expected_result)
self.object.seek(0)
self.assertAlmostEqual(expected_result, self.object.read_float(), 2)
def test_write_double(self):
expected_result = 9123123123.1
self.object.write_double(expected_result)
self.object.seek(0)
self.assertEqual(expected_result, self.object.read_double())
def test_write_string(self):
expected_result = "Some text"
self.object.write_string(expected_result)
self.object.seek(0)
self.assertEqual(expected_result, self.object.read_string())
def test_write_byte_array(self):
expected_result = [1, 2, 3, 4, 5]
self.object.write_byte_array(expected_result)
self.object.seek(0)
self.assertListEqual(expected_result, self.object.read_byte_array())