-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added ladder graph generators and test_ladder #705
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Licensed under the Apache License, | ||
|
||
import unittest | ||
|
||
import rustworkx | ||
|
||
|
||
class TestLadderGraph(unittest.TestCase): | ||
def test_ladder_graph(self): | ||
graph = rustworkx.generators.ladder_graph(20) | ||
self.assertEqual(len(graph), 40) | ||
IvanIsCoding marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.assertEqual(len(graph.edges()), 58) | ||
|
||
def test_ladder_graph_weights(self): | ||
graph = rustworkx.generators.ladder_graph(weights=list(range(40))) | ||
self.assertEqual(len(graph), 40) | ||
self.assertEqual([x for x in range(40)], graph.nodes()) | ||
self.assertEqual(len(graph.edges()), 58) | ||
Comment on lines
+12
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For these 2 tests it'd be good to add some assertion on the structure of the edges too. For example, if I built a circuit like: from rustworkx import rx
graph = rx.PyGraph()
graph.add_nodes_from(range(40))
graph.add_edges_from_no_data([(0, 1)*50) We should try to make the tests so they assert the structure of the created graph is correct and if it were to change by mistake on a future change to the code the test will fail if it's no longer a ladder graph. |
||
|
||
def test_ladder_no_weights_or_num(self): | ||
with self.assertRaises(IndexError): | ||
rustworkx.generators.ladder_graph() | ||
|
||
def test_zero_length_ladder_graph(self): | ||
graph = rustworkx.generators.ladder_graph(0) | ||
self.assertEqual(0, len(graph)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The syntax might not be correct, but the ladder graph is equivalent to a
n x 2
grid graph hence we probably want to reuse most of the other code