|
@@ -0,0 +1,43 @@
|
|
1
|
+// Copyright 2017 Google Inc. All Rights Reserved.
|
|
2
|
+//
|
|
3
|
+// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+// you may not use this file except in compliance with the License.
|
|
5
|
+// You may obtain a copy of the License at
|
|
6
|
+//
|
|
7
|
+// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+//
|
|
9
|
+// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+// See the License for the specific language governing permissions and
|
|
13
|
+// limitations under the License.
|
|
14
|
+
|
|
15
|
+package measurement
|
|
16
|
+
|
|
17
|
+import (
|
|
18
|
+ "testing"
|
|
19
|
+)
|
|
20
|
+
|
|
21
|
+func TestScale(t *testing.T) {
|
|
22
|
+ for _, tc := range []struct {
|
|
23
|
+ value int64
|
|
24
|
+ fromUnit, toUnit string
|
|
25
|
+ wantValue float64
|
|
26
|
+ wantUnit string
|
|
27
|
+ }{
|
|
28
|
+ {1, "s", "ms", 1000, "ms"},
|
|
29
|
+ {1, "kb", "b", 1024, "B"},
|
|
30
|
+ {1, "kbyte", "b", 1024, "B"},
|
|
31
|
+ {1, "kilobyte", "b", 1024, "B"},
|
|
32
|
+ {1, "mb", "kb", 1024, "kB"},
|
|
33
|
+ {1, "gb", "mb", 1024, "MB"},
|
|
34
|
+ {1024, "gb", "tb", 1, "TB"},
|
|
35
|
+ {1024, "tb", "pb", 1, "PB"},
|
|
36
|
+ {2048, "mb", "auto", 2, "GB"},
|
|
37
|
+ } {
|
|
38
|
+ if gotValue, gotUnit := Scale(tc.value, tc.fromUnit, tc.toUnit); gotValue != tc.wantValue || gotUnit != tc.wantUnit {
|
|
39
|
+ t.Errorf("Scale(%d, %q, %q) = (%f, %q), want (%f, %q)",
|
|
40
|
+ tc.value, tc.fromUnit, tc.toUnit, gotValue, gotUnit, tc.wantValue, tc.wantUnit)
|
|
41
|
+ }
|
|
42
|
+ }
|
|
43
|
+}
|