def testFindCoClaw(self): g = DalGraph(make_co_claw()) # add some noise g._g.add_node(4) g._g.add_node(5) g._g.add_node(6) g._g.add_node(7) g._g.add_edge(3, 4) g._g.add_edge(2,5) g._g.add_edge(1, 6) g._g.add_edge(3, 7) result = g.find_co_claw() expect = [2, 3, 1, 0] self.assertEqual(result, expect) # no triangle g = DalGraph(make_claw()) # add some noise g._g.add_node(4) g._g.add_node(5) g._g.add_node(6) g._g.add_node(7) g._g.add_edge(0, 4) g._g.add_edge(0, 5) g._g.add_edge(0, 6) g._g.add_edge(0, 7) result = g.find_co_claw() expect = None self.assertEqual(result, expect) g = DalGraph(make_wheel(6)) result = g.find_co_claw() self.assertEqual(result, expect)
def testUnionNeighbors(self): g = DalGraph(make_claw()) result = g.union_neighbors([0]) expect = [1, 2, 3] self.assertEqual(result, expect) g._g.add_node(4) g._g.add_edge(3, 4) result =g.union_neighbors([4, 2]) expect = [3, 0] self.assertEqual(result, expect)
def testCriticalAprox(self): # is_critical graphs g = nx.Graph() g.add_node(0) g = join(g, g) g = join(g, g) d = DalGraph(g) result = d.critical_aprox() self.assertEqual(result, True) g = make_wheel(6) d = DalGraph(g) result = d.critical_aprox() self.assertEqual(result, True) d = DalGraph(make_cycle(5)) result = d.critical_aprox() self.assertEqual(result, True) # test non is_critical d = DalGraph(make_claw()) result = d.critical_aprox() self.assertEqual(result, False) d = DalGraph(make_co_claw()) result = d.critical_aprox() self.assertEqual(result, False)