def test_nodes_by_degree(self): d = {} d["a"] = ["b", "c", "d", "e"] d["b"] = ["a", "c"] d["c"] = ["a", "b", "d"] d["d"] = ["a", "c"] d["e"] = ["a"] g = Graph(d) self.assertIn(("a", 4), graph_functions.nodes_by_degree(g)) self.assertIn(("c", 3), graph_functions.nodes_by_degree(g))
def test_nodes_by_degree(self): self.assertEqual(nodes_by_degree(self.g1), [], "T2: g1 should be blank") self.assertEqual(nodes_by_degree(self.g2), [('A', 0)], "T2: g2 should contain 1 element") self.assertEqual( nodes_by_degree(self.g3), [('B', 3), ('A', 2), ('D', 2), ('C', 1), ('E', 0)], "T2: g3 should contain 5 elements with each neighbors from 3 to 0") self.assertEqual( nodes_by_degree(self.g4), [('A', 4), ('B', 4), ('C', 4), ('D', 4), ('E', 4)], "T2: g4 should be 5 elements with each neighbors of 4, a complete graphl" ) self.assertEqual(nodes_by_degree(self.g5), None, "T2: g5 is not a graph")
def test_nodes_by_degree_invalid(self): caught = False try: res = graph_functions.nodes_by_degree(self.not_a_graph) except TypeError: caught = True self.assertEqual(caught, True, "Expected True")
def testg24_nodesByDegree_type(self): with self.assertRaises(TypeError): gf.nodes_by_degree(None)
def testg23_nodesByDegree_order(self): g = Graph({'1': ['2', '3', '4'], '2': ['1', '3'], '3': ['2'], '4': []}) self.assertEqual(gf.nodes_by_degree(g)[0][0], '1', "G23") self.assertEqual(gf.nodes_by_degree(g)[1][0], '2', "G23") self.assertEqual(gf.nodes_by_degree(g)[2][0], '3', "G23") self.assertEqual(gf.nodes_by_degree(g)[3][0], '4', "G23")
def testg22_nodesByDegree_empty(self): self.assertEqual(gf.nodes_by_degree(self.empty), [], "G22")
def testg21_nodesByDegree_full(self): self.assertEqual(gf.nodes_by_degree(self.complete)[0], ('1', 2), "G21") self.assertEqual(gf.nodes_by_degree(self.complete)[1], ('3', 2), "G21") self.assertEqual(gf.nodes_by_degree(self.complete)[2], ('2', 2), "G21")
def test_node_deg(self): exp = [('A', 1), ('C', 1), ('B', 1)] self.assertEqual(nodes_by_degree(self.abc), exp) exp = [(1, 4), (3, 3), (5, 2)] self.assertEqual(nodes_by_degree(self.num), exp)
def test_nodes_by_degree_empty(self): g = Graph() self.assertNotIn(("a", 4), graph_functions.nodes_by_degree(g)) self.assertNotIn(("c", 3), graph_functions.nodes_by_degree(g))
def test_nodes_by_degree_valid(self): res = graph_functions.nodes_by_degree(self.g1) self.assertEqual(res, [('B', 3), ('A', 2), ('D', 2), ('C', 1), ('E', 0)], "Unexpected output")
def test_node_deg(self): exp = [('A', 1), ('C', 1), ('B', 1)] self.assertEqual(nodes_by_degree(self.abc), exp) exp = [(1, 4), (3,3), (5,2)] self.assertEqual(nodes_by_degree(self.num), exp)