mirror of
https://github.com/jefferyjob/go-easy-utils.git
synced 2025-10-05 15:06:50 +08:00

* anyutil test * fix:delete debug * unit test utils * unit test * strUtil unit test * fix;4, 6, 9, 11 Month determination error * fix:The last digit of ID number is x, and the weighted sum comparison condition is wrong * test * test * docs * fix:docs * idcard test * test unit * no message * docs update * 单元测试覆盖 --------- Co-authored-by: libin <libinjob@163.com> Co-authored-by: 李斌 <libin1-hj@huafang.com>
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package anyUtil
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestToBool(t *testing.T) {
|
|
iPtr := 90
|
|
|
|
var tests = []struct {
|
|
input interface{}
|
|
want bool
|
|
}{
|
|
{true, true},
|
|
{false, false},
|
|
{int(-1), true},
|
|
{int(1), true},
|
|
{int(0), false},
|
|
{int8(1), true},
|
|
{int8(0), false},
|
|
{int16(1), true},
|
|
{int16(0), false},
|
|
{int32(1), true},
|
|
{int32(0), false},
|
|
{int64(1), true},
|
|
{int64(0), false},
|
|
{uint(1), true},
|
|
{uint(0), false},
|
|
{uint8(1), true},
|
|
{uint8(0), false},
|
|
{uint16(1), true},
|
|
{uint16(0), false},
|
|
{uint32(1), true},
|
|
{uint32(0), false},
|
|
{uint64(1), true},
|
|
{uint64(0), false},
|
|
{float32(1.0), true},
|
|
{float32(0.0), false},
|
|
{float64(1.0), true},
|
|
{float64(0.0), false},
|
|
{"abc", true},
|
|
{"true", true},
|
|
{"false", false},
|
|
{"", false},
|
|
{nil, false},
|
|
{complex64(1 + 1i), true},
|
|
{complex64(0 + 0i), false},
|
|
{complex128(1 + 1i), true},
|
|
{complex128(0 + 0i), false},
|
|
{(*int)(nil), false},
|
|
{&iPtr, true},
|
|
{[]int{}, false},
|
|
}
|
|
for _, test := range tests {
|
|
if got := AnyToBool(test.input); got != test.want {
|
|
t.Errorf("toBool(%v) = %v; want %v", test.input, got, test.want)
|
|
}
|
|
}
|
|
}
|