-
Notifications
You must be signed in to change notification settings - Fork 10
feat: iterate over shortest path #155
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
base: main
Are you sure you want to change the base?
Changes from all commits
28f8e3e
102c280
ff85f14
5baeaf7
1761bb8
a4a1c0e
5cdbb67
d5e2c8f
c98798a
42ec97a
8baba8d
0e681c6
441e2c5
5c3734b
6e15083
5277f52
06ab70f
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 | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -71,6 +71,31 @@ def test_get_branches_in_path_empty_path(self, basic_grid): | |||||||||||||||||||||||||||
| assert 0 == branches.size | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| class TestIterBranchesInShortestPath: | ||||||||||||||||||||||||||||
| def test_iter_branches_in_shortest_path_returns_branch_arrays(self, basic_grid): | ||||||||||||||||||||||||||||
| branches = list(basic_grid.iter_branches_in_shortest_path(101, 106)) | ||||||||||||||||||||||||||||
| assert branches == [basic_grid.branches.filter(id=201), basic_grid.branches.filter(id=301)] | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def test_iter_branches_in_shortest_path_three_winding_transformer(self, grid_with_3wt): | ||||||||||||||||||||||||||||
| branches = list(grid_with_3wt.iter_branches_in_shortest_path(101, 104)) | ||||||||||||||||||||||||||||
| assert len(branches) == 2 | ||||||||||||||||||||||||||||
| assert branches[0].id.item() == 301 | ||||||||||||||||||||||||||||
| assert branches[0].from_node.item() == 101 | ||||||||||||||||||||||||||||
| assert branches[0].to_node.item() == 102 | ||||||||||||||||||||||||||||
| assert branches[1] == grid_with_3wt.branches.filter(id=201) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def test_iter_branches_same_node_returns_empty(self, basic_grid): | ||||||||||||||||||||||||||||
| assert [] == list(basic_grid.iter_branches_in_shortest_path(101, 101)) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def test_iter_branches_in_shortest_path_typed(self, basic_grid): | ||||||||||||||||||||||||||||
| branches = list(basic_grid.iter_branches_in_shortest_path(101, 106, typed=True)) | ||||||||||||||||||||||||||||
| assert branches == [basic_grid.line.filter(id=201), basic_grid.transformer.filter(id=301)] | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def test_iter_branches_in_shortest_path_three_winding_transformer_typed(self, grid_with_3wt): | ||||||||||||||||||||||||||||
| branches = list(grid_with_3wt.iter_branches_in_shortest_path(101, 104, typed=True)) | ||||||||||||||||||||||||||||
| assert branches == [grid_with_3wt.three_winding_transformer.filter(id=301), grid_with_3wt.line.filter(id=201)] | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
Comment on lines
+97
to
+98
|
||||||||||||||||||||||||||||
| def test_iter_branches_in_shortest_path_missing_branch_raises(self, basic_grid, monkeypatch): | |
| # Simulate an inconsistent state where the graph reports a path but | |
| # there is no active branch between consecutive nodes in that path. | |
| def fake_get_shortest_path(*args, **kwargs): | |
| # Return a path with a node pair that has no active branch | |
| return [101, 999], 1 | |
| monkeypatch.object(basic_grid.graphs.active_graph, "get_shortest_path", fake_get_shortest_path) | |
| with pytest.raises(Exception): | |
| list(basic_grid.iter_branches_in_shortest_path(101, 999)) |
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.
I'd rather have _private functions below the functions that use them. This is also suggested in the book "Clean Code"