Rounding the latency in certain scenarios (#1005)

* Rounding the latency in certain scenarios

* run gofmt
This commit is contained in:
Carter
2016-08-08 12:14:53 -04:00
committed by Matt Holt
parent de7bf4f241
commit 4d76ccb1c4
2 changed files with 55 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import (
"os"
"strings"
"testing"
"time"
)
func TestNewReplacer(t *testing.T) {
@ -140,3 +141,23 @@ func TestSet(t *testing.T) {
t.Error("Expected variable replacement failed")
}
}
func TestRound(t *testing.T) {
var tests = map[time.Duration]time.Duration{
// 599.935µs -> 560µs
559935 * time.Nanosecond: 560 * time.Microsecond,
// 1.55ms -> 2ms
1550 * time.Microsecond: 2 * time.Millisecond,
// 1.5555s -> 1.556s
1555500 * time.Microsecond: 1556 * time.Millisecond,
// 1m2.0035s -> 1m2.004s
62003500 * time.Microsecond: 62004 * time.Millisecond,
}
for dur, expected := range tests {
rounded := roundDuration(dur)
if rounded != expected {
t.Errorf("Expected %v, Got %v", expected, rounded)
}
}
}