From 5399c2290e51608a38c7227b280ae46b89544326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=87=95=E5=BD=92=E6=9D=A5?= Date: Wed, 19 Oct 2022 17:21:53 +0800 Subject: [PATCH] feat: support type alias for Number constraint (#60) --- lancetconstraints/constraints.go | 2 +- mathutil/mathutil_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lancetconstraints/constraints.go b/lancetconstraints/constraints.go index f501099..87e50be 100644 --- a/lancetconstraints/constraints.go +++ b/lancetconstraints/constraints.go @@ -14,5 +14,5 @@ type Comparator interface { // Number contains all types of number and uintptr, used for generics constraint type Number interface { - int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | uintptr | float32 | float64 + ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64 } diff --git a/mathutil/mathutil_test.go b/mathutil/mathutil_test.go index 5e5da0d..c11f23f 100644 --- a/mathutil/mathutil_test.go +++ b/mathutil/mathutil_test.go @@ -87,6 +87,9 @@ func TestMax(t *testing.T) { assert.Equal(Max(0, 0), 0) assert.Equal(Max(1, 2, 3), 3) assert.Equal(Max(1.2, 1.4, 1.1, 1.4), 1.4) + + type Integer int + assert.Equal(Max(Integer(1), Integer(0)), Integer(1)) } func TestMaxBy(t *testing.T) {