This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
AI 评测:单元测试 #3
Comments
Testcase2描述: 查询Nonce
Codeium |
Testcase3相关链接 https://github.com/kubebb/core/pull/15/files#r1205109415 |
@dayuy 你的首次AI单测记录 😆 |
Testcase4
package main
import (
"reflect"
"testing"
)
func TestRemoveDuplicateForStringSlice(t *testing.T) {
testCases := []struct {
name string
input []string
expected []string
}{
{
name: "no duplicates",
input: []string{"a", "b", "c"},
expected: []string{"a", "b", "c"},
},
{
name: "some duplicates",
input: []string{"a", "b", "a", "c", "b"},
expected: []string{"a", "b", "c"},
},
{
name: "all duplicates",
input: []string{"a", "a", "a", "a", ""},
expected: []string{"a"},
},
{
name: "empty slice",
input: []string{},
expected: []string{},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := RemoveDuplicateForStringSlice(tc.input)
if !reflect.DeepEqual(result, tc.expected) {
t.Errorf("expected %v, but got %v", tc.expected, result)
}
})
}
} |
Testcase5
func GetNestedString(obj map[string]interface{}, fields ...string) string {
val, _, _ := unstructured.NestedString(obj, fields...)
return val
}
import (
"testing"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
func TestGetNestedString(t *testing.T) {
obj := map[string]interface{}{
"foo": map[string]interface{}{
"bar": "baz",
},
}
// Test a valid nested string value.
expected := "baz"
actual := GetNestedString(obj, "foo", "bar")
if actual != expected {
t.Errorf("Expected %s but got %s", expected, actual)
}
// Test a missing nested field.
expected = ""
actual = GetNestedString(obj, "foo", "notfound")
if actual != expected {
t.Errorf("Expected %s but got %s", expected, actual)
}
// Test a non-string nested value.
obj["foo"].(map[string]interface{})["baz"] = 123
expected = ""
actual = GetNestedString(obj, "foo", "baz")
if actual != expected {
t.Errorf("Expected %s but got %s", expected, actual)
}
} |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
定义测试用例
描述: 测试类型转换
特点:
结果:
描述: 测试LocalWallet功能
特点:
结果(chatgpt)
查看详细单测代码
The text was updated successfully, but these errors were encountered: