From: Shawn Smith Date: Thu, 2 Jan 2014 10:01:18 +0000 (+1100) Subject: time: add tests for Duration.Nanoseconds, Duration.Minutes, and Duration.Hours X-Git-Tag: go1.3beta1~1073 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b38da05ab15e9414ffcbf7f5ea3cf390e16e719c;p=gostls13.git time: add tests for Duration.Nanoseconds, Duration.Minutes, and Duration.Hours R=golang-codereviews, rsc, dave CC=golang-codereviews https://golang.org/cl/42440043 --- diff --git a/src/pkg/time/time_test.go b/src/pkg/time/time_test.go index 334c4b0cf7..821b7f27ff 100644 --- a/src/pkg/time/time_test.go +++ b/src/pkg/time/time_test.go @@ -1461,6 +1461,60 @@ func TestSub(t *testing.T) { } } +var nsDurationTests = []struct { + d Duration + want int64 +}{ + {Duration(-1000), -1000}, + {Duration(-1), -1}, + {Duration(1), 1}, + {Duration(1000), 1000}, +} + +func TestDurationNanoseconds(t *testing.T) { + for _, tt := range nsDurationTests { + if got := tt.d.Nanoseconds(); got != tt.want { + t.Errorf("d.Nanoseconds() = %d; want: %d", got, tt.want) + } + } +} + +var minDurationTests = []struct { + d Duration + want float64 +}{ + {Duration(-60000000000), -1}, + {Duration(-1), -1 / 60e9}, + {Duration(1), 1 / 60e9}, + {Duration(60000000000), 1}, +} + +func TestDurationMinutes(t *testing.T) { + for _, tt := range minDurationTests { + if got := tt.d.Minutes(); got != tt.want { + t.Errorf("d.Minutes() = %d; want: %d", got, tt.want) + } + } +} + +var hourDurationTests = []struct { + d Duration + want float64 +}{ + {Duration(-3600000000000), -1}, + {Duration(-1), -1 / 3600e9}, + {Duration(1), 1 / 3600e9}, + {Duration(3600000000000), 1}, +} + +func TestDurationHours(t *testing.T) { + for _, tt := range hourDurationTests { + if got := tt.d.Hours(); got != tt.want { + t.Errorf("d.Hours() = %d; want: %d", got, tt.want) + } + } +} + func BenchmarkNow(b *testing.B) { for i := 0; i < b.N; i++ { t = Now()