1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
11 "golang.org/x/tools/benchmark/parse"
14 func TestSelectBest(t *testing.T) {
16 "Benchmark1": []*parse.Benchmark{
19 N: 10, NsPerOp: 100, Measured: parse.NsPerOp,
24 N: 10, NsPerOp: 50, Measured: parse.NsPerOp,
28 "Benchmark2": []*parse.Benchmark{
31 N: 10, NsPerOp: 60, Measured: parse.NsPerOp,
36 N: 10, NsPerOp: 500, Measured: parse.NsPerOp,
43 "Benchmark1": []*parse.Benchmark{
46 N: 10, NsPerOp: 50, Measured: parse.NsPerOp,
50 "Benchmark2": []*parse.Benchmark{
53 N: 10, NsPerOp: 60, Measured: parse.NsPerOp,
60 if !reflect.DeepEqual(want, have) {
61 t.Errorf("filtered bench set incorrectly, want %v have %v", want, have)
65 func TestFormatNs(t *testing.T) {
70 {input: 0, expected: "0.00"},
71 {input: 0.2, expected: "0.20"},
72 {input: 2, expected: "2.00"},
73 {input: 2.2, expected: "2.20"},
74 {input: 4, expected: "4.00"},
75 {input: 16, expected: "16.0"},
76 {input: 16.08, expected: "16.1"},
77 {input: 128, expected: "128"},
78 {input: 256.2, expected: "256"},
81 for _, tt := range tests {
82 actual := formatNs(tt.input)
83 if actual != tt.expected {
84 t.Fatalf("%f. got %q, want %q", tt.input, actual, tt.expected)