Exemple #1
0
 def test_constructor_007(self):
     "Test conversion from dictionary: more complex graph"
     d = {"A": ["B"], "B": ["A", "C", "D"], "C": ["A", "D"],
          "D": ["D"] }
     dg = digraph_create_from_dict(d)
     e = dg.as_dict()
     assert(d == e)
Exemple #2
0
 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")
     assert(n.get_name() == "A")
Exemple #3
0
 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")
     assert(n == None)
Exemple #4
0
 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")
     assert(n.get_name() == "A")
Exemple #5
0
 def test_tsort_005(self):
     "Digraph with two components"
     dg = digraph_create_from_dict( {"A": ["B", "C"], "B": ["C"], "C": [],
                    "D": ["E"], "E": [] } )
     tsort = topological_sort(dg)
     tnames = node_list_to_node_name_list(tsort)
     self.assertEqual(tnames, ['C', 'B', 'A', 'E', 'D'], "incorrect")
Exemple #6
0
 def test_constructor_005(self):
     "Test conversion: error: pointed node does not exists"
     d = {"A": ["B"] }
     try:
         d = digraph_create_from_dict(d)
         assert(False)
     except RMTException, rmte:
         assert(rmte.id() == 24)
Exemple #7
0
 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 = topological_sort(dg)
     tnames = node_list_to_node_name_list(tsort)        
     self.assertEqual(tnames, ['E', 'D', 'C', 'B', 'A'], "incorrect")
Exemple #8
0
 def test_get_named_node_02(self):
     "Digraph get named node with map available but invalid node name"
     d = {"A": ["B"], "B": ["A", "C", "D"], "C": ["A", "D"],
          "D": ["D"] }
     dg = digraph_create_from_dict(d)
     try:
         n = dg.find_wt("NotThere")
         assert(False)
     except RMTException, rmte:
         assert(rmte.id() == 23)
Exemple #9
0
 def test_scc_006(self):
     "Check for scc in a three node digraph with scc"
     dg = digraph_create_from_dict({
         "A": ["B", "C"],
         "B": ["A"],
         "C": ["B"]
     })
     sccs = strongly_connected_components(dg)
     scc_exists = check_for_strongly_connected_components(sccs)
     self.assertEqual(scc_exists, True, "incorrect")
Exemple #10
0
 def test_scc_005(self):
     "Simple three node digraph with one scc II"
     dg = digraph_create_from_dict({
         "A": ["B", "C"],
         "B": ["A"],
         "C": ["B"]
     })
     sccs = strongly_connected_components(dg)
     sccsnames = node_sl_to_node_name_sl(sccs)
     self.assertEqual(sccsnames, [set(['A', 'C', 'B'])], "incorrect")
Exemple #11
0
 def test_cc_002(self):
     "Not connected digraph"
     dg = digraph_create_from_dict({
         "A": ["B"],
         "B": ["C"],
         "C": [],
         "D": ["E"],
         "E": []
     })
     ccs = connected_components(dg)
     assert (ccs.get_length() > 1)
Exemple #12
0
 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 = topological_sort(dg)
     tnames = node_list_to_node_name_list(tsort)
     self.assertEqual(tnames, ['E', 'D', 'C', 'B', 'A'], "incorrect")
Exemple #13
0
 def test_tsort_005(self):
     "Digraph with two components"
     dg = digraph_create_from_dict({
         "A": ["B", "C"],
         "B": ["C"],
         "C": [],
         "D": ["E"],
         "E": []
     })
     tsort = topological_sort(dg)
     tnames = node_list_to_node_name_list(tsort)
     self.assertEqual(tnames, ['C', 'B', 'A', 'E', 'D'], "incorrect")
Exemple #14
0
 def test_tsort_002(self):
     "Zero node digraph"
     dg = digraph_create_from_dict({})
     tsort = topological_sort(dg)
     tnames = node_list_to_node_name_list(tsort)
     self.assertEqual(tnames, [], "incorrect")
Exemple #15
0
 def test_tsort_003(self):
     "One node digraph"
     dg = digraph_create_from_dict({"A": []})
     tsort = topological_sort(dg)
     tnames = node_list_to_node_name_list(tsort)
     self.assertEqual(tnames, ["A"], "incorrect")
Exemple #16
0
 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()
     assert(d == e)
Exemple #17
0
 def test_scc_002(self):
     "Simple two node digraph with no scc"
     dg = digraph_create_from_dict({"A": ["B"], "B": [] })
     sccs = strongly_connected_components(dg)
     sccsnames = node_sl_to_node_name_sl(sccs)
     self.assertEqual(sccsnames, [set(['B']), set(['A'])], "incorrect")
Exemple #18
0
 def test_tsort_001(self):
     "Simple three node digraph"
     dg = digraph_create_from_dict({"A": ["B", "C"], "B": ["C"], "C": []})
     tsort = topological_sort(dg)
     tnames = node_list_to_node_name_list(tsort)
     self.assertEqual(tnames, ['C', 'B', 'A'], "incorrect")
Exemple #19
0
 def test_scc_005(self):
     "Simple three node digraph with one scc II"
     dg = digraph_create_from_dict({"A": ["B", "C"], "B": ["A"], "C": ["B"] })
     sccs = strongly_connected_components(dg)
     sccsnames = node_sl_to_node_name_sl(sccs)
     self.assertEqual(sccsnames, [set(['A', 'C', 'B'])], "incorrect")
Exemple #20
0
 def test_tsort_002(self):
     "Zero node digraph"
     dg = digraph_create_from_dict( {} )
     tsort = topological_sort(dg)
     tnames = node_list_to_node_name_list(tsort)
     self.assertEqual(tnames, [], "incorrect")
Exemple #21
0
 def test_scc_002(self):
     "Simple two node digraph with no scc"
     dg = digraph_create_from_dict({"A": ["B"], "B": []})
     sccs = strongly_connected_components(dg)
     sccsnames = node_sl_to_node_name_sl(sccs)
     self.assertEqual(sccsnames, [set(['B']), set(['A'])], "incorrect")
Exemple #22
0
 def test_scc_008(self):
     "Check for scc in a three node digraph with a two node scc"
     dg = digraph_create_from_dict({"A": ["B"], "B": ["A"], "C": [] })
     sccs = strongly_connected_components(dg)
     scc_exists = check_for_strongly_connected_components(sccs)
     self.assertEqual(scc_exists, True, "incorrect")
Exemple #23
0
 def test_tsort_001(self):
     "Simple three node digraph"
     dg = digraph_create_from_dict( {"A": ["B", "C"], "B": ["C"], "C": [] } )
     tsort = topological_sort(dg)
     tnames = node_list_to_node_name_list(tsort)
     self.assertEqual(tnames, ['C', 'B', 'A'], "incorrect")
Exemple #24
0
 def test_constructor_001(self):
     "Test conversion from dictionary to graph and back (two nodes)"
     d = {"A": ["B"], "B": []}
     dg = digraph_create_from_dict(d)
     e = dg.as_dict()
     assert(d == e)
Exemple #25
0
 def test_tsort_003(self):
     "One node digraph"
     dg = digraph_create_from_dict( {"A": [] } )
     tsort = topological_sort(dg)
     tnames = node_list_to_node_name_list(tsort)
     self.assertEqual(tnames, ["A"], "incorrect")
Exemple #26
0
 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()
     assert(d == e)
Exemple #27
0
 def test_constructor_004(self):
     "Test conversion from dictionary to graph and back (one node to itself)"
     d = {"A": ["A"] }
     dg = digraph_create_from_dict(d)
     e = dg.as_dict()
     assert(d == e)
Exemple #28
0
 def test_cc_002(self):
     "Not connected digraph"
     dg = digraph_create_from_dict({"A": ["B"], "B": ["C"], "C": [],
                    "D": ["E"], "E": [] })
     ccs = connected_components(dg)
     assert(ccs.get_length() > 1)