mirror of
https://github.com/jefferyjob/go-easy-utils.git
synced 2025-10-01 21:32:14 +08:00
49 lines
774 B
Go
49 lines
774 B
Go
package mathUtil
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
)
|
|
|
|
func TestRoundFloat32(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
input float32
|
|
expected int
|
|
}{
|
|
{
|
|
name: "负数四舍五入",
|
|
input: -12.4,
|
|
expected: -12,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
res := Round(tc.input)
|
|
assert.Equal(t, tc.expected, res)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestRoundFloat64(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
input float64
|
|
expected int
|
|
}{
|
|
{
|
|
name: "正数四舍五入",
|
|
input: 12.5,
|
|
expected: 13,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
res := Round(tc.input)
|
|
assert.Equal(t, tc.expected, res)
|
|
})
|
|
}
|
|
}
|