예제 #1
0
 def test_invalid_source_index(self):
     graph = retworkx.PyGraph()
     graph.add_node(0)
     graph.add_node(1)
     graph.add_edge(0, 1, None)
     with self.assertRaises(IndexError):
         retworkx.num_shortest_paths_unweighted(graph, 4)
예제 #2
0
 def test_node_with_no_path(self):
     graph = retworkx.generators.directed_path_graph(5)
     graph.extend_from_edge_list([(6, 7), (7, 8), (8, 9), (9, 10), (10, 11)])
     expected = {1: 1, 2: 1, 3: 1, 4: 1}
     res = retworkx.num_shortest_paths_unweighted(graph, 0)
     self.assertEqual(expected, res)
     res = retworkx.num_shortest_paths_unweighted(graph, 6)
     expected = {7: 1, 8: 1, 9: 1, 10: 1, 11: 1}
     self.assertEqual(expected, res)
예제 #3
0
 def test_grid_graph(self):
     """Test num shortest paths for a 5x5 grid graph
     0 -> 1 -> 2 -> 3 -> 4
     |    |    |    |    |
     v    v    v    v    v
     5 -> 6 -> 7 -> 8 -> 9
     |    |    |    |    |
     v    v    v    v    v
     10-> 11-> 12-> 13-> 14
     |    |    |    |    |
     v    v    v    v    v
     15-> 16-> 17-> 18-> 19
     |    |    |    |    |
     v    v    v    v    v
     20-> 21-> 22-> 23-> 24
     """
     graph = retworkx.generators.directed_grid_graph(5, 5)
     res = retworkx.num_shortest_paths_unweighted(graph, 0)
     expected = {
         1: 1,
         2: 1,
         3: 1,
         4: 1,
         5: 1,
         6: 2,
         7: 3,
         8: 4,
         9: 5,
         10: 1,
         11: 3,
         12: 6,
         13: 10,
         14: 15,
         15: 1,
         16: 4,
         17: 10,
         18: 20,
         19: 35,
         20: 1,
         21: 5,
         22: 15,
         23: 35,
         24: 70,
     }
     self.assertEqual(expected, res)
예제 #4
0
 def test_parallel_paths(self):
     graph = retworkx.PyGraph()
     graph.extend_from_edge_list([
         (0, 1),
         (1, 2),
         (2, 3),
         (0, 4),
         (4, 5),
         (5, 3),
     ])
     res = retworkx.num_shortest_paths_unweighted(graph, 0)
     expected = {
         1: 1,
         2: 1,
         3: 2,
         4: 1,
         5: 1,
     }
     self.assertEqual(expected, res)
예제 #5
0
 def test_node_indices_with_holes(self):
     graph = retworkx.generators.directed_path_graph(5)
     graph.extend_from_edge_list([(6, 7), (7, 8), (8, 9), (9, 10), (10, 11)])
     graph.add_edge(4, 6, None)
     graph.remove_node(5)
     expected = {
         1: 1,
         2: 1,
         3: 1,
         4: 1,
         6: 1,
         7: 1,
         8: 1,
         9: 1,
         10: 1,
         11: 1,
     }
     res = retworkx.num_shortest_paths_unweighted(graph, 0)
     self.assertEqual(expected, res)
예제 #6
0
 def test_grid_graph(self):
     """Test num shortest paths for a 5x5 grid graph
     0 - 1 - 2 - 3 - 4
     |   |   |   |   |
     5 - 6 - 7 - 8 - 9
     |   |   |   |   |
     10- 11- 12- 13- 14
     |   |   |   |   |
     15- 16- 17- 18- 19
     |   |   |   |   |
     20- 21- 22- 23- 24
     """
     graph = retworkx.generators.grid_graph(5, 5)
     res = retworkx.num_shortest_paths_unweighted(graph, 0)
     expected = {
         1: 1,
         2: 1,
         3: 1,
         4: 1,
         5: 1,
         6: 2,
         7: 3,
         8: 4,
         9: 5,
         10: 1,
         11: 3,
         12: 6,
         13: 10,
         14: 15,
         15: 1,
         16: 4,
         17: 10,
         18: 20,
         19: 35,
         20: 1,
         21: 5,
         22: 15,
         23: 35,
         24: 70,
     }
     self.assertEqual(expected, res)
예제 #7
0
 def test__ne__different_length(self):
     self.assertTrue(
         retworkx.num_shortest_paths_unweighted(self.dag, 0) != {
             1: 1,
             2: 2
         })
예제 #8
0
 def test_iter(self):
     mapping_iter = iter(retworkx.num_shortest_paths_unweighted(
         self.dag, 0))
     output = list(mapping_iter)
     self.assertEqual(output, [1])
예제 #9
0
 def test_values(self):
     values = retworkx.num_shortest_paths_unweighted(self.dag, 0).values()
     self.assertEqual([1], list(values))
예제 #10
0
 def test_index_error(self):
     res = retworkx.num_shortest_paths_unweighted(self.dag, 0)
     with self.assertRaises(IndexError):
         res[42]
예제 #11
0
 def test_str(self):
     res = retworkx.num_shortest_paths_unweighted(self.dag, 0)
     self.assertEqual("NodesCountMapping{1: 1}", str(res))
예제 #12
0
 def test_deepcopy(self):
     paths = retworkx.num_shortest_paths_unweighted(self.dag, 0)
     paths_copy = copy.deepcopy(paths)
     self.assertEqual(paths, paths_copy)
예제 #13
0
 def test__eq__not_match_values(self):
     self.assertFalse(
         retworkx.num_shortest_paths_unweighted(self.dag, 0) == {1: 2})
예제 #14
0
 def test__eq__match(self):
     self.assertTrue(
         retworkx.num_shortest_paths_unweighted(self.dag, 0) == {1: 1})
예제 #15
0
 def test_no_edges(self):
     graph = retworkx.PyGraph()
     graph.add_node(0)
     graph.add_node(1)
     res = retworkx.num_shortest_paths_unweighted(graph, 0)
     self.assertEqual({}, res)
예제 #16
0
 def test__ne__invalid_type(self):
     self.assertTrue(
         retworkx.num_shortest_paths_unweighted(self.dag, 0) != ["a", None])
예제 #17
0
 def test__gt__not_implemented(self):
     with self.assertRaises(NotImplementedError):
         retworkx.num_shortest_paths_unweighted(self.dag, 0) > {1: 1}
예제 #18
0
 def test__eq__different_length(self):
     self.assertFalse(
         retworkx.num_shortest_paths_unweighted(self.dag, 0) == {
             1: 1,
             2: 2
         })
예제 #19
0
 def test_pickle(self):
     paths = retworkx.num_shortest_paths_unweighted(self.dag, 0)
     paths_pickle = pickle.dumps(paths)
     paths_copy = pickle.loads(paths_pickle)
     self.assertEqual(paths, paths_copy)
예제 #20
0
 def test_eq__same_type(self):
     self.assertEqual(
         retworkx.num_shortest_paths_unweighted(self.dag, 0),
         retworkx.num_shortest_paths_unweighted(self.dag, 0),
     )
예제 #21
0
 def test_hash(self):
     res = retworkx.num_shortest_paths_unweighted(self.dag, 0)
     hash_res = hash(res)
     self.assertIsInstance(hash_res, int)
     # Assert hash is stable
     self.assertEqual(hash_res, hash(res))
예제 #22
0
 def test__eq__invalid_type(self):
     self.assertFalse(
         retworkx.num_shortest_paths_unweighted(self.dag, 0) == ["a", None])
예제 #23
0
 def test_keys(self):
     keys = retworkx.num_shortest_paths_unweighted(self.dag, 0).keys()
     self.assertEqual([1], list(keys))
예제 #24
0
 def test__eq__invalid_inner_type(self):
     self.assertFalse(
         retworkx.num_shortest_paths_unweighted(self.dag, 0) == {0: "a"})
예제 #25
0
 def test_items(self):
     items = retworkx.num_shortest_paths_unweighted(self.dag, 0).items()
     self.assertEqual([(1, 1)], list(items))
예제 #26
0
 def test__ne__match(self):
     self.assertFalse(
         retworkx.num_shortest_paths_unweighted(self.dag, 0) != {1: 1})
예제 #27
0
 def test_not_contains(self):
     res = retworkx.num_shortest_paths_unweighted(self.dag, 0)
     self.assertNotIn(0, res)
예제 #28
0
 def test__ne__not_match_values(self):
     self.assertTrue(
         retworkx.num_shortest_paths_unweighted(self.dag, 0) != {1: 2})