github.com/MerlinKodo/quic-go@v0.39.2/internal/utils/minmax_test.go (about) 1 package utils 2 3 import ( 4 "time" 5 6 . "github.com/onsi/ginkgo/v2" 7 . "github.com/onsi/gomega" 8 ) 9 10 var _ = Describe("Min / Max", func() { 11 It("returns the maximum", func() { 12 Expect(Max(5, 7)).To(Equal(7)) 13 Expect(Max(5.5, 5.7)).To(Equal(5.7)) 14 }) 15 16 It("returns the minimum", func() { 17 Expect(Min(5, 7)).To(Equal(5)) 18 Expect(Min(5.5, 5.7)).To(Equal(5.5)) 19 }) 20 21 It("returns the maximum time", func() { 22 a := time.Now() 23 b := a.Add(time.Second) 24 Expect(MaxTime(a, b)).To(Equal(b)) 25 Expect(MaxTime(b, a)).To(Equal(b)) 26 }) 27 28 It("returns the minimum duration", func() { 29 a := time.Now() 30 b := a.Add(time.Second) 31 Expect(MinTime(a, b)).To(Equal(a)) 32 Expect(MinTime(b, a)).To(Equal(a)) 33 }) 34 35 It("returns the minium non-zero duration", func() { 36 var a time.Duration 37 b := time.Second 38 Expect(MinNonZeroDuration(0, 0)).To(BeZero()) 39 Expect(MinNonZeroDuration(a, b)).To(Equal(b)) 40 Expect(MinNonZeroDuration(b, a)).To(Equal(b)) 41 Expect(MinNonZeroDuration(time.Minute, time.Hour)).To(Equal(time.Minute)) 42 }) 43 44 It("returns the minium non-zero time", func() { 45 a := time.Time{} 46 b := time.Now() 47 Expect(MinNonZeroTime(time.Time{}, time.Time{})).To(Equal(time.Time{})) 48 Expect(MinNonZeroTime(a, b)).To(Equal(b)) 49 Expect(MinNonZeroTime(b, a)).To(Equal(b)) 50 Expect(MinNonZeroTime(b, b.Add(time.Second))).To(Equal(b)) 51 Expect(MinNonZeroTime(b.Add(time.Second), b)).To(Equal(b)) 52 }) 53 54 It("returns the abs time", func() { 55 Expect(AbsDuration(time.Microsecond)).To(Equal(time.Microsecond)) 56 Expect(AbsDuration(-time.Microsecond)).To(Equal(time.Microsecond)) 57 }) 58 })