1 // Copyright 2018, OpenCensus Authors 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 16 package zpages 17 18 import "testing" 19 20 func TestCountFormatter(t *testing.T) { 21 tests := []struct { 22 in uint64 23 want string 24 }{ 25 {0, " "}, 26 {1, "1"}, 27 {1024, "1024"}, 28 {1e5, "100000"}, 29 {1e6, "1.000 M "}, 30 {1e9, "1.000 G "}, 31 {1e8 + 2e9, "2.100 G "}, 32 {1e12, "1.000 T "}, 33 {1e15, "1.000 P "}, 34 {1e18, "1.000 E "}, 35 } 36 37 for _, tt := range tests { 38 if g, w := countFormatter(tt.in), tt.want; g != w { 39 t.Errorf("%d got %q want %q", tt.in, g, w) 40 } 41 } 42 } 43