version 1.0.1 (#8)

* 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>
This commit is contained in:
jeffery
2023-03-27 16:52:08 +08:00
committed by GitHub
parent 005437a82b
commit cea73b8e18
14 changed files with 220 additions and 49 deletions

View File

@@ -5,41 +5,127 @@ import (
)
func TestStrToInt(t *testing.T) {
expected := 123
result := StrToInt("123")
if result != expected {
t.Errorf("StrToInt test failed, expected %d but got %d", expected, result)
// Test cases
testCases := []struct {
input string
expected int
}{
{"0", 0},
{"1", 1},
{"-1", -1},
{"invalid", 0},
}
// Test loop
for _, tc := range testCases {
// Call the function
got := StrToInt(tc.input)
// Check the result
if got != tc.expected {
t.Errorf("Unexpected result: StrToInt(%v) = %v, expected %v", tc.input, got, tc.expected)
}
}
}
func TestStrToInt8(t *testing.T) {
expected := int8(123)
result := StrToInt8("123")
if result != expected {
t.Errorf("StrToInt8 test failed, expected %d but got %d", expected, result)
// Test cases
testCases := []struct {
input string
expected int8
}{
{"0", 0},
{"1", 1},
{"-1", -1},
{"invalid", 0},
}
// Test loop
for _, tc := range testCases {
// Call the function
got := StrToInt8(tc.input)
// Check the result
if got != tc.expected {
t.Errorf("Unexpected result: StrToInt8(%v) = %v, expected %v", tc.input, got, tc.expected)
}
}
}
func TestStrToInt16(t *testing.T) {
expected := int16(123)
result := StrToInt16("123")
if result != expected {
t.Errorf("StrToInt16 test failed, expected %d but got %d", expected, result)
// Test cases
testCases := []struct {
input string
expected int16
}{
{"0", 0},
{"1", 1},
{"-1", -1},
{"invalid", 0},
}
// Test loop
for _, tc := range testCases {
// Call the function
got := StrToInt16(tc.input)
// Check the result
if got != tc.expected {
t.Errorf("Unexpected result: StrToInt16(%v) = %v, expected %v", tc.input, got, tc.expected)
}
}
}
func TestStrToInt32(t *testing.T) {
expected := int32(123)
result := StrToInt32("123")
if result != expected {
t.Errorf("StrToInt32 test failed, expected %d but got %d", expected, result)
// Test cases
testCases := []struct {
input string
expected int32
}{
{"0", 0},
{"1", 1},
{"-1", -1},
{"invalid", 0},
}
// Test loop
for _, tc := range testCases {
// Call the function
got := StrToInt32(tc.input)
// Check the result
if got != tc.expected {
t.Errorf("Unexpected result: StrToInt32(%v) = %v, expected %v", tc.input, got, tc.expected)
}
}
}
func TestStrToInt64(t *testing.T) {
expected := int64(123)
result := StrToInt64("123")
if result != expected {
t.Errorf("StrToInt64 test failed, expected %d but got %d", expected, result)
// Test cases
testCases := []struct {
input string
expected int64
}{
{"0", 0},
{"1", 1},
{"-1", -1},
{"9223372036854775807", 9223372036854775807},
{"-9223372036854775808", -9223372036854775808},
{"2147483647", 2147483647},
{"-2147483648", -2147483648},
{"invalid", 0},
{"9223372036854775808", 0},
{"-9223372036854775809", 0},
}
// Test loop
for _, tc := range testCases {
// Call the function
got := StrToInt64(tc.input)
// Check the result
if got != tc.expected {
t.Errorf("Unexpected result: StrToInt64(%v) = %v, expected %v", tc.input, got, tc.expected)
}
}
}