def test_digraph_graph_attrs(self): graph = retworkx.directed_gnp_random_graph(3, 0.9, seed=42) dot_str = graph.to_dot(lambda _: {}, lambda _: {}, {"bgcolor": "red"}) self.assertEqual( "digraph {\nbgcolor=red ;\n0 ;\n1 ;\n2 ;\n0 -> 1 ;\n" "0 -> 2 ;\n}\n", dot_str, )
def test_random_gnp_directed_invalid_probability(self): with self.assertRaises(ValueError): retworkx.directed_gnp_random_graph(23, 123.5)
def test_random_gnp_directed_invalid_num_nodes(self): with self.assertRaises(ValueError): retworkx.directed_gnp_random_graph(-23, .5)
def test_random_gnp_directed_complete_graph(self): graph = retworkx.directed_gnp_random_graph(20, 1) self.assertEqual(len(graph), 20) self.assertEqual(len(graph.edges()), 20 * (20 - 1))
def test_random_gnp_directed_empty_graph(self): graph = retworkx.directed_gnp_random_graph(20, 0) self.assertEqual(len(graph), 20) self.assertEqual(len(graph.edges()), 0)
def test_random_gnp_directed(self): graph = retworkx.directed_gnp_random_graph(20, .5, seed=10) self.assertEqual(len(graph), 20) self.assertEqual(len(graph.edges()), 104)
def setUp(self): super().setUp() if self.class_type == "PyGraph": self.graph = retworkx.undirected_gnp_random_graph(10, 0.5, seed=42) else: self.graph = retworkx.directed_gnp_random_graph(10, 0.5, seed=42)
def test_axes(self): fig, ax = plt.subplots() graph = retworkx.directed_gnp_random_graph(50, 0.75) mpl_draw(graph, ax=ax) _save_images(fig, "test_axes.png")
def test_random_graph_full_path(self): graph = retworkx.directed_gnp_random_graph(100, 0.95, seed=42) adjacency_matrix = retworkx.digraph_adjacency_matrix(graph) new_graph = retworkx.PyDiGraph.from_adjacency_matrix(adjacency_matrix) new_adjacency_matrix = retworkx.digraph_adjacency_matrix(new_graph) self.assertTrue(np.array_equal(adjacency_matrix, new_adjacency_matrix))
def test_digraph_no_args(self): graph = retworkx.directed_gnp_random_graph(3, .95, seed=24) dot_str = graph.to_dot() self.assertEqual("digraph {\n0 ;\n1 ;\n2 ;\n0 -> 1 ;\n0 -> 2 ;\n}\n", dot_str)
def test_digraph_empty_dicts(self): graph = retworkx.directed_gnp_random_graph(3, .9, seed=42) dot_str = graph.to_dot(lambda _: {}, lambda _: {}) self.assertEqual("digraph {\n0 ;\n1 ;\n2 ;\n0 -> 1 ;\n0 -> 2 ;\n}\n", dot_str)
def test_method(self): graph = retworkx.directed_gnp_random_graph(50, 0.8) image = graphviz_draw(graph, method="sfdp") self.assertIsInstance(image, PIL.Image.Image) _save_image(image, "test_graphviz_method.png")
def test_image_type(self): graph = retworkx.directed_gnp_random_graph(50, 0.8) image = graphviz_draw(graph, image_type="jpg") self.assertIsInstance(image, PIL.Image.Image) _save_image(image, "test_graphviz_draw_image_type.jpg")