Skip to content

Commit f5bec80

Browse files
committed
clean up bipartitegraph tests
1 parent ebadb67 commit f5bec80

File tree

3 files changed

+44
-93
lines changed

3 files changed

+44
-93
lines changed

matchers/support/goraph/bipartitegraph/bipartitegraph_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package bipartitegraph_test
22

33
import (
4+
"fmt"
45
"reflect"
56

67
. "github.com/onsi/gomega/matchers/support/goraph/bipartitegraph"
@@ -165,4 +166,44 @@ var _ = Describe("Bipartitegraph", func() {
165166
Ω(graph3.LargestMatching()).Should(HaveLen(79))
166167
})
167168
})
169+
170+
Describe("Edge case in Issue #765", func() {
171+
It("is now resolved", func() {
172+
knownEdges := map[string]bool{
173+
"1A": true,
174+
"1B": true,
175+
"1C": true,
176+
"1D": true,
177+
"1E": true,
178+
"2A": true,
179+
"2D": true,
180+
"3B": true,
181+
"3D": true,
182+
"4B": true,
183+
"4D": true,
184+
"4E": true,
185+
"5A": true,
186+
}
187+
188+
edgesFunc := func(l, r interface{}) (bool, error) {
189+
return knownEdges[fmt.Sprintf("%v%v", l, r)], nil
190+
}
191+
192+
vertices := []interface{}{"1", "2", "3", "4", "5", "A", "B", "C", "D", "E"}
193+
leftPart := vertices[:5]
194+
rightPart := vertices[5:]
195+
196+
bipartiteGraph, err := NewBipartiteGraph(leftPart, rightPart, edgesFunc)
197+
Ω(err).ShouldNot(HaveOccurred())
198+
edgeSet := bipartiteGraph.LargestMatching()
199+
Ω(edgeSet).Should(HaveLen(5))
200+
201+
result := []string{}
202+
for _, edge := range edgeSet {
203+
result = append(result, fmt.Sprintf("%v%v", vertices[edge.Node1], vertices[edge.Node2]))
204+
}
205+
Ω(result).Should(ConsistOf("1C", "2D", "3B", "4E", "5A"))
206+
207+
})
208+
})
168209
})

matchers/support/goraph/bipartitegraph/bipartitegraphmatching.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package bipartitegraph
22

33
import (
4+
"slices"
5+
46
. "github.com/onsi/gomega/matchers/support/goraph/edge"
57
. "github.com/onsi/gomega/matchers/support/goraph/node"
68
"github.com/onsi/gomega/matchers/support/goraph/util"
7-
"slices"
89
)
910

1011
// LargestMatching implements the Hopcroft–Karp algorithm taking as input a bipartite graph
@@ -159,7 +160,7 @@ func (bg *BipartiteGraph) createSLAPGuideLayers(matching EdgeSet) (guideLayers [
159160
return []NodeOrderedSet{}
160161
}
161162
if done { // if last layer - into last layer must be only 'free' nodes
162-
currentLayer = slices.DeleteFunc(currentLayer, func(in Node)bool{
163+
currentLayer = slices.DeleteFunc(currentLayer, func(in Node) bool {
163164
return !matching.Free(in)
164165
})
165166
}

matchers/support/goraph/bipartitegraph/bipartitegraphmatching_test.go

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)