Check that all PACs are inputs or outputs#273
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files☔ View full report in Codecov by Sentry. |
alexdewar
left a comment
There was a problem hiding this comment.
This is great, especially for your first Rust PR! Good job.
I've made a small suggestion about the test (mutable variables can be a source of errors) and a few comments, but otherwise this is all good.
AdrianDAlessandro
left a comment
There was a problem hiding this comment.
I haven't dug into the logic inside the loops, but have some macro-level questions
| } | ||
|
|
||
| #[derive(PartialEq, Debug, Deserialize)] | ||
| #[derive(PartialEq, Debug, Deserialize, Clone)] |
There was a problem hiding this comment.
Is this Clone (and the one above) only added for the tests? I'm not sure if we want to make the structs clone-able just for the testing, it opens up cloning as an option in other parts of the code, which we maybe don't want? @alexdewar
There was a problem hiding this comment.
I hadn't really thought about it from that perspective, but that's an interesting thought. I don't think we'll want instances of these objects outside of the input layer, either with "clone()" or "new()". That said, I think we can catch this kind of broken code at review time.
You possibly could make it a test-only feature by doing something like this:
#[cfg(test)])
#[derive(Clone)]
#[derive(PartialEq, Debug, Deserialize)]
Not sure it's worth the effort though.
dalonsoa
left a comment
There was a problem hiding this comment.
The logic looks fine, but I'd extract the validation as a separate function to improve the readability and the encapsulation of specific functionality.
Description
This adds a check in
read_process_pacs_from_iterto make sure the PACs for each process are either all inputs or all outputs.I do this by looping through the processes and creating a flag
current_flow_signwhich is compared against the commodity flow for each PAC (positive flows represent outputs, negative flows represent inputs). Implicit is the assumption that flows cannot be zero - I don't think we actually have this check anywhere, we we should add this in.This required passing
flowsto this function and alsoread_process_pacs. I had to modify all the tests accordingly, and have added a new test.Fixes #165
Type of change
Key checklist
$ cargo test$ cargo docFurther checks