]> Cypherpunks repositories - gostls13.git/commitdiff
time: add tests for Duration.Nanoseconds, Duration.Minutes, and Duration.Hours
authorShawn Smith <shawn.p.smith@gmail.com>
Thu, 2 Jan 2014 10:01:18 +0000 (21:01 +1100)
committerDave Cheney <dave@cheney.net>
Thu, 2 Jan 2014 10:01:18 +0000 (21:01 +1100)
R=golang-codereviews, rsc, dave
CC=golang-codereviews
https://golang.org/cl/42440043

src/pkg/time/time_test.go

index 334c4b0cf737107a2db5e3670f5ff482a1567d73..821b7f27ff9fc136ade99094ce18b7395f75edb1 100644 (file)
@@ -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()