aboutsummaryrefslogtreecommitdiff
path: root/src/time/time_test.go
diff options
context:
space:
mode:
authorCarl Johnson <me@carlmjohnson.net>2022-03-26 02:10:29 +0000
committerEmmanuel Odeke <emmanuel@orijtech.com>2022-03-27 20:23:17 +0000
commit0bbd05b8262624bb8e8aea43fa76934fbff8fc81 (patch)
tree7cd0e5003612b17ef613d42957e4d5648425d05d /src/time/time_test.go
parent737837c9d45946e6a43f4de5fe3309b9e06ba83f (diff)
downloadgo-0bbd05b8262624bb8e8aea43fa76934fbff8fc81.tar.gz
go-0bbd05b8262624bb8e8aea43fa76934fbff8fc81.zip
time: add Duration.Abs
Fixes #51414 Change-Id: Ia3b1674f2a902c8396fe029397536643a3bc1784 GitHub-Last-Rev: 67159648af09e7a8ac2825a1fe71b2de3fb9d748 GitHub-Pull-Request: golang/go#51739 Reviewed-on: https://go-review.googlesource.com/c/go/+/393515 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Diffstat (limited to 'src/time/time_test.go')
-rw-r--r--src/time/time_test.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/time/time_test.go b/src/time/time_test.go
index ea13ffe3c9..1701401ab4 100644
--- a/src/time/time_test.go
+++ b/src/time/time_test.go
@@ -1240,6 +1240,30 @@ func TestDurationRound(t *testing.T) {
}
}
+var durationAbsTests = []struct {
+ d Duration
+ want Duration
+}{
+ {0, 0},
+ {1, 1},
+ {-1, 1},
+ {1 * Minute, 1 * Minute},
+ {-1 * Minute, 1 * Minute},
+ {minDuration, maxDuration},
+ {minDuration + 1, maxDuration},
+ {minDuration + 2, maxDuration - 1},
+ {maxDuration, maxDuration},
+ {maxDuration - 1, maxDuration - 1},
+}
+
+func TestDurationAbs(t *testing.T) {
+ for _, tt := range durationAbsTests {
+ if got := tt.d.Abs(); got != tt.want {
+ t.Errorf("Duration(%s).Abs() = %s; want: %s", tt.d, got, tt.want)
+ }
+ }
+}
+
var defaultLocTests = []struct {
name string
f func(t1, t2 Time) bool