github.com/XiaoMi/Gaea@v1.2.5/stats/multidimensional_test.go (about) 1 /* 2 Copyright 2017 Google Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreedto in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package stats 18 19 import ( 20 "reflect" 21 "testing" 22 "time" 23 ) 24 25 func TestMultiTimingsCounterFor(t *testing.T) { 26 clear() 27 mtm := NewMultiTimings("multitimings3", "help", []string{"dim1", "dim2"}) 28 29 mtm.Add([]string{"tag1a", "tag1b"}, 500*time.Microsecond) 30 mtm.Add([]string{"tag1a", "tag2b"}, 500*time.Millisecond) 31 mtm.Add([]string{"tag2a", "tag2b"}, 500*time.Millisecond) 32 33 cases := []struct { 34 dim string 35 want map[string]int64 36 }{ 37 {"dim1", map[string]int64{"tag1a": 2, "tag2a": 1, "All": 3}}, 38 {"dim2", map[string]int64{"tag1b": 1, "tag2b": 2, "All": 3}}, 39 } 40 for _, c := range cases { 41 counts := CounterForDimension(mtm, c.dim).Counts() 42 if !reflect.DeepEqual(c.want, counts) { 43 t.Errorf("mtm.CounterFor(%q).Counts()=%v, want %v", c.dim, counts, c.want) 44 } 45 } 46 }