From f981c23f60f2f439a81be6839c361b5c46b98fcc Mon Sep 17 00:00:00 2001 From: failfmi Date: Thu, 5 Oct 2023 18:07:38 +0300 Subject: [PATCH] feat(math): minU32 --- math.go | 7 +++++++ math_test.go | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/math.go b/math.go index d308546..735f314 100644 --- a/math.go +++ b/math.go @@ -52,6 +52,13 @@ func MaxU128() U128 { } } +func Min32(a, b U32) U32 { + if a < b { + return a + } + return b +} + func Min64(a, b U64) U64 { if a < b { return a diff --git a/math_test.go b/math_test.go index d9a5c1c..5e3bdf6 100644 --- a/math_test.go +++ b/math_test.go @@ -49,6 +49,26 @@ func Test_Max128(t *testing.T) { } } +func Test_Min32(t *testing.T) { + testExamples := []struct { + label string + a U32 + b U32 + expect U32 + }{ + {"Min(1, 2)", 1, 2, 1}, + {"Min(1, MaxU32)", 1, math.MaxUint32, 1}, + {"Min(MaxU32, MaxU32)", math.MaxUint32, math.MaxUint32, math.MaxUint32}, + } + + for _, testExample := range testExamples { + t.Run(testExample.label, func(t *testing.T) { + result := Min32(testExample.a, testExample.b) + assert.Equal(t, testExample.expect, result) + }) + } +} + func Test_Min64(t *testing.T) { testExamples := []struct { label string