github.com/grailbio/bigslice@v0.0.0-20230519005545-30c4c12152ad/stats/stats_test.go (about) 1 // Copyright 2018 GRAIL, Inc. All rights reserved. 2 // Use of this source code is governed by the Apache 2.0 3 // license that can be found in the LICENSE file. 4 5 package stats 6 7 import "testing" 8 9 func TestStats(t *testing.T) { 10 coll := NewMap() 11 var ( 12 x = coll.Int("x") 13 _ = coll.Int("y") 14 ) 15 if got, want := x.Get(), int64(0); got != want { 16 t.Errorf("got %v, want %v", got, want) 17 } 18 x.Add(123) 19 x.Add(123) 20 if got, want := x.Get(), int64(123*2); got != want { 21 t.Errorf("got %v, want %v", got, want) 22 } 23 all := make(Values) 24 coll.AddAll(all) 25 coll.AddAll(all) 26 if got, want := len(all), 2; got != want { 27 t.Errorf("got %v, want %v", got, want) 28 } 29 if got, want := all["x"], int64(123*4); got != want { 30 t.Errorf("got %v, want %v", got, want) 31 } 32 if got, want := all["y"], int64(0); got != want { 33 t.Errorf("got %v, want %v", got, want) 34 } 35 }