tools: Add src/cts/results.List.MinimalVariantTags

MinimalVariantTags accepts a list of tag-sets (e.g GPU tags, OS tags, etc),
and returns an optimized list of variants, folding together variants that
have identical result query-to-status mappings, and removing redundant tags.

Bug: dawn:1342
Change-Id: I759c82e9a0631a9d321d376656e5a2dbbf5f5507
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87643
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton
2022-04-29 08:13:19 +00:00
committed by Dawn LUCI CQ
parent cede544df3
commit 2c1154c36f
6 changed files with 316 additions and 6 deletions

View File

@@ -71,7 +71,7 @@ func (s Set[T]) Contains(item T) bool {
return found
}
// Contains returns true if the set contains all the items in o
// ContainsAll returns true if the set contains all the items in o
func (s Set[T]) ContainsAll(o Set[T]) bool {
for item := range o {
if !s.Contains(item) {
@@ -81,6 +81,16 @@ func (s Set[T]) ContainsAll(o Set[T]) bool {
return true
}
// ContainsAny returns true if the set contains any of the items in o
func (s Set[T]) ContainsAny(o Set[T]) bool {
for item := range o {
if s.Contains(item) {
return true
}
}
return false
}
// Intersection returns true if the set contains all the items in o
func (s Set[T]) Intersection(o Set[T]) Set[T] {
out := NewSet[T]()

View File

@@ -123,6 +123,39 @@ func TestSetContainsAll(t *testing.T) {
expectEq(t, `s.ContainsAll("c", "a", "b")`, s.ContainsAll(S("c", "a", "b")), true)
}
func TestSetContainsAny(t *testing.T) {
S := container.NewSet[string]
s := container.NewSet[string]()
s.Add("c")
expectEq(t, `s.ContainsAny("a")`, s.ContainsAny(S("a")), false)
expectEq(t, `s.ContainsAny("b")`, s.ContainsAny(S("b")), false)
expectEq(t, `s.ContainsAny("c")`, s.ContainsAny(S("c")), true)
expectEq(t, `s.ContainsAny("a", "b")`, s.ContainsAny(S("a", "b")), false)
expectEq(t, `s.ContainsAny("b", "c")`, s.ContainsAny(S("b", "c")), true)
expectEq(t, `s.ContainsAny("c", "a")`, s.ContainsAny(S("c", "a")), true)
expectEq(t, `s.ContainsAny("c", "a", "b")`, s.ContainsAny(S("c", "a", "b")), true)
s.Add("a")
expectEq(t, `s.ContainsAny("a")`, s.ContainsAny(S("a")), true)
expectEq(t, `s.ContainsAny("b")`, s.ContainsAny(S("b")), false)
expectEq(t, `s.ContainsAny("c")`, s.ContainsAny(S("c")), true)
expectEq(t, `s.ContainsAny("a", "b")`, s.ContainsAny(S("a", "b")), true)
expectEq(t, `s.ContainsAny("b", "c")`, s.ContainsAny(S("b", "c")), true)
expectEq(t, `s.ContainsAny("c", "a")`, s.ContainsAny(S("c", "a")), true)
expectEq(t, `s.ContainsAny("c", "a", "b")`, s.ContainsAny(S("c", "a", "b")), true)
s.Remove("c")
s.Add("b")
expectEq(t, `s.ContainsAny("a")`, s.ContainsAny(S("a")), true)
expectEq(t, `s.ContainsAny("b")`, s.ContainsAny(S("b")), true)
expectEq(t, `s.ContainsAny("c")`, s.ContainsAny(S("c")), false)
expectEq(t, `s.ContainsAny("a", "b")`, s.ContainsAny(S("a", "b")), true)
expectEq(t, `s.ContainsAny("b", "c")`, s.ContainsAny(S("b", "c")), true)
expectEq(t, `s.ContainsAny("c", "a")`, s.ContainsAny(S("c", "a")), true)
expectEq(t, `s.ContainsAny("c", "a", "b")`, s.ContainsAny(S("c", "a", "b")), true)
}
func TestSetIntersection(t *testing.T) {
a := container.NewSet(1, 3, 4, 6)
b := container.NewSet(2, 3, 4, 5)