-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathutil_test.go
More file actions
117 lines (105 loc) · 3 KB
/
util_test.go
File metadata and controls
117 lines (105 loc) · 3 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package tldr
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Utility functions", func() {
Describe("SymmetricDifference", func() {
Context("With different slices", func() {
It("Should return indices where values differ", func() {
src := []int{1, 2, 3, 4, 5}
dst := []int{1, 0, 3, 0, 5}
result := SymmetricDifference(src, dst)
Expect(result).To(Equal([]int{1, 3}))
})
})
Context("With identical slices", func() {
It("Should return empty slice", func() {
src := []int{1, 2, 3}
dst := []int{1, 2, 3}
result := SymmetricDifference(src, dst)
Expect(result).To(BeEmpty())
})
})
Context("With completely different slices", func() {
It("Should return all indices", func() {
src := []int{1, 2, 3}
dst := []int{0, 0, 0}
result := SymmetricDifference(src, dst)
Expect(result).To(Equal([]int{0, 1, 2}))
})
})
Context("With empty slices", func() {
It("Should return empty slice", func() {
src := []int{}
dst := []int{}
result := SymmetricDifference(src, dst)
Expect(result).To(BeEmpty())
})
})
Context("With single element slices", func() {
It("Should handle single element comparison", func() {
src := []int{1}
dst := []int{0}
result := SymmetricDifference(src, dst)
Expect(result).To(Equal([]int{0}))
})
})
})
Describe("Intersection", func() {
Context("With some matching elements", func() {
It("Should return indices where values match", func() {
src := []int{1, 2, 3, 4, 5}
dst := []int{1, 0, 3, 0, 5}
result := Intersection(src, dst)
Expect(result).To(Equal([]int{0, 2, 4}))
})
})
Context("With no matching elements", func() {
It("Should return empty slice", func() {
src := []int{1, 2, 3}
dst := []int{0, 0, 0}
result := Intersection(src, dst)
Expect(result).To(BeEmpty())
})
})
Context("With all matching elements", func() {
It("Should return all indices", func() {
src := []int{1, 2, 3}
dst := []int{1, 2, 3}
result := Intersection(src, dst)
Expect(result).To(Equal([]int{0, 1, 2}))
})
})
Context("With empty slices", func() {
It("Should return empty slice", func() {
src := []int{}
dst := []int{}
result := Intersection(src, dst)
Expect(result).To(BeEmpty())
})
})
Context("With single element slices", func() {
It("Should handle single element comparison", func() {
src := []int{1}
dst := []int{1}
result := Intersection(src, dst)
Expect(result).To(Equal([]int{0}))
})
})
Context("With larger slices to test capacity optimization", func() {
It("Should handle larger slices efficiently", func() {
src := make([]int, 100)
dst := make([]int, 100)
for i := 0; i < 100; i++ {
src[i] = i
dst[i] = i % 2 // Every other position matches when i is even
}
result := Intersection(src, dst)
// Positions where src[i] == dst[i] (only when i=0 and i=1)
expected := []int{0, 1}
Expect(result).To(Equal(expected))
})
})
})
})