Skip to content

Commit

Permalink
feat(math): minU32
Browse files Browse the repository at this point in the history
  • Loading branch information
failfmi committed Oct 5, 2023
1 parent e6401e2 commit f981c23
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions math.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions math_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f981c23

Please sign in to comment.