diff options
| author | Shawn Smith <shawn.p.smith@gmail.com> | 2014-01-02 21:01:18 +1100 |
|---|---|---|
| committer | Dave Cheney <dave@cheney.net> | 2014-01-02 21:01:18 +1100 |
| commit | b38da05ab15e9414ffcbf7f5ea3cf390e16e719c (patch) | |
| tree | 91077320c4aa2604b4fd401fb0d2031913cf6f39 /src/pkg | |
| parent | 66730120fa2ff7d58d22a7e1cf9a1a299572a907 (diff) | |
| download | go-b38da05ab15e9414ffcbf7f5ea3cf390e16e719c.tar.xz | |
time: add tests for Duration.Nanoseconds, Duration.Minutes, and Duration.Hours
R=golang-codereviews, rsc, dave
CC=golang-codereviews
https://golang.org/cl/42440043
Diffstat (limited to 'src/pkg')
| -rw-r--r-- | src/pkg/time/time_test.go | 54 |
1 files changed, 54 insertions, 0 deletions
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() |
