-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprefix_test.go
171 lines (160 loc) · 5.46 KB
/
prefix_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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package binaryprefix
import (
"fmt"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestInvalidFormat(t *testing.T) {
Convey("Scenario: Convert string with an invalid format to number of megabytes", t, func() {
Convey("Given the string 'foo', fails as it is an invalid format", func() {
str := "foo"
mb, err := GetMB(str)
So(mb, ShouldEqual, 0)
So(err.Error(), ShouldEqual, "strconv.ParseFloat: parsing \"f\": invalid syntax")
})
})
}
func TestMB(t *testing.T) {
Convey("Scenario: Convert string with the prefix MB to number of megabytes", t, func() {
Convey("Given the string 1MB, the number of megabytes is 1", func() {
str := "1MB"
mb, _ := GetMB(str)
So(mb, ShouldEqual, 1)
})
Convey("Given the string 0.5MB, the number of megabytes is 0.5", func() {
str := "0.5MB"
mb, err := GetMB(str)
fmt.Println(err)
So(mb, ShouldEqual, 0)
})
Convey("Given the string 1mb, the number of megabytes is 0 as lower case denominations are not supported", func() {
str := "1mb"
mb, err := GetMB(str)
So(mb, ShouldEqual, 0)
So(err.Error(), ShouldEqual, "Unknown Denomination")
})
})
}
func TestGB(t *testing.T) {
Convey("Scenario: Convert string with the prefix GB to number of megabytes", t, func() {
Convey("Given the string 1GB, the number of megabytes is 1024", func() {
str := "1GB"
mb, _ := GetMB(str)
So(mb, ShouldEqual, 1024)
})
Convey("Given the string 0.5GB, the number of megabytes is 0.5024", func() {
str := "0.5GB"
mb, _ := GetMB(str)
So(mb, ShouldEqual, 512)
})
Convey("Given the string 1gb, the number of megabytes is 0 as lower case denominations are not supported", func() {
str := "1gb"
mb, err := GetMB(str)
So(mb, ShouldEqual, 0)
So(err.Error(), ShouldEqual, "Unknown Denomination")
})
})
}
func TestTB(t *testing.T) {
Convey("Scenario: Convert string with the prefix TB to number of megabytes", t, func() {
Convey("Given the string 1TB, the number of megabytes is 1048576", func() {
str := "1TB"
mb, _ := GetMB(str)
So(mb, ShouldEqual, 1048576)
})
Convey("Given the string 0.5TB, the number of megabytes is 0.5048576", func() {
str := "0.5TB"
mb, _ := GetMB(str)
So(mb, ShouldEqual, 524288)
})
Convey("Given the string 1tb, the number of megabytes is 0 as lower case denominations are not supported", func() {
str := "1tb"
mb, err := GetMB(str)
So(mb, ShouldEqual, 0)
So(err.Error(), ShouldEqual, "Unknown Denomination")
})
})
}
func TestPB(t *testing.T) {
Convey("Scenario: Convert string with the prefix PB to number of megabytes", t, func() {
Convey("Given the string 1PB, the number of megabytes is 1073741824", func() {
str := "1PB"
mb, _ := GetMB(str)
So(mb, ShouldEqual, 1073741824)
})
Convey("Given the string 0.5PB, the number of megabytes is 0.5073740.5824", func() {
str := "0.5PB"
mb, _ := GetMB(str)
So(mb, ShouldEqual, 536870912)
})
Convey("Given the string 1pb, the number of megabytes is 0 as lower case denominations are not supported", func() {
str := "1pb"
mb, err := GetMB(str)
So(mb, ShouldEqual, 0)
So(err.Error(), ShouldEqual, "Unknown Denomination")
})
})
}
func TestEB(t *testing.T) {
Convey("Scenario: Convert string with the prefix EB to number of megabytes", t, func() {
Convey("Given the string 1EB, the number of megabytes is 1099511627776", func() {
str := "1EB"
mb, _ := GetMB(str)
So(mb, ShouldEqual, 1099511627776)
})
Convey("Given the string 0.5EB, the number of megabytes is 0.509950.50.5627776", func() {
str := "0.5EB"
mb, _ := GetMB(str)
So(mb, ShouldEqual, 549755813888)
})
Convey("Given the string 1eb, the number of megabytes is 0 as lower case denominations are not supported", func() {
str := "1eb"
mb, err := GetMB(str)
So(mb, ShouldEqual, 0)
So(err.Error(), ShouldEqual, "Unknown Denomination")
})
})
}
func TestZB(t *testing.T) {
Convey("Scenario: Convert string with the prefix ZB to number of megabytes", t, func() {
Convey("Given the string 1ZB, the number of megabytes is 1125899906842624", func() {
str := "1ZB"
mb, _ := GetMB(str)
So(mb, ShouldEqual, 1125899906842624)
})
Convey("Given the string 0.5ZB, the number of megabytes is 0.50.525899906842624", func() {
str := "0.5ZB"
mb, _ := GetMB(str)
So(mb, ShouldEqual, 562949953421312)
})
Convey("Given the string 1zb, the number of megabytes is 0 as lower case denominations are not supported", func() {
str := "1zb"
mb, err := GetMB(str)
So(mb, ShouldEqual, 0)
So(err.Error(), ShouldEqual, "Unknown Denomination")
})
})
}
func TestYB(t *testing.T) {
Convey("Scenario: Convert string with the prefix YB to number of megabytes", t, func() {
Convey("Given the string 1YB, the number of megabytes is 1152921504606846976", func() {
str := "1YB"
mb, _ := GetMB(str)
So(mb, ShouldEqual, 1152921504606846976)
})
Convey("Given the string 0.5YB, the number of megabytes is 0.50.552920.5504606846976", func() {
str := "0.5YB"
mb, _ := GetMB(str)
So(mb, ShouldEqual, 576460752303423488)
})
Convey("Given the string 1yb, the number of megabytes is 0 as lower case denominations are not supported", func() {
str := "1yb"
mb, err := GetMB(str)
So(mb, ShouldEqual, 0)
So(err.Error(), ShouldEqual, "Unknown Denomination")
})
})
}