aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/vendor/github.com/google/pprof/internal/measurement/measurement_test.go
blob: 155cafa19824ac4373b1bfbd57a20a720e8e8e23 (plain)
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
// 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"},
		{3.1536e7, "s", "auto", 1, "yrs"},
		{-1, "s", "ms", -1000, "ms"},
		{1, "foo", "count", 1, ""},
		{1, "foo", "bar", 1, "bar"},
	} {
		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)
		}
	}
}