mirror of
https://github.com/jefferyjob/go-easy-utils.git
synced 2025-10-05 06:56:50 +08:00
Feature/cover unit test (#81)
This commit is contained in:
@@ -1,21 +1,48 @@
|
||||
package mathUtil
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRoundFloat32(t *testing.T) {
|
||||
var input float32 = -12.4
|
||||
var expected int = -12
|
||||
res := Round(input)
|
||||
if res != expected {
|
||||
t.Errorf("Round error %d", res)
|
||||
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) {
|
||||
var input float64 = 12.5
|
||||
var expected int = 13
|
||||
res := Round(input)
|
||||
if res != expected {
|
||||
t.Errorf("Round error %d", res)
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user