def test_tsort_003(self): """One node digraph""" dg = digraph_create_from_dict({"A": []}) tsort = dg.topological_sort() tnames = node_list_to_node_name_list(tsort) self.assertEqual(tnames, ["A"], "incorrect")
def test_find_02(self): """Digraph find with element not available""" d = {"A": ["B"], "B": ["A", "C", "D"], "C": ["A", "D"], "D": ["D"]} dg = digraph_create_from_dict(d) n = dg.find("Z") self.assertIsNone(n)
def test_constructor_004(self): """Test conversion from dictionary to graph and back (one node)""" d = {"A": ["A"]} dg = digraph_create_from_dict(d) e = dg.as_dict() self.assertEqual(d["A"], list(e["A"]))
def test_constructor_002(self): """Test conversion from dictionary to graph and back (zero nodes)""" d = {} dg = digraph_create_from_dict(d) e = dg.as_dict() self.assertEqual(d, e)
def test_get_named_node_01(self): """Digraph get named node with map available""" d = {"A": ["B"], "B": ["A", "C", "D"], "C": ["A", "D"], "D": ["D"]} dg = digraph_create_from_dict(d) n = dg.find("A") self.assertEqual("A", n.get_name())
def test_tsort_001(self): """Simple three node digraph""" dg = digraph_create_from_dict( {"A": ["B", "C"], "B": ["C"], "C": []}) tsort = dg.topological_sort() tnames = node_list_to_node_name_list(tsort) self.assertEqual(tnames, ['A', 'B', 'C'], "incorrect")
def test_constructor_006(self): """Test conversion from dictionary: two node circle""" d = {"A": ["B"], "B": ["A"]} dg = digraph_create_from_dict(d) e = dg.as_dict() self.assertEqual(d["A"], list(e["A"])) self.assertEqual(d["B"], list(e["B"]))
def test_tsort_004(self): """More complex digraph""" dg = digraph_create_from_dict( {"A": ["B", "C"], "B": ["C", "E"], "C": ["D", "E"], "D": ["E"], "E": []}) tsort = dg.topological_sort() tnames = node_list_to_node_name_list(tsort) self.assertEqual(tnames, ['A', 'B', 'C', 'D', 'E'], "incorrect")
def test_constructor_005(self): """Test conversion: error: pointed node does not exists""" d = {"A": ["B"]} try: d = digraph_create_from_dict(d) self.assertTrue(False) except RuntimeError: pass
def test_find_01(self): """Digraph find with element available""" d = {"A": ["B"], "B": ["A", "C", "D"], "C": ["A", "D"], "D": ["D"]} dg = digraph_create_from_dict(d) n = dg.find("A") self.assertEqual( "A", n.get_name(), )
def test_constructor_007(self): """Test conversion from dictionary: more complex graph""" d = {"A": ["B"], "B": ["A", "D", "C"], "C": ["A", "D"], "D": ["D"]} dg = digraph_create_from_dict(d) e = dg.as_dict() self.assertEqual(d['A'], list(e['A'])) self.assertEqual(set(d['B']), set(e['B'])) self.assertEqual(set(d['C']), set(e['C'])) self.assertEqual(d['D'], list(e['D']))
def test_tsort_005(self): """Digraph with two components""" dg = digraph_create_from_dict({"A": ["B", "C"], "B": ["C"], "C": [], "D": ["E"], "E": []}) tsort = dg.topological_sort() tnames = node_list_to_node_name_list(tsort) # Because of two components, there exist a couple of different # possibilities - but these are all the requirements that have # to be fulfilled to be a correct topological sort: self.assertTrue(tnames.index('A') < tnames.index('B')) self.assertTrue(tnames.index('B') < tnames.index('C')) self.assertTrue(tnames.index('D') < tnames.index('E'))