mirror of
https://github.com/jefferyjob/go-easy-utils.git
synced 2025-10-05 15:06:50 +08:00
Feature/cover unit test (#81)
This commit is contained in:
@@ -1,21 +1,32 @@
|
||||
package mathUtil
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestMaxEmpty(t *testing.T) {
|
||||
s := []int{}
|
||||
var expected int = 0
|
||||
res := Max(s)
|
||||
if res != expected {
|
||||
t.Errorf("max error %d", res)
|
||||
}
|
||||
}
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMax(t *testing.T) {
|
||||
s := []int{3, 7, 1, 9, 3, 0, 2, 2}
|
||||
var expected int = 9
|
||||
res := Max(s)
|
||||
if res != expected {
|
||||
t.Errorf("max error %d", res)
|
||||
testCases := []struct {
|
||||
name string
|
||||
input []int
|
||||
expected int
|
||||
}{
|
||||
{
|
||||
name: "空切片",
|
||||
input: []int{},
|
||||
expected: 0,
|
||||
},
|
||||
{
|
||||
name: "普通切片",
|
||||
input: []int{3, 7, 1, 9, 3, 0, 2, 2},
|
||||
expected: 9,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
res := Max(tc.input)
|
||||
assert.Equal(t, tc.expected, res)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user