github.com/apernet/quic-go@v0.43.1-0.20240515053213-5e9e635fd9f0/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 time", func() {
    12  		a := time.Now()
    13  		b := a.Add(time.Second)
    14  		Expect(MaxTime(a, b)).To(Equal(b))
    15  		Expect(MaxTime(b, a)).To(Equal(b))
    16  	})
    17  
    18  	It("returns the minimum duration", func() {
    19  		a := time.Now()
    20  		b := a.Add(time.Second)
    21  		Expect(MinTime(a, b)).To(Equal(a))
    22  		Expect(MinTime(b, a)).To(Equal(a))
    23  	})
    24  
    25  	It("returns the minium non-zero duration", func() {
    26  		var a time.Duration
    27  		b := time.Second
    28  		Expect(MinNonZeroDuration(0, 0)).To(BeZero())
    29  		Expect(MinNonZeroDuration(a, b)).To(Equal(b))
    30  		Expect(MinNonZeroDuration(b, a)).To(Equal(b))
    31  		Expect(MinNonZeroDuration(time.Minute, time.Hour)).To(Equal(time.Minute))
    32  	})
    33  })