Skip to content

Commit

Permalink
clean up bipartitegraph tests
Browse files Browse the repository at this point in the history
  • Loading branch information
onsi committed Jul 25, 2024
1 parent ebadb67 commit f5bec80
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 93 deletions.
41 changes: 41 additions & 0 deletions matchers/support/goraph/bipartitegraph/bipartitegraph_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bipartitegraph_test

import (
"fmt"
"reflect"

. "github.com/onsi/gomega/matchers/support/goraph/bipartitegraph"
Expand Down Expand Up @@ -165,4 +166,44 @@ var _ = Describe("Bipartitegraph", func() {
Ω(graph3.LargestMatching()).Should(HaveLen(79))
})
})

Describe("Edge case in Issue #765", func() {
It("is now resolved", func() {
knownEdges := map[string]bool{
"1A": true,
"1B": true,
"1C": true,
"1D": true,
"1E": true,
"2A": true,
"2D": true,
"3B": true,
"3D": true,
"4B": true,
"4D": true,
"4E": true,
"5A": true,
}

edgesFunc := func(l, r interface{}) (bool, error) {
return knownEdges[fmt.Sprintf("%v%v", l, r)], nil
}

vertices := []interface{}{"1", "2", "3", "4", "5", "A", "B", "C", "D", "E"}
leftPart := vertices[:5]
rightPart := vertices[5:]

bipartiteGraph, err := NewBipartiteGraph(leftPart, rightPart, edgesFunc)
Ω(err).ShouldNot(HaveOccurred())
edgeSet := bipartiteGraph.LargestMatching()
Ω(edgeSet).Should(HaveLen(5))

result := []string{}
for _, edge := range edgeSet {
result = append(result, fmt.Sprintf("%v%v", vertices[edge.Node1], vertices[edge.Node2]))
}
Ω(result).Should(ConsistOf("1C", "2D", "3B", "4E", "5A"))

})
})
})
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package bipartitegraph

import (
"slices"

. "github.com/onsi/gomega/matchers/support/goraph/edge"
. "github.com/onsi/gomega/matchers/support/goraph/node"
"github.com/onsi/gomega/matchers/support/goraph/util"
"slices"
)

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

This file was deleted.

0 comments on commit f5bec80

Please sign in to comment.