-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbytes_test.go
executable file
·57 lines (54 loc) · 1.35 KB
/
bytes_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
package creader
import (
"testing"
)
func TestByteCountDecimal(t *testing.T) {
type args struct {
b int64
}
tests := []struct {
name string
args args
want string
}{
{"bytes", args{b: 2}, "2 B"},
{"kilobytes", args{b: 2 * 1 << 10}, "2.0 kB"},
{"megabytes", args{b: 2 * 1 << 20}, "2.1 MB"},
{"gigabytes", args{b: 2 * 1 << 30}, "2.1 GB"},
{"terabytes", args{b: 2 * 1 << 40}, "2.2 TB"},
{"petabytes", args{b: 2 * 1 << 50}, "2.3 PB"},
{"exabytes", args{b: 2 * 1 << 60}, "2.3 EB"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ByteCountDecimal(tt.args.b); got != tt.want {
t.Errorf("ByteCountDecimal() = %v, want %v", got, tt.want)
}
})
}
}
func TestByteCountBinary(t *testing.T) {
type args struct {
b int64
}
tests := []struct {
name string
args args
want string
}{
{"bytes", args{b: 2}, "2 B"},
{"kibibytes", args{b: 2 * 1 << 10}, "2.0 KiB"},
{"mebibytes", args{b: 2 * 1 << 20}, "2.0 MiB"},
{"gibibytes", args{b: 2 * 1 << 30}, "2.0 GiB"},
{"tebibytes", args{b: 2 * 1 << 40}, "2.0 TiB"},
{"pebibytes", args{b: 2 * 1 << 50}, "2.0 PiB"},
{"exbibytes", args{b: 2 * 1 << 60}, "2.0 EiB"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ByteCountBinary(tt.args.b); got != tt.want {
t.Errorf("ByteCountBinary() = %v, want %v", got, tt.want)
}
})
}
}