forked from DiceDB/dice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slices.go
64 lines (53 loc) · 1.09 KB
/
slices.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
package testutils
// UnorderedEqual compares two slices of interfaces and returns true if they
// contain the same elements, regardless of order.
func UnorderedEqual(expected, actual interface{}) bool {
expectedSlice, ok := expected.([]interface{})
if !ok {
return false
}
actualSlice, ok := actual.([]interface{})
if !ok {
return false
}
if len(expectedSlice) != len(actualSlice) {
return false
}
for _, e := range expectedSlice {
found := false
for _, a := range actualSlice {
if e == a {
found = true
break
}
}
if !found {
return false
}
}
return true
}
// EqualByteSlice compares two byte slices and returns true if they are equal.
func EqualByteSlice(a, b []byte) bool {
if len(a) != len(b) {
return false
}
for i := 0; i < len(a); i++ {
if a[i] != b[i] {
return false
}
}
return true
}
// EqualInt64Slice compares two int64 slices and returns true if they are equal.
func EqualInt64Slice(a, b []int64) bool {
if len(a) != len(b) {
return false
}
for i := 0; i < len(a); i++ {
if a[i] != b[i] {
return false
}
}
return true
}