MCPcopy Create free account
hub / github.com/buildpacks/pack / testStringSet

Function testStringSet

internal/stringset/stringset_test.go:22–82  ·  view source on GitHub ↗

NOTE: Do NOT use AssertSliceContains() or variants of it in theses tests, as they use `stringset`

(t *testing.T, when spec.G, it spec.S)

Source from the content-addressed store, hash-verified

20
21// NOTE: Do NOT use AssertSliceContains() or variants of it in theses tests, as they use `stringset`
22func testStringSet(t *testing.T, when spec.G, it spec.S) {
23 when("#FromSlice", func() {
24 it("returns a map with elements as unique keys", func() {
25 slice := []string{"a", "b", "a", "c"}
26
27 set := stringset.FromSlice(slice)
28
29 h.AssertEq(t, len(set), 3)
30
31 _, ok := set["a"]
32 h.AssertTrue(t, ok)
33
34 _, ok = set["b"]
35 h.AssertTrue(t, ok)
36
37 _, ok = set["c"]
38 h.AssertTrue(t, ok)
39 })
40 })
41
42 when("#Compare", func() {
43 it("returns elements in slice 1 but not in slice 2", func() {
44 slice1 := []string{"a", "b", "c", "d"}
45 slice2 := []string{"a", "c"}
46
47 extra, _, _ := stringset.Compare(slice1, slice2)
48
49 h.AssertEq(t, len(extra), 2)
50
51 sort.Strings(extra)
52 h.AssertEq(t, extra[0], "b")
53 h.AssertEq(t, extra[1], "d")
54 })
55
56 it("returns elements in slice 2 missing from slice 1", func() {
57 slice1 := []string{"a", "c"}
58 slice2 := []string{"a", "b", "c", "d"}
59
60 _, missing, _ := stringset.Compare(slice1, slice2)
61
62 h.AssertEq(t, len(missing), 2)
63
64 sort.Strings(missing)
65 h.AssertEq(t, missing[0], "b")
66 h.AssertEq(t, missing[1], "d")
67 })
68
69 it("returns elements present in both slices", func() {
70 slice1 := []string{"a", "b", "c"}
71 slice2 := []string{"b", "c", "d"}
72
73 _, _, common := stringset.Compare(slice1, slice2)
74
75 h.AssertEq(t, len(common), 2)
76
77 sort.Strings(common)
78 h.AssertEq(t, common[0], "b")
79 h.AssertEq(t, common[1], "c")

Callers

nothing calls this directly

Calls 2

FromSliceFunction · 0.92
CompareFunction · 0.92

Tested by

no test coverage detected