github.com/loov/hrtime@v1.0.3/histogram_bounds_test.go (about) 1 package hrtime 2 3 import ( 4 "testing" 5 ) 6 7 func TestTruncate(t *testing.T) { 8 tests := []struct { 9 in float64 10 trunc int 11 exp float64 12 }{ 13 {0, 1, 0}, 14 {0, 2, 0}, 15 {0, 3, 0}, 16 17 {10, 1, 10}, 18 {10, 2, 10}, 19 {10, 3, 10}, 20 21 {1234, 1, 1000}, 22 {1234, 2, 1200}, 23 {1234, 3, 1230}, 24 } 25 26 for _, test := range tests { 27 got := truncate(test.in, test.trunc) 28 if got != test.exp { 29 t.Errorf("%f %d => %f expected %f", test.in, test.trunc, got, test.exp) 30 } 31 } 32 }