refactor: replace min/max helpers with built-in min/max
We can use the built-in `min` and `max` functions since Go 1.21. Reference: https://go.dev/ref/spec#Min_and_max Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
7 files changed
+6
-116
No files matched your search
@@ -1,26 +0,0 @@
|
||||
package lntypes
|
||||
|
||||
import "golang.org/x/exp/constraints"
|
||||
|
||||
// Number defines a type constraint for numbers.
|
||||
type Number interface {
|
||||
constraints.Integer | constraints.Float
|
||||
}
|
||||
|
||||
// Max returns the greater of the two inputs.
|
||||
func Max[N Number](op1 N, op2 N) N {
|
||||
if op1 > op2 {
|
||||
return op1
|
||||
}
|
||||
|
||||
return op2
|
||||
}
|
||||
|
||||
// Min returns the lesser of the two inputs.
|
||||
func Min[N Number](op1 N, op2 N) N {
|
||||
if op1 < op2 {
|
||||
return op1
|
||||
}
|
||||
|
||||
return op2
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package lntypes
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestMin tests getting correct minimal numbers.
|
||||
func TestMin(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
require.Equal(t, 1, Min(1, 1))
|
||||
require.Equal(t, 1, Min(1, 2))
|
||||
require.Equal(t, 1.5, Min(1.5, 2.5))
|
||||
}
|
||||
|
||||
// TestMax tests getting correct maximal numbers.
|
||||
func TestMax(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
require.Equal(t, 1, Max(1, 1))
|
||||
require.Equal(t, 2, Max(1, 2))
|
||||
require.Equal(t, 2.5, Max(1.5, 2.5))
|
||||
}
|
||||
Reference in new issue
Block a user