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 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 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 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 = DenseColor(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 = DenseColor(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 = DenseColor(g) result = self.dcolor.color() expect = [[0, 1]] self.assertEqual(expect, result, "Coloring: Stable Set")