From bd32a3e7394d34ef8d8f3a54dc7c368e9d15ac9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arda=20G=C3=BC=C3=A7l=C3=BC?= Date: Tue, 12 Nov 2019 21:25:32 +0300 Subject: [PATCH] cmd/benchcmp: add unit test for formatNs function Test function is added for formatNs function in the benchcmp package. Change-Id: I9a1050be9fba3b5e217741d3faadbf5d913d1d4d Reviewed-on: https://go-review.googlesource.com/c/tools/+/206857 Run-TryBot: Ian Cottrell Reviewed-by: Ian Cottrell --- cmd/benchcmp/benchcmp_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cmd/benchcmp/benchcmp_test.go b/cmd/benchcmp/benchcmp_test.go index 22260795e6..b79bfaa86e 100644 --- a/cmd/benchcmp/benchcmp_test.go +++ b/cmd/benchcmp/benchcmp_test.go @@ -57,3 +57,27 @@ func TestSelectBest(t *testing.T) { t.Errorf("filtered bench set incorrectly, want %v have %v", want, have) } } + +func TestFormatNs(t *testing.T) { + tests := []struct { + input float64 + expected string + }{ + {input: 0, expected: "0.00"}, + {input: 0.2, expected: "0.20"}, + {input: 2, expected: "2.00"}, + {input: 2.2, expected: "2.20"}, + {input: 4, expected: "4.00"}, + {input: 16, expected: "16.0"}, + {input: 16.08, expected: "16.1"}, + {input: 128, expected: "128"}, + {input: 256.2, expected: "256"}, + } + + for _, tt := range tests { + actual := formatNs(tt.input) + if actual != tt.expected { + t.Fatalf("%f. got %q, want %q", tt.input, actual, tt.expected) + } + } +}