Feature/cover unit test (#81)

This commit is contained in:
libin
2024-07-31 19:51:01 +08:00
committed by GitHub
parent 0990bbce4d
commit a59af60d9a
60 changed files with 2571 additions and 2606 deletions

View File

@@ -1,23 +1,48 @@
package mathUtil
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestCeilFloat32(t *testing.T) {
var input float32 = -12.4
var expected int = -12
res := Ceil(input)
if res != expected {
t.Errorf("ceil error")
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 := Ceil(tc.input)
assert.Equal(t, tc.expected, res)
})
}
}
func TestCeilFloat64(t *testing.T) {
var input float64 = 12.4
var expected int = 13
res := Ceil(input)
if res != expected {
t.Errorf("ceil error")
testCases := []struct {
name string
input float64
expected int
}{
{
name: "正浮点数取整",
input: 12.4,
expected: 13,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
res := Ceil(tc.input)
assert.Equal(t, tc.expected, res)
})
}
}