-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
75 lines (69 loc) · 4.35 KB
/
utils_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
package easykafka
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestUnorderedStringsEqual(t *testing.T) {
assert := assert.New(t)
assert.True(unorderedStringsEqual([]string{"a", "b", "c"}, []string{"c", "b", "a"}))
assert.False(unorderedStringsEqual([]string{"a", "b", "c"}, []string{"c", "b", "a", "d"}))
assert.False(unorderedStringsEqual([]string{"a", "b", "c"}, []string{"c", "b"}))
assert.False(unorderedStringsEqual([]string{"a", "b", "c"}, []string{"c", "b", "a", "d"}))
assert.False(unorderedStringsEqual([]string{"a", "b", "c"}, []string{"c", "b", "a", "d"}))
assert.False(unorderedStringsEqual([]string{"a", "b", "c"}, []string{"c", "b", "a", "d"}))
assert.False(unorderedStringsEqual([]string{"a", "b", "c"}, []string{"c", "b", "a", "d"}))
assert.False(unorderedStringsEqual([]string{"a", "b", "c"}, []string{"c", "b", "a", "d"}))
assert.False(unorderedStringsEqual([]string{"a", "b", "c"}, []string{"c", "b", "a", "d"}))
}
// unit test easykafka.findMissing[T comparable](a, b []T) []T
func TestFindMissing(t *testing.T) {
assert := assert.New(t)
assert.Equal([]string{"a", "b"}, findMissing([]string{"a", "b", "c"}, []string{"c"}))
assert.Equal([]string{"a", "b", "c"}, findMissing([]string{"a", "b", "c"}, []string{}))
assert.Equal([]string{"a", "b", "c"}, findMissing([]string{"a", "b", "c"}, []string{"d"}))
assert.Equal([]string{"a", "b", "c"}, findMissing([]string{"a", "b", "c"}, []string{"d", "e"}))
assert.Equal([]string{"a", "b", "c"}, findMissing([]string{"a", "b", "c"}, []string{"d", "e", "f"}))
assert.Equal([]string{"a", "b", "c"}, findMissing([]string{"a", "b", "c"}, []string{"d", "e", "f", "g"}))
assert.Equal([]string{"a", "b", "c"}, findMissing([]string{"a", "b", "c"}, []string{"d", "e", "f", "g", "h"}))
assert.Equal([]string{"a", "b", "c"}, findMissing([]string{"a", "b", "c"}, []string{"d", "e", "f", "g", "h", "i"}))
assert.Equal([]string{"a", "b", "c"}, findMissing([]string{"a", "b", "c"}, []string{"d", "e", "f", "g", "h", "i", "j"}))
assert.Equal([]string{"a", "b", "c"}, findMissing([]string{"a", "b", "c"}, []string{"d", "e", "f", "g", "h", "i", "j", "k"}))
assert.Equal([]string{"a"}, findMissing([]string{"a"}, []string{"c", "d", "e"}))
assert.Equal([]string{"a"}, findMissing([]string{"a", "b"}, []string{"b", "c", "d", "e"}))
assert.Equal([]string{"a", "b"}, findMissing([]string{"a", "b", "c"}, []string{"c", "d", "e"}))
}
// unit test easykafka.convertSlice[T any](slice []*T) []T
func TestConvertSlice(t *testing.T) {
assert := assert.New(t)
assert.Equal([]string{"a", "b", "c"}, convertSlice([]*string{strP("a"), strP("b"), strP("c")}))
assert.Equal([]int{1, 2, 3}, convertSlice([]*int{intP(1), intP(2), intP(3)}))
assert.Equal([]string{"a", "b", "c"}, convertSlice([]*string{strP("a"), strP("b"), strP("c")}))
}
// unit test easykafka.appendIfMissing[T comparable](slice []T, elem T) []T
func TestAppendIfMissing(t *testing.T) {
assert := assert.New(t)
assert.Equal([]string{"a", "b", "c"}, appendIfMissing([]string{"a", "b"}, "c"))
assert.Equal([]string{"a", "b", "c"}, appendIfMissing([]string{"a", "b", "c"}, "c"))
assert.Equal([]string{"a", "b", "c"}, appendIfMissing([]string{"a", "b", "c"}, "c"))
assert.Equal([]string{"a", "b", "c"}, appendIfMissing([]string{"a", "b", "c"}, "c"))
assert.Equal([]string{"a", "b", "c"}, appendIfMissing([]string{"a", "b", "c"}, "c"))
assert.Equal([]string{"a", "b", "c"}, appendIfMissing([]string{"a", "b", "c"}, "c"))
assert.Equal([]string{"a", "b", "c"}, appendIfMissing([]string{"a", "b", "c"}, "c"))
assert.Equal([]string{"a", "b", "c"}, appendIfMissing([]string{"a", "b", "c"}, "c"))
assert.Equal([]string{"a", "b", "c"}, appendIfMissing([]string{"a", "b", "c"}, "c"))
}
// unit test easykafka.contains[T comparable](slice []T, elem T) bool
func TestContains(t *testing.T) {
assert := assert.New(t)
assert.True(contains([]string{"a", "b", "c"}, "a"))
assert.True(contains([]string{"a", "b", "c"}, "b"))
assert.True(contains([]string{"a", "b", "c"}, "c"))
assert.False(contains([]string{"a", "b", "c"}, "d"))
assert.False(contains([]string{"a", "b", "c"}, "e"))
assert.False(contains([]string{"a", "b", "c"}, "f"))
assert.False(contains([]string{"a", "b", "c"}, "g"))
assert.False(contains([]string{"a", "b", "c"}, "h"))
assert.False(contains([]string{"a", "b", "c"}, "i"))
assert.False(contains([]string{"a", "b", "c"}, "j"))
assert.False(contains([]string{"a", "b", "c"}, "k"))
}