def testC5DiamondCoDiamondFree(self): g = make_cycle(5) subgraphs = [make_diamond(), make_co_diamond()] k_vertexes = k_vertex(g, subgraphs) expect = [False, False, True, True, False, False] for index, k in enumerate(k_vertexes): self.assertEqual(k['has_k_vertex'], expect[index], '''K Vertex says (diamond,co-diamond)- free Graph %d - vertex:%r but should be %r''' %(index, k['has_k_vertex'], expect[index])) set_2_vertex = [(0, 1), (0, 4), (1, 2), (2, 3), (3, 4)] for check in set_2_vertex: self.assertEqual(check in k_vertexes[2]['combinations'], True, ''' K vertex missing 2 Vertex set (%d, %d) on (diamond, co-diamond)-free Grpah ''' %(check[0],check[1])) set_3_vertex = [(0, 1, 3), (0, 2, 3), (0, 2, 4), (1, 2, 4), (1, 3, 4)] for check in set_3_vertex: self.assertEqual(check in k_vertexes[3]['combinations'], True, ''' K vertex missing 3 Vertex set (%d, %d, %d) on (diamond, co-diamond)-free Grpah ''' %(check[0],check[1], check[2]))
def testValidColoring(self): g = make_claw() # test invalid claw coloring coloring = [[0, 1, 2, 3]] valid = valid_coloring(coloring, g) self.assertEqual(valid, False, "Valid coloring: Failed for one coloring on claw") coloring = [[1, 3, 2], [0]] valid = valid_coloring(coloring, g) self.assertEqual(valid, True, "Valid coloring: Failed for valid coloring on claw") # test valid claw coloring coloring = [[0], [1, 2, 3]] valid = valid_coloring(coloring, g) self.assertEqual(valid, True, "Valid coloring: Failed for valid coloring on claw") # test invalid claw coloring coloring = [[0, 1], [2, 3]] valid = valid_coloring(coloring, g) self.assertEqual(valid, False, "Valid coloring: Failed for invalid coloring on claw") # test valid diamond coloring g = make_diamond() coloring = [[0], [1], [2, 3]] valid = valid_coloring(coloring, g) self.assertEqual(valid, True, "Valid coloring: failed for valid coloring on diamond") coloring = [[3], [2], [0, 1]] valid = valid_coloring(coloring, g) self.assertEqual(valid, False, ''' Valid coloring: failed for invalid coloring on diamond ''')
def testFindEliminatinSet(self): expect = find_eliminating_set(make_claw()) self.assertEqual(expect, []) expect = find_eliminating_set(make_diamond()) self.assertEqual(expect, [0]) print() expect = find_eliminating_set(make_clique(4)) self.assertEqual(expect, [])
def testChromaticNumber(self): g = make_claw() chromatic = chromatic_number(g) expect = 2 self.assertEqual(expect, chromatic, "Chromatic Number: Claw Case") g = make_diamond() chromatic = chromatic_number(g) expect = 3 self.assertEqual(expect, chromatic, "Chromatic Number: Diamond Case")
def testTriangleFree(self): G = make_cycle(4) self.assertEqual(triangle_free(G), True) G = make_claw() self.assertEqual(triangle_free(G), True) G = make_co_claw() self.assertEqual(triangle_free(G), False) G = make_diamond() self.assertEqual(triangle_free(G), False)
def testCreateCliqueList(self): c, k, i = self.dcolor.create_clique_list() self.assertEqual([[[0], [1]], [[2]], [[3]]], c) self.assertEqual(k, 2) self.assertEqual(i, 0) self.dcolor = Dcolor(make_diamond()) c, k, i = self.dcolor.create_clique_list() self.assertEqual([[[0], [1], [2]], [[3]]], c) self.assertEqual(k, 3) self.assertEqual(i, 0)
def testColoring(self): g = make_claw() result = coloring(g) expect = [[1, 3, 2], [0]] self.assertEqual(expect, result, "Coloring: Claw Case") g = make_diamond() result = coloring(g) expect = [[2, 3], [0], [1]] self.assertEqual(expect, result, "Coloring: Diamond Case") g = nx.Graph() g.add_node(0) g.add_node(1) result = coloring(g) expect = [[0, 1]] self.assertEqual(expect, result, "Coloring: Stable Set")
def testColor(self): result = self.dcolor.color() expect = [[0], [1, 2, 3]] self.assertEqual(expect, result, "Coloring: Claw Case") self.dcolor = Dcolor(make_diamond()) result = self.dcolor.color() expect = [[0], [1], [2, 3]] self.assertEqual(expect, result, "Coloring: Diamond Case") g = nx.Graph() g.add_node(0) g.add_node(1) self.dcolor = Dcolor(g) result = self.dcolor.color() expect = [[0, 1]] self.assertEqual(expect, result, "Coloring: Stable Set")
def testCliqueCutset(self): # no cutset result = clique_cutset(make_cycle(5)) self.assertEqual(result, None) # cutset is subclique of the maximal clique result = clique_cutset(make_diamond()) self.assertEqual(result, (0, 1)) # just a normal cutset result = clique_cutset(make_kite()) self.assertEqual(result, (2,)) # whole graph is a clique result = clique_cutset(make_clique(4)) self.assertEqual(result, (0, 1, 2, 3)) # a random graph result = clique_cutset(make_bridge()) self.assertEqual(result, (0, 1))
def special_graph(g): valid = False if induced_subgraph(g, make_diamond()) is not None: if clique_cutset(g) is None: valid = True return valid