forked from quic-go/quic-go
merge protocol.MinMax into utils.MinMax
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package utils
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
)
|
||||
|
||||
// Max returns the maximum of two Ints
|
||||
func Max(a, b int) int {
|
||||
@@ -81,3 +85,19 @@ func AbsDuration(d time.Duration) time.Duration {
|
||||
}
|
||||
return -d
|
||||
}
|
||||
|
||||
// MaxPacketNumber returns the max packet number
|
||||
func MaxPacketNumber(a, b protocol.PacketNumber) protocol.PacketNumber {
|
||||
if a > b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// MinPacketNumber returns the min packet number
|
||||
func MinPacketNumber(a, b protocol.PacketNumber) protocol.PacketNumber {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package utils
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
@@ -38,6 +39,11 @@ var _ = Describe("Min / Max", func() {
|
||||
Expect(MinDuration(time.Microsecond, time.Nanosecond)).To(Equal(time.Nanosecond))
|
||||
Expect(MinDuration(time.Nanosecond, time.Microsecond)).To(Equal(time.Nanosecond))
|
||||
})
|
||||
|
||||
It("returns packet number max", func() {
|
||||
Expect(MaxPacketNumber(1, 2)).To(Equal(protocol.PacketNumber(2)))
|
||||
Expect(MaxPacketNumber(2, 1)).To(Equal(protocol.PacketNumber(2)))
|
||||
})
|
||||
})
|
||||
|
||||
Context("Min", func() {
|
||||
@@ -55,6 +61,11 @@ var _ = Describe("Min / Max", func() {
|
||||
Expect(MinInt64(7, 5)).To(Equal(int64(5)))
|
||||
Expect(MinInt64(5, 7)).To(Equal(int64(5)))
|
||||
})
|
||||
|
||||
It("returns packet number min", func() {
|
||||
Expect(MinPacketNumber(1, 2)).To(Equal(protocol.PacketNumber(1)))
|
||||
Expect(MinPacketNumber(2, 1)).To(Equal(protocol.PacketNumber(1)))
|
||||
})
|
||||
})
|
||||
|
||||
It("returns the abs time", func() {
|
||||
|
||||
Reference in New Issue
Block a user