-
Notifications
You must be signed in to change notification settings - Fork 5
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
Validate allocation input #972
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
764f23d
made an invalid model that misses edge between node
Jingru923 6965280
Merge branch 'main' into validate-allocation-input
Jingru923 df322b5
resolved comment non_positive_allocation_network_id()
Jingru923 e99ab09
resolved Bart's second round of comments
Jingru923 b4da2e8
Merge branch 'main' into validate-allocation-input
Jingru923 9f7a396
remove unnecessary comment
Jingru923 27e217b
Merge branch 'validate-allocation-input' of https://github.com/Deltar…
Jingru923 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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,89 @@ | ||
@testitem "Non-positive allocation network ID" begin | ||
using MetaGraphsNext | ||
using Graphs | ||
using Logging | ||
using Ribasim | ||
using Accessors: @set | ||
|
||
graph = MetaGraph( | ||
DiGraph(); | ||
label_type = Ribasim.NodeID, | ||
vertex_data_type = Ribasim.NodeMetadata, | ||
edge_data_type = Symbol, | ||
graph_data = Tuple, | ||
) | ||
|
||
graph[Ribasim.NodeID(1)] = Ribasim.NodeMetadata(Symbol(:delft), 1) | ||
graph[Ribasim.NodeID(2)] = Ribasim.NodeMetadata(Symbol(:denhaag), -1) | ||
|
||
graph[1, 2] = :yes | ||
|
||
node_ids = Dict{Int, Set{Ribasim.NodeID}}() | ||
node_ids[0] = Set{Ribasim.NodeID}() | ||
node_ids[-1] = Set{Ribasim.NodeID}() | ||
push!(node_ids[0], Ribasim.NodeID(1)) | ||
push!(node_ids[-1], Ribasim.NodeID(2)) | ||
|
||
graph_data = (; node_ids,) | ||
graph = @set graph.graph_data = graph_data | ||
|
||
logger = TestLogger() | ||
with_logger(logger) do | ||
Ribasim.non_positive_allocation_network_id(graph) | ||
end | ||
|
||
@test length(logger.logs) == 2 | ||
@test logger.logs[1].level == Error | ||
@test logger.logs[1].message == | ||
"Allocation network id 0 needs to be a positive integer." | ||
@test logger.logs[2].level == Error | ||
@test logger.logs[2].message == | ||
"Allocation network id -1 needs to be a positive integer." | ||
end | ||
|
||
@testitem "Incomplete subnetwork" begin | ||
using MetaGraphsNext | ||
using Graphs | ||
using Logging | ||
using Ribasim | ||
|
||
graph = MetaGraph( | ||
DiGraph(); | ||
label_type = Ribasim.NodeID, | ||
vertex_data_type = Ribasim.NodeMetadata, | ||
edge_data_type = Symbol, | ||
graph_data = Tuple, | ||
) | ||
|
||
node_ids = Dict{Int, Set{Ribasim.NodeID}}() | ||
node_ids[1] = Set{Ribasim.NodeID}() | ||
push!(node_ids[1], Ribasim.NodeID(1)) | ||
push!(node_ids[1], Ribasim.NodeID(2)) | ||
push!(node_ids[1], Ribasim.NodeID(3)) | ||
node_ids[2] = Set{Ribasim.NodeID}() | ||
push!(node_ids[2], Ribasim.NodeID(4)) | ||
push!(node_ids[2], Ribasim.NodeID(5)) | ||
push!(node_ids[2], Ribasim.NodeID(6)) | ||
|
||
graph[Ribasim.NodeID(1)] = Ribasim.NodeMetadata(Symbol(:delft), 1) | ||
graph[Ribasim.NodeID(2)] = Ribasim.NodeMetadata(Symbol(:denhaag), 1) | ||
graph[Ribasim.NodeID(3)] = Ribasim.NodeMetadata(Symbol(:rdam), 1) | ||
graph[Ribasim.NodeID(4)] = Ribasim.NodeMetadata(Symbol(:adam), 2) | ||
graph[Ribasim.NodeID(5)] = Ribasim.NodeMetadata(Symbol(:utrecht), 2) | ||
graph[Ribasim.NodeID(6)] = Ribasim.NodeMetadata(Symbol(:leiden), 2) | ||
|
||
graph[Ribasim.NodeID(1), Ribasim.NodeID(2)] = :yes | ||
graph[Ribasim.NodeID(1), Ribasim.NodeID(3)] = :yes | ||
graph[4, 5] = :yes | ||
|
||
logger = TestLogger() | ||
|
||
with_logger(logger) do | ||
errors = Ribasim.incomplete_subnetwork(graph, node_ids) | ||
@test errors == true | ||
end | ||
|
||
@test length(logger.logs) == 1 | ||
@test logger.logs[1].level == Error | ||
@test logger.logs[1].message == "All nodes in subnetwork 2 should be connected" | ||
end |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Regarding this test: It is good practice to create your own test model to do this, but I thought of an easier way: load the parameters of an existing model, say
remove an edge to make it invalid and run your validation test on that.
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.
This morning I tried to load an existing model and change one of the allocation id to negative number. It gave error saying the immutable struct of type cannot be changed. I remembered you mentioned this yesterday, it probably can't be changed or maybe I didn't do it the correct way. Anyhow, in my new code I created a graph that has the required feature and used it as the test model.