def testCritical(self): critical = self.dal.k4_codiamond_critical() self.assertEqual(critical, True) self.dal = DalGraph(make_cycle(4)) critical = self.dal.k4_codiamond_critical() self.assertEqual(critical, False) self.dal = DalGraph(make_cycle(5)) self.dal._g.add_node(5) self.dal._g.add_edge(0, 5) self.dal._g.add_edge(1, 5) self.dal._g.add_edge(2, 5) self.dal._g.add_node(6) self.dal._g.add_edge(2, 6) self.dal._g.add_edge(3, 6) self.dal._g.add_edge(4, 6) critical = self.dal.k4_codiamond_critical() self.assertEqual(critical, True) self.dal = DalGraph(make_cycle(5)) self.dal._g.add_node(5) self.dal._g.add_edge(0, 5) self.dal._g.add_edge(1, 5) self.dal._g.add_edge(2, 5) self.dal._g.add_node(6) self.dal._g.add_edge(1, 6) self.dal._g.add_edge(2, 6) self.dal._g.add_edge(3, 6) critical = self.dal.k4_codiamond_critical() self.assertEqual(critical, False)
def testCycleNodes(self): g = DalGraph(make_cycle(3)) c = g.cycle_nodes() self.assertEqual(c, [], "Cycle Nodes Failed: found cycle less than 3") g = DalGraph(make_cycle(5)) c = g.cycle_nodes() self.assertEqual(c, [0, 1, 2, 3, 4 ,0], "Cycle Nodes Failed: did not find C5") c5 = make_cycle(5) c5.add_edge(2,4) g = DalGraph(c5) c = g.cycle_nodes() self.assertEqual(c, [], "Cycle Nodes Failed: did found non-induced C5")
def testKColor(self): g = DalGraph(make_cycle(3)) c = g.k_color() self.assertEqual(3, c, "KColor: K3 case") g = DalGraph(make_cycle(4)) c = g.k_color() self.assertEqual(None, c, "KColor: C4 case") g = DalGraph(make_wheel(6)) c = g.k_color() self.assertEqual(4, c, "KColor: W6 case") c5 = make_cycle(5) c5_2 = make_cycle(5) c = join(c5,c5_2) g = DalGraph(c) c = g.k_color() self.assertEqual(c, 6, "KColor: C5 joined with a C5")
def testHoleNumber(self): # test C3 c3 = make_cycle(3) hole = DalGraph(c3).hole_number() self.assertEqual(hole, 3, "Hole Number on C3") # test C5 c5 = make_cycle(5) hole = DalGraph(c5).hole_number() self.assertEqual(hole, 5, "Hole Number on C5") # test C8 c8 = make_cycle(8) hole = DalGraph(c8).hole_number() self.assertEqual(hole, 8, "Hole Number on C8") # test K4 k4 = nx.complete_graph(4) hole = DalGraph(k4).hole_number() self.assertEqual(hole, None, "Hole Number on K4") # test random graph rando = nx.barbell_graph(10, 10) hole = DalGraph(rando).hole_number() self.assertEqual(hole, None, "Hole Number on random graph")
def testStrongStableSet(self): g = nx.Graph() g.add_node(0) # check a triangle result = strong_stable_set(make_clique(3)) self.assertEqual(result.nodes(), g.nodes()) # check a diamond result = strong_stable_set(make_diamond()) self.assertEqual(result.nodes(), g.nodes()) # C5 result = strong_stable_set(make_cycle(5)) self.assertEqual(result, None)
def testCheckSmallerCycle(self): c3 = make_cycle(3) g = DalGraph(c3) c = g.check_smaller_cycle([], 1, 0) self.assertEqual(c, [0, 1], "Failed the simple C2 case") c3 = make_cycle(3) g = DalGraph(c3) c = g.check_smaller_cycle([0], 0, 1) self.assertEqual(c, [0, 1], "Failed the simple C2 case") c5 = make_cycle(5) g = DalGraph(c5) c = g.check_smaller_cycle([0, 1, 2], 4, 3) self.assertEqual(c, [0, 1, 2, 3 , 4, 0], "Failed the simple C5 Case") c4 = make_cycle(4) g = DalGraph(c4) c = g.check_smaller_cycle([0, 1, 2], 0 ,3) self.assertEqual([], c, "Failed the simple C4 case") c5 = make_cycle(5) c5.add_edge(2, 4) g = DalGraph(c5) c = g.check_smaller_cycle([0, 1, 2], 4, 3) self.assertEqual([], c, "Failed to find back track node in C5 Case") c = g.check_smaller_cycle([2], 4, 3) self.assertEqual([], c, "Failed to find back track node in C5 Case")
def testCliqueNumber(self): # test K3 k3 = nx.complete_graph(3) clique = DalGraph(k3).clique_number() self.assertEqual(clique, 3, "Clique Number on K3") # test K5 k5 = nx.complete_graph(5) clique = DalGraph(k5).clique_number() self.assertEqual(clique, 5, "Clique Number on K5") # test K8 k8 = nx.complete_graph(8) clique = DalGraph(k8).clique_number() self.assertEqual(clique, 8, "Clique Number on K8") # test C4 c4 = make_cycle(4) clique = DalGraph(c4).clique_number() self.assertEqual(clique, None, "Clique Number on C4") # test random graph rando = nx.barbell_graph(10, 10) clique = DalGraph(rando).clique_number() self.assertEqual(clique, None, "Clique Number on random graph")
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)
def setUp(self): self.dal = DalGraph(make_cycle(5))