Skip to content
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

Add Base.@kwdef to all system-related structs #19

Merged
merged 8 commits into from
Jul 21, 2022
Merged

Conversation

raphaelsaavedra
Copy link
Member

This makes it easier to keep track of arguments when using these structs, as some of them have many arguments.

@codecov
Copy link

codecov bot commented Jul 19, 2022

Codecov Report

Merging #19 (a79c549) into main (eb5b435) will increase coverage by 0.40%.
The diff coverage is 85.71%.

@@            Coverage Diff             @@
##             main      #19      +/-   ##
==========================================
+ Coverage   79.59%   80.00%   +0.40%     
==========================================
  Files           2        2              
  Lines          98      105       +7     
==========================================
+ Hits           78       84       +6     
- Misses         20       21       +1     
Impacted Files Coverage Δ
src/system.jl 53.48% <85.71%> (+6.26%) ⬆️

@nickrobinson251
Copy link
Contributor

Closes #7

Needs tests :)

@raphaelsaavedra
Copy link
Member Author

Needs tests :)

My plan was to create fake structs using the kwargs and test that they're equal to the ones not using kwargs, but that would require AutoHashEquals... is there another simple way of testing this?

@nickrobinson251
Copy link
Contributor

we just need to test these methods exist

perhaps just @test Zone(; number=1, ...) isa Zone or z = Zone(; number=1, ...); @test z.number=1

@raphaelsaavedra
Copy link
Member Author

The result was a bit ugly (circa 100 lines of code), but I covered all structs

@raphaelsaavedra
Copy link
Member Author

Hmm, I think I'll need to do it a bit differently for Branch to avoid having to always define the transformer-only fields e.g. tap

break_points,
penalties,
resistance,
reactance,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should resistance and reactance have defaults too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, can't see any specific reason to have default values for these

src/system.jl Outdated
penalties,
resistance,
reactance,
is_transformer=false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the behaviour of the current constructors is that is_transformer is true if tap and angle are non-missing

perhaps that's the behaviour we should match here too?
perhaps remove is_transformer as a keyword and have something like

if ismissing(tap) && ismissing(angle) 
    is_transformer = false
elseif !ismissing(tap) && !ismissing(angle) 
    is_transformer = true
else
    ArgumentError("Transformers must have non-missing values for both `tap` and `angle`. Got `tap=$tap, angle=$angle`.")

?

Alternatively perhaps the constructors here are overly complex and we should check which are used in practice to see if we need them all ?

@nickrobinson251
Copy link
Contributor

The result was a bit ugly (circa 100 lines of code), but I covered all structs

I suppose an alternative is to update the existing tests to use the new syntax e.g.

- zone1 = Zone(1, 1.0, 1.0, 1.0)
+ zone1 = Zone(number=1, regulation=1.0, etc1=1.0, etc2=1.0)

@raphaelsaavedra
Copy link
Member Author

Does this look good to you now @nickrobinson251?

Copy link
Contributor

@nickrobinson251 nickrobinson251 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think of update the existing tests to use the new syntax rather than adding a bunch of more tests?

I also wonder if we should open an issue about reviewing which Brnach constructors are necessary - what do you think?

Otherwise LGTM

@raphaelsaavedra
Copy link
Member Author

what do you think of update the existing tests to use the new syntax rather than adding a bunch of more tests?

I was thinking that the current way covers both cases – but in the end I think we get the same coverage if we update the existing ones? I can do that

@nickrobinson251
Copy link
Contributor

thanks - LGTM!

@raphaelsaavedra
Copy link
Member Author

Had a test failing due to resistance, reactance having default values, which I'm not sure should be the case. I'll leave this unchanged in this PR; opened #21 to track it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants