/
githubmirror
/
terraform
Обзор
Документация
Войти
/
githubmirror
/
terraform
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
internal/dag/seq_test.go
108 строк
2 KB
James Bardin
Final renaming, calrification, and commenting
03 авг 2026, 17:17
03 авг 2026, 17:17
b0ec8dc
Код
Авторство
О чём код?
// Copyright IBM Corp. 2014, 2026 // SPDX-License-Identifier: BUSL-1.1 package dag import ( "fmt" "testing" ) // Mock implementation of SeqVertex for testing type MockVertex struct { id int } func (v MockVertex) Name() string { return fmt.Sprintf("MockVertex(%d)", v.id) } func (v MockVertex) ZeroValue() any { return MockVertex{} } type MockVertex2 struct { id int } func (v MockVertex2) Name() string { return fmt.Sprintf("MockVertex2(%d)", v.id) } func TestSelectSeq(t *testing.T) { v1 := MockVertex{id: 1} v11 := MockVertex{id: 11} v2 := MockVertex2{id: 2} vertices := NewVertexSet() vertices.Add(v1) vertices.Add(v2) vertices.Add(v11) graph := &Graph{vertices: vertices} seq := SelectSeq[MockVertex](graph.VerticesSeq()) t.Run("Select objects of given type", func(t *testing.T) { count := len(seq.Collect()) if count != 2 { t.Errorf("Expected 2, got %d", count) } }) t.Run("Returns empty when looking for incompatible types", func(t *testing.T) { seq := SelectSeq[MockVertex2](seq.AsGeneric()) count := len(seq.Collect()) if count != 0 { t.Errorf("Expected empty, got %d", count) } }) t.Run("Select objects of given interface", func(t *testing.T) { type zeroValuer interface { Vertex ZeroValue() any } seq := SelectSeq[zeroValuer](graph.VerticesSeq()) count := len(seq.Collect()) if count != 2 { t.Errorf("Expected 1, got %d", count) } }) } func TestExcludeSeq(t *testing.T) { v1 := MockVertex{id: 1} v11 := MockVertex{id: 11} v2 := MockVertex2{id: 2} vertices := NewVertexSet() vertices.Add(v1) vertices.Add(v2) vertices.Add(v11) graph := &Graph{vertices: vertices} seq := ExcludeSeq[MockVertex](graph.VerticesSeq()) t.Run("Exclude objects of given type", func(t *testing.T) { count := len(seq.Collect()) if count != 1 { t.Errorf("Expected 1, got %d", count) } }) t.Run("Returns empty when looking for incompatible types", func(t *testing.T) { seq := ExcludeSeq[MockVertex2](seq) count := len(seq.Collect()) if count != 0 { t.Errorf("Expected empty, got %d", count) } }) t.Run("Exclude objects of given interface", func(t *testing.T) { type zeroValuer interface { Vertex ZeroValue() any } seq := ExcludeSeq[zeroValuer](graph.VerticesSeq()) count := len(seq.Collect()) if count != 1 { t.Errorf("Expected 1, got %d", count) } }) }