-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.test.py
81 lines (66 loc) · 2.95 KB
/
display.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
79
80
81
import unittest
from display import beautify_size_bytes
class TestDisplay(unittest.TestCase):
def setUp(self) -> None:
self.fn = beautify_size_bytes
return super().setUp()
def tearDown(self) -> None:
return super().tearDown()
def test_zero_bytes(self):
self.assertEqual(self.fn(0), '0 B')
self.assertEqual(self.fn(0, decimal=True), '0 B')
self.assertEqual(self.fn(0, force_int=True), '0 B')
self.assertEqual(
self.fn(0, force_int=True, decimal=True), '0 B')
def test_one_byte(self):
self.assertEqual(self.fn(1), '1 B')
self.assertEqual(self.fn(1, decimal=True), '1 B')
self.assertEqual(self.fn(1, force_int=True), '1 B')
self.assertEqual(
self.fn(1, force_int=True, decimal=True), '1 B')
def test_one_kibibyte_or_kilobyte(self):
self.assertEqual(self.fn(1024), '1.00 KiB')
self.assertEqual(self.fn(1000, decimal=True), '1.00 KB')
self.assertEqual(self.fn(1024, force_int=True), '1 KiB')
self.assertEqual(
self.fn(1000, force_int=True, decimal=True), '1 KB')
def test_one_mebibyte_or_megabyte(self):
self.assertEqual(self.fn(1024 * 1024), '1.00 MiB')
self.assertEqual(
self.fn(1000 * 1000, decimal=True), '1.00 MB')
self.assertEqual(
self.fn(1024 * 1024, force_int=True), '1 MiB')
self.assertEqual(
self.fn(1000 * 1000, force_int=True, decimal=True),
'1 MB')
def test_one_gibibyte_or_gigabyte(self):
self.assertEqual(self.fn(1024 * 1024 * 1024), '1.00 GiB')
self.assertEqual(
self.fn(1000 * 1000 * 1000, decimal=True), '1.00 GB')
self.assertEqual(
self.fn(1024 * 1024 * 1024, force_int=True), '1 GiB')
self.assertEqual(
self.fn(
1000 * 1000 * 1000, force_int=True, decimal=True),
'1 GB')
def test_negative_bytes(self):
self.assertEqual(self.fn(-1), '-1 B')
self.assertEqual(self.fn(-1, decimal=True), '-1 B')
self.assertEqual(self.fn(-1, force_int=True), '-1 B')
self.assertEqual(
self.fn(-1, force_int=True, decimal=True), '-1 B')
def test_negative_one_kibibyte_or_kilobyte(self):
self.assertEqual(self.fn(-1024), '-1.00 KiB')
self.assertEqual(self.fn(-1000, decimal=True), '-1.00 KB')
self.assertEqual(self.fn(-1024, force_int=True), '-1 KiB')
self.assertEqual(
self.fn(-1000, force_int=True, decimal=True), '-1 KB')
def test_1025_bytes_to_kibibytes(self):
self.assertEqual(self.fn(1025), '1.00 KiB')
self.assertEqual(self.fn(1025, force_int=True), '1.00 KiB')
def test_1000100_bytes_to_megabytes(self):
self.assertEqual(self.fn(1000100, decimal=True), '1.00 MB')
self.assertEqual(
self.fn(1000100, decimal=True, force_int=True), '1.00 MB')
if __name__ == '__main__':
unittest.main()