MCPcopy
hub / github.com/cilium/cilium / TestImmSetFunc

Function TestImmSetFunc

pkg/container/immset_test.go:14–46  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestImmSetFunc(t *testing.T) {
15 // Test the ImmSet with netip.Addr.
16 a1, a2, a3 := netip.MustParseAddr("1.1.1.1"), netip.MustParseAddr("2.2.2.2"), netip.MustParseAddr("3.3.3.3")
17
18 // Empty set
19 s := NewImmSetFunc[netip.Addr](netip.Addr.Compare)
20 assert.Equal(t, 0, s.Len(), "expected 0 len for empty set")
21 assert.True(t, s.Equal(s), "expected empty set to equal itself")
22
23 s = s.Insert(a1)
24 assert.Equal(t, 1, s.Len(), "expected length of 1 after Insert")
25 s = s.Insert(a2)
26 assert.Equal(t, 2, s.Len(), "expected length of 2 after second Insert")
27 assert.ElementsMatch(t, s.AsSlice(), []netip.Addr{a1, a2})
28
29 s1 := s.Delete(a2)
30 assert.Equal(t, 2, s.Len(), "expected length of 2 for original")
31 assert.Equal(t, 1, s1.Len(), "expected length of 1 after Delete")
32
33 // Initialized set
34 s2 := NewImmSetFunc[netip.Addr](netip.Addr.Compare, a1, a2, a3)
35 assert.Equal(t, 3, s2.Len(), "expected length of 3 for initialized set")
36
37 s2 = s2.Difference(s)
38 assert.Equal(t, 1, s2.Len(), "expected length of 1 after diff")
39 assert.ElementsMatch(t, s2.AsSlice(), []netip.Addr{a3})
40
41 s2 = s2.Delete(a2 /* no-op */, a3)
42 assert.Equal(t, 0, s2.Len(), "expected length of 0 after final delete")
43
44 s2 = s2.Delete(a3)
45 assert.Equal(t, 0, s2.Len(), "expected no change in length after nop delete")
46}
47
48func TestImmSet(t *testing.T) {
49 // Empty set

Callers

nothing calls this directly

Calls 7

NewImmSetFuncFunction · 0.85
DifferenceMethod · 0.80
EqualMethod · 0.65
LenMethod · 0.65
InsertMethod · 0.65
DeleteMethod · 0.65
AsSliceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…