def testSubgraphSearchSolutionFound(self): # Test that when the length of query=>data vertex matches is the # same as the number of query vertices, then the solution is stored. g = Graph() q = Graph() q.addVertex(Vertex('u1', 'A')) # one query vertex matches = {'u1': 'v1'} # one match g._subgraphSearch(matches, q) self.assertEqual(len(g._solutions), 1)
def testSubgraphSearchSolutionNoCandidates(self): # Test when an umatched query vertex doesn't have any candidates, we # don't find any solutions. g = Graph() g.addVertex(Vertex('v1', 'A')) q = Graph() q.addVertex(Vertex('u1', 'B')) matches = {} self.assertEqual(len(g._solutions), 0) g._subgraphSearch(matches, q) self.assertEqual(len(g._solutions), 0)
def testSubgraphSearchSimpleSolution(self): # One simple solution. g = Graph() g.addVertex(Vertex('v1', 'A')) v1 = g._vertices['v1'] q = Graph() q.addVertex(Vertex('u1', 'A')) q._vertices['u1'].candidates = [v1] self.assertEqual(len(g._solutions), 0) g._subgraphSearch({}, q) self.assertEqual(len(g._solutions), 1) self.assertIn('u1', g._solutions[0]) self.assertEquals(g._solutions[0]['u1'], 'v1')
def testSubgraphSearchOneCandidateNotJoinable(self): # The query vertex has a candidate data vertex, but they aren't # "joinable" -- no solution. g = Graph() g.addVertex(Vertex('v1', 'A')) g.addVertex(Vertex('v2', 'B')) v1 = g._vertices['v1'] q = Graph() q.addEdge(Vertex('u1', 'A'), Vertex('u2', 'B')) q._vertices['u1'].candidates = [v1] # u2 and v2 are already matched. There's an edge between u1 and # u2, but no edge between v1 and v2 so u1 and v1 cannot be matched. matches = {'u2': 'v2'} self.assertEqual(len(g._solutions), 0) g._subgraphSearch(matches, q) self.assertEqual(len(g._solutions), 0)