-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for terabyte and petabyte memory units. (#138)
* Add support for terabyte and petabyte memory units. This fixes #137 (but not #136, this will come separately once we decide what we want to do if anything). * Add a test. * Update copyright year
- Loading branch information
Showing
2 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2017 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package measurement | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestScale(t *testing.T) { | ||
for _, tc := range []struct { | ||
value int64 | ||
fromUnit, toUnit string | ||
wantValue float64 | ||
wantUnit string | ||
}{ | ||
{1, "s", "ms", 1000, "ms"}, | ||
{1, "kb", "b", 1024, "B"}, | ||
{1, "kbyte", "b", 1024, "B"}, | ||
{1, "kilobyte", "b", 1024, "B"}, | ||
{1, "mb", "kb", 1024, "kB"}, | ||
{1, "gb", "mb", 1024, "MB"}, | ||
{1024, "gb", "tb", 1, "TB"}, | ||
{1024, "tb", "pb", 1, "PB"}, | ||
{2048, "mb", "auto", 2, "GB"}, | ||
} { | ||
if gotValue, gotUnit := Scale(tc.value, tc.fromUnit, tc.toUnit); gotValue != tc.wantValue || gotUnit != tc.wantUnit { | ||
t.Errorf("Scale(%d, %q, %q) = (%f, %q), want (%f, %q)", | ||
tc.value, tc.fromUnit, tc.toUnit, gotValue, gotUnit, tc.wantValue, tc.wantUnit) | ||
} | ||
} | ||
} |