Repository navigation
Expand file tree
/
Copy pathequal_test.go
More file actions
100 lines (92 loc) · 2.08 KB
/
Copy pathequal_test.go
File metadata and controls
100 lines (92 loc) · 2.08 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package maps_test
import (
"testing"
"github.com/dosadczuk/go-maps"
"github.com/google/go-cmp/cmp"
)
func TestEqual(t *testing.T) {
tt := map[string]struct {
// input
values1 map[int]int
values2 map[int]int
// assert
want bool
}{
"empty maps": {
values1: nil, // zero value
values2: nil, // zero value
want: true,
},
"maps with different size": {
values1: map[int]int{1: 2},
values2: map[int]int{1: 2, 2: 3},
want: false,
},
"maps with the same keys but different values": {
values1: map[int]int{1: 2},
values2: map[int]int{1: 3},
want: false,
},
"maps with the same values but different keys": {
values1: map[int]int{1: 2},
values2: map[int]int{2: 2},
want: false,
},
"maps with the same key-value pairs": {
values1: map[int]int{1: 2, 2: 3},
values2: map[int]int{1: 2, 2: 3},
want: true,
},
}
for name, tc := range tt {
t.Run(name, func(t *testing.T) {
have := maps.Equal(tc.values1, tc.values2)
if !cmp.Equal(tc.want, have) {
t.Error(cmp.Diff(tc.want, have))
}
})
}
}
func TestEqualFunc(t *testing.T) {
tt := map[string]struct {
// input
values1 map[int]int
values2 map[int]int
// assert
want bool
}{
"empty maps": {
values1: nil, // zero value
values2: nil, // zero value
want: true,
},
"maps with different size": {
values1: map[int]int{1: 2},
values2: map[int]int{1: 2, 2: 3},
want: false,
},
"maps with the same keys but different values": {
values1: map[int]int{1: 2},
values2: map[int]int{1: 3},
want: false,
},
"maps with the same values but different keys": {
values1: map[int]int{1: 2},
values2: map[int]int{2: 2},
want: false,
},
"maps with the same key-value pairs": {
values1: map[int]int{1: 2, 2: 3},
values2: map[int]int{1: 2, 2: 3},
want: true,
},
}
for name, tc := range tt {
t.Run(name, func(t *testing.T) {
have := maps.EqualFunc(tc.values1, tc.values2, func(v1, v2 int) bool { return v1 == v2 })
if !cmp.Equal(tc.want, have) {
t.Error(cmp.Diff(tc.want, have))
}
})
}
}