-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added empty and complete graph generators (#679)
* added empty and complete generators * cargo fmt fix * updated `empty_graph` and added `reno` * updated reno Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
bc945c9
commit c817aa1
Showing
5 changed files
with
245 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
releasenotes/notes/empty-and-complete-09d569b42cb6b9d5.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
features: | ||
- | | ||
Added new generator functions, :func:`~rustworkx.generators.empty_graph`, | ||
and :func:`~rustworkx.generators.directed_empty_graph` to the | ||
``rustworkx.generators`` module that will generate an empty graph. | ||
For example: | ||
.. jupyter-execute:: | ||
import rustworkx.generators | ||
from rustworkx.visualization import mpl_draw | ||
graph = rustworkx.generators.empty_graph(4) | ||
mpl_draw(graph) | ||
- | | ||
Added new generator functions, :func:`~rustworkx.generators.complete_graph`, | ||
and :func:`~rustworkx.generators.directed_complete_graph` to the | ||
``rustworkx.generators`` module that will generate a complete graph. | ||
These functions are equivalent to calling the :func:`~rustworkx.generators.mesh_graph` | ||
and :func:`~rustworkx.generators.directed_mesh_graph` functions. | ||
For example: | ||
.. jupyter-execute:: | ||
import rustworkx.generators | ||
from rustworkx.visualization import mpl_draw | ||
graph = rustworkx.generators.complete_graph(4) | ||
mpl_draw(graph) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import unittest | ||
|
||
import rustworkx | ||
|
||
|
||
class TestCompleteGraph(unittest.TestCase): | ||
def test_complete_graph(self): | ||
for m in [0, 1, 3, 5]: | ||
graph = rustworkx.generators.complete_graph(m) | ||
self.assertEqual(len(graph), m) | ||
self.assertEqual(len(graph.edges()), m * (m - 1) / 2) | ||
|
||
def test_complete_directed_graph(self): | ||
for m in [0, 1, 3, 5]: | ||
graph = rustworkx.generators.directed_complete_graph(m) | ||
self.assertEqual(len(graph), m) | ||
self.assertEqual(len(graph.edges()), m * (m - 1)) | ||
self.assertIsInstance(graph, rustworkx.PyDiGraph) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import unittest | ||
|
||
import rustworkx | ||
|
||
|
||
class TestEmptyGraph(unittest.TestCase): | ||
def test_empty_graph(self): | ||
graph = rustworkx.generators.empty_graph(20) | ||
self.assertEqual(len(graph), 20) | ||
self.assertEqual(len(graph.edges()), 0) | ||
|
||
def test_empty_directed_graph(self): | ||
graph = rustworkx.generators.directed_empty_graph(20) | ||
self.assertEqual(len(graph), 20) | ||
self.assertEqual(len(graph.edges()), 0) | ||
self.assertIsInstance(graph, rustworkx.PyDiGraph) |