Skip to content

Commit 24026d0

Browse files
committed
wip: add examples
1 parent 2bc68a1 commit 24026d0

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

examples_hashset_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,42 @@ func ExampleHashSet_Equal() {
288288
// false
289289
}
290290

291+
func ExampleHashSet_EqualSlice() {
292+
anna := &person{name: "anna", id: 94}
293+
bill := &person{name: "bill", id: 50}
294+
carl := &person{name: "carl", id: 10}
295+
dave := &person{name: "dave", id: 32}
296+
297+
s := HashSetFrom[*person, string]([]*person{anna, bill, carl})
298+
299+
fmt.Println(s.EqualSlice([]*person{bill, anna, carl}))
300+
fmt.Println(s.EqualSlice([]*person{anna, anna, bill, carl}))
301+
fmt.Println(s.EqualSlice([]*person{dave, bill, carl}))
302+
303+
// Output:
304+
// true
305+
// true
306+
// false
307+
}
308+
309+
func ExampleHashSet_EqualSliceSet() {
310+
anna := &person{name: "anna", id: 94}
311+
bill := &person{name: "bill", id: 50}
312+
carl := &person{name: "carl", id: 10}
313+
dave := &person{name: "dave", id: 32}
314+
315+
s := HashSetFrom[*person, string]([]*person{anna, bill, carl})
316+
317+
fmt.Println(s.EqualSliceSet([]*person{bill, anna, carl}))
318+
fmt.Println(s.EqualSliceSet([]*person{anna, anna, bill, carl}))
319+
fmt.Println(s.EqualSliceSet([]*person{dave, bill, carl}))
320+
321+
// Output:
322+
// true
323+
// false
324+
// false
325+
}
326+
291327
func ExampleHashSet_Copy() {
292328
anna := &person{name: "anna", id: 94}
293329
bill := &person{name: "bill", id: 50}

examples_set_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,32 @@ func ExampleSet_Equal() {
201201
// true
202202
}
203203

204+
func ExampleSet_EqualSlice() {
205+
s := From([]string{"red", "green", "blue"})
206+
207+
fmt.Println(s.EqualSlice([]string{"red", "blue", "green"}))
208+
fmt.Println(s.EqualSlice([]string{"red", "red", "blue", "green"}))
209+
fmt.Println(s.EqualSlice([]string{"yellow", "blue", "green"}))
210+
211+
// Output:
212+
// true
213+
// true
214+
// false
215+
}
216+
217+
func ExampleSet_EqualSliceSet() {
218+
s := From([]string{"red", "green", "blue"})
219+
220+
fmt.Println(s.EqualSliceSet([]string{"red", "blue", "green"}))
221+
fmt.Println(s.EqualSliceSet([]string{"red", "red", "blue", "green"}))
222+
fmt.Println(s.EqualSliceSet([]string{"yellow", "blue", "green"}))
223+
224+
// Output:
225+
// true
226+
// false
227+
// false
228+
}
229+
204230
func ExampleSet_Copy() {
205231
s := From([]string{"red", "green", "blue"})
206232
t := s.Copy()

examples_treeset_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,32 @@ func ExampleTreeSet_Equal() {
283283
// false
284284
}
285285

286+
func ExampleTreeSet_EqualSlice() {
287+
t := TreeSetFrom[int]([]int{5, 4, 3, 2, 1}, Compare[int])
288+
289+
fmt.Println(t.EqualSlice([]int{1, 2, 3, 4, 5}))
290+
fmt.Println(t.EqualSlice([]int{1, 1, 2, 3, 4, 5}))
291+
fmt.Println(t.EqualSlice([]int{0, 2, 3, 4, 5}))
292+
293+
// Output:
294+
// true
295+
// true
296+
// false
297+
}
298+
299+
func ExampleTreeSet_EqualSliceSet() {
300+
t := TreeSetFrom[int]([]int{5, 4, 3, 2, 1}, Compare[int])
301+
302+
fmt.Println(t.EqualSliceSet([]int{1, 2, 3, 4, 5}))
303+
fmt.Println(t.EqualSliceSet([]int{1, 1, 2, 3, 4, 5}))
304+
fmt.Println(t.EqualSliceSet([]int{0, 2, 3, 4, 5}))
305+
306+
// Output:
307+
// true
308+
// false
309+
// false
310+
}
311+
286312
func ExampleTreeSet_Copy() {
287313
s := TreeSetFrom[int]([]int{1, 2, 3, 4, 5}, Compare[int])
288314
c := s.Copy()

0 commit comments

Comments
 (0)