-
Notifications
You must be signed in to change notification settings - Fork 0
/
ByteMath_test.go
196 lines (159 loc) · 4.27 KB
/
ByteMath_test.go
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package bytemath
import (
"testing"
)
var (
byte = 1
kilobyte = byte * 1024
megabyte = kilobyte * 1024
gigabyte = megabyte * 1024
terabyte = gigabyte * 1024
petabyte = terabyte * 1024
)
func TestHumanReadable(t *testing.T) {
t.Run("Test Bytes to Human-Readable Bytes", func(t *testing.T) {
want := "1 B"
got := ConvertBytesToHumanReadable(int64(byte))
if got != want {
t.Errorf("Wanted %s got %s", want, got)
}
})
t.Run("Test Bytes to Human-Readable Kilobytes", func(t *testing.T) {
want := "1 KB"
got := ConvertBytesToHumanReadable(int64(kilobyte))
if got != want {
t.Errorf("Wanted %s got %s", want, got)
}
})
t.Run("Test Bytes to Human-Readable Megabytes", func(t *testing.T) {
mbs := int64(megabyte)
want := "1 MB"
got := ConvertBytesToHumanReadable(mbs)
if got != want {
t.Errorf("Wanted %s got %s", want, got)
}
})
t.Run("Test Bytes to Human-Readable Gigabytes", func(t *testing.T) {
gbs := int64(gigabyte)
want := "1 GB"
got := ConvertBytesToHumanReadable(gbs)
if got != want {
t.Errorf("Wanted %s got %s", want, got)
}
})
t.Run("Test Bytes to Human-Readable Terabytes", func(t *testing.T) {
tbs := int64(terabyte)
want := "1 TB"
got := ConvertBytesToHumanReadable(tbs)
if got != want {
t.Errorf("Wanted %s got %s", want, got)
}
})
t.Run("Test Bytes to Human-Readable Petabytes", func(t *testing.T) {
pbs := int64(petabyte)
want := "1 PB"
got := ConvertBytesToHumanReadable(pbs)
if got != want {
t.Errorf("Wanted %s got %s", want, got)
}
})
}
func TestConvertToBytes(t *testing.T) {
//test convert to bytes function
t.Run("Test Convert Bytes to Bytes", func(t *testing.T) {
want := float64(byte)
got := ConvertToBytes(float64(byte), B)
if got != want {
t.Errorf("Wanted %f got %f", want, got)
}
})
t.Run("Test Convert Kilobytes to Bytes", func(t *testing.T) {
want := float64(kilobyte)
got := ConvertToBytes(float64(1), KB)
if got != want {
t.Errorf("Wanted %f got %f", want, got)
}
})
t.Run("Test convert Megabytes to Bytes", func(t *testing.T) {
want := float64(megabyte)
got := ConvertToBytes(float64(1), MB)
if got != want {
t.Errorf("Wanted %f got %f", want, got)
}
})
t.Run("Test convert Gigabytes to Bytes", func(t *testing.T) {
want := float64(gigabyte)
got := ConvertToBytes(float64(1), GB)
if got != want {
t.Errorf("Wanted %f got %f", want, got)
}
})
t.Run("Test convert Terabytes to Bytes", func(t *testing.T) {
want := float64(terabyte)
got := ConvertToBytes(float64(1), TB)
if got != want {
t.Errorf("Wanted %f got %f", want, got)
}
})
t.Run("Test Convert Petabytes to Bytes", func(t *testing.T) {
want := float64(petabyte)
got := ConvertToBytes(float64(1), PB)
if got != want {
t.Errorf("Wanted %f got %f", want, got)
}
})
}
func TestConvertBytesToOther(t *testing.T) {
t.Run("Test convert Bytes to Bytes", func(t *testing.T) {
var want = float64(byte)
got := ConvertBytes(int64(byte), B)
if got != want {
t.Errorf("Wanted %f got %f", want, got)
}
})
t.Run("Test convert Bytes to Kilobytes", func(t *testing.T) {
var want float64 = 1.00
got := ConvertBytes(int64(kilobyte), KB)
if got != want {
t.Errorf("Wanted %f got %f", want, got)
}
})
t.Run("Test convert Byte to Megabytes", func(t *testing.T) {
var want float64 = 1.00
got := ConvertBytes(int64(megabyte), MB)
if got != want {
t.Errorf("Wanted %f got %f", want, got)
}
})
t.Run("Test convert Bytes to Gigabytes", func(t *testing.T) {
var want float64 = 1.00
got := ConvertBytes(int64(gigabyte), GB)
if got != want {
t.Errorf("Wanted %f got %f", want, got)
}
})
t.Run("Test convert Bytes to Terabytes", func(t *testing.T) {
var want float64 = 1.00
got := ConvertBytes(int64(terabyte), TB)
if got != want {
t.Errorf("Wanted %f got %f", want, got)
}
})
t.Run("Test convert Bytes to Petabytes", func(t *testing.T) {
var want float64 = 1.00
got := ConvertBytes(int64(petabyte), PB)
if got != want {
t.Errorf("Wanted %f got %f", want, got)
}
})
}
func TestGetSuffixByValue(t *testing.T) {
t.Run("Test Getting Suffix by String Value", func(t *testing.T) {
suffixString := "KB"
want := KB
got := *GetSuffixByString(suffixString)
if got != want {
t.Errorf("Wanted %v got %v", want, got)
}
})
}