-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguti_test.go
78 lines (72 loc) · 1.53 KB
/
guti_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package guti
import "testing"
func TestGetTypeName(t *testing.T) {
type Person struct {
Name string
Age int
}
testCases := []struct {
input interface{}
expected string
}{
{1, "int"},
{3.14, "float64"},
{"hello", "string"},
{true, "bool"},
{&Person{Name: "Alice", Age: 30}, "*Person"},
}
for _, tc := range testCases {
actual := GetTypeName(tc.input)
if actual != tc.expected {
t.Errorf("GetTypeName(%v) = %s; expected %s", tc.input, actual, tc.expected)
}
}
}
func TestCompareStructs(t *testing.T) {
testCases := []struct {
name string
s1 interface{}
s2 interface{}
expected bool
}{
{
"equal maps",
map[string]interface{}{"a": 1, "b": "two", "c": true},
map[string]interface{}{"a": 1, "b": "two", "c": true},
true,
},
{
"Unequal maps",
map[string]interface{}{"a": 1, "b": "two", "c": true},
map[string]interface{}{"a": 1, "b": "two", "c": false},
false,
},
{
"Equal slices",
[]interface{}{1, "two", true},
[]interface{}{1, "two", true},
true,
},
{
"Unequal slices",
[]interface{}{1, "two", true},
[]interface{}{1, "two", false},
false,
},
{
"Different types",
map[string]interface{}{"a": 1, "b": "two", "c": true},
[]interface{}{1, "two", true},
false,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := CompareStructs(tc.s1, tc.s2)
if result != tc.expected {
t.Errorf("CompareStructs(%v, %v) = %v, expected %v",
tc.s1, tc.s2, result, tc.expected)
}
})
}
}