Skip to content

Commit

Permalink
Merge pull request #1088 from PetholzA/feature/19062023_python_tests_…
Browse files Browse the repository at this point in the history
…matching

python test: adds tests in test_matching.py
  • Loading branch information
fabratu committed Jul 12, 2023
2 parents ade66bc + b69996f commit 478396a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions networkit/test/test_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ def runAlgo(g):
runAlgo(self.g)
runAlgo(self.gw)

def testPathGrowingMatcherEdgeScores(self):
G = nk.Graph(5)
G.addEdge(0,1)
G.addEdge(2,1)
G.addEdge(3,1)
G.addEdge(2,4)
G.indexEdges()
edgeScores = [0.5, 1.5, 1.0, 2.0]
pgmes = nk.matching.PathGrowingMatcher(G, edgeScores)
pgmes.run()
self.assertEqual(len(pgmes.getMatching().getVector()), 5)

def testSuitorMatcher(self):

def doTest(g):
Expand All @@ -45,5 +57,28 @@ def doTest(g):
doTest(self.g)
doTest(self.gw)

def testMatching(self):
#test all functions of abstract Matching class
m1 = nk.matching.Matching(4)
G = nk.Graph(4)
G.addEdge(0,1) # G: 0 -- 1
G.addEdge(0,2) # |
G.addEdge(2,3) # 2 -- 3
m1.match(0,1)
m1.match(2,3)
self.assertTrue(m1.isProper(G))
self.assertTrue(m1.areMatched(0,1))
self.assertTrue(m1.isMatched(0))
self.assertTrue(m1.isMatched(1))
self.assertEqual(m1.size(G), 2)
self.assertEqual(m1.mate(1), 0)
self.assertEqual(m1.weight(G), 2.0)
G2=nk.Graph(2)#size of matching
Par=m1.toPartition(G2)
self.assertEqual(len(Par), 2)
self.assertListEqual(m1.getVector(), [1, 0, 3, 2])
m1.unmatch(0,1)
self.assertFalse(m1.areMatched(0,1))

if __name__ == "__main__":
unittest.main()

0 comments on commit 478396a

Please sign in to comment.