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

RFC: unit tests #329

Merged
merged 10 commits into from
May 1, 2018
Merged

RFC: unit tests #329

merged 10 commits into from
May 1, 2018

Conversation

odow
Copy link
Member

@odow odow commented Apr 27, 2018

This PR adds some atomic tests that aim to minimally test each expected feature in addition to the full end-to-end tests in contlinear.jl etc.

It has already found a few bugs in LinQuadOptInterface that weren't following the API to the letter.

Bug fixes to existing tests

  • If we delete the variable as it was, we can't add the constraints.

Questions

- Should we enforce a default objective sense? Raised as separate issue #335

Other

Closes #244

@odow odow mentioned this pull request Apr 27, 2018
12 tasks
@codecov-io
Copy link

codecov-io commented Apr 27, 2018

Codecov Report

Merging #329 into master will decrease coverage by 1.68%.
The diff coverage is 31.65%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #329      +/-   ##
==========================================
- Coverage   96.47%   94.79%   -1.69%     
==========================================
  Files          31       34       +3     
  Lines        4537     4837     +300     
==========================================
+ Hits         4377     4585     +208     
- Misses        160      252      +92
Impacted Files Coverage Δ
src/MathOptInterface.jl 100% <ø> (ø) ⬆️
src/Test/UnitTests/constraints.jl 0% <0%> (ø)
src/Test/modellike.jl 100% <100%> (ø) ⬆️
src/Test/UnitTests/variables.jl 25% <25%> (ø)
src/Test/UnitTests/objectives.jl 50% <50%> (ø)
src/indextypes.jl 62.5% <50%> (ø) ⬆️
src/Utilities/parser.jl 97.59% <0%> (-0.86%) ⬇️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d9295f1...026c0e3. Read the comment docs.

@mlubin
Copy link
Member

mlubin commented Apr 27, 2018

Another reason to split these tests apart.

@odow odow changed the title Change order of tests Some more atomic tests Apr 28, 2018
@odow odow mentioned this pull request Apr 28, 2018
14 tasks
"""
This function tests adding a single variable.
"""
function add_variable(model::MOI.ModelLike, config::TestConfig)
Copy link
Member

Choose a reason for hiding this comment

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

It would be more consistent with the rest of the tests to call it addvariabletest

@blegat
Copy link
Member

blegat commented Apr 28, 2018

Should we enforce a default objective sense?

This is related to the question : Should a solver error if optimize! is called and ObjectiveSense has not been set or assume it is FeasibilitySense ?

@odow
Copy link
Member Author

odow commented Apr 29, 2018

I guess we can just leave each solver to have a default. Otherwise despite the backend having a default sense, every MOIWrapper will have to store a flag indicating whether the sense has been set.

@odow
Copy link
Member Author

odow commented Apr 29, 2018

I had to exclude a few of the atomic tests since MockOptimizer doesn't implement names.

@odow odow mentioned this pull request Apr 29, 2018
@odow odow changed the title Some more atomic tests RFC: some more atomic tests Apr 29, 2018
@blegat
Copy link
Member

blegat commented Apr 29, 2018

every MOIWrapper will have to store a flag indicating whether the sense has been set

Yes, that is the reason, we stay vague on this issue. ObjectiveSense will not appear in ListOfModelAttributesSet so it won't be used on copy! hence the value the model has is not critical.

@blegat
Copy link
Member

blegat commented Apr 29, 2018

I had to exclude a few of the atomic tests since MockOptimizer doesn't implement names.

Should be fixed in #336 :)

Test getting constraints by name.
"""
function getconstraint(model::MOI.ModelLike, config::TestConfig)
MOI.empty!(model)
Copy link
Member

Choose a reason for hiding this comment

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

It's weird that we have to call MOI.empty! at the beginning of every test. This should happen somewhere else.

Copy link
Member Author

Choose a reason for hiding this comment

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

MOI.empty!(model)
@test MOI.isempty(model)
MOIU.loadfromstring!(model,"""
variables: x
Copy link
Member

Choose a reason for hiding this comment

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

This is a great use of loadfromstring!

"""
Test constant in objective.
"""
function constant_obj(model::MOI.ModelLike, config::TestConfig)
Copy link
Member

Choose a reason for hiding this comment

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

If the test calls optimize!, I'd propose to have "solve" somewhere in the name, like solve_constant_obj. You could easily think that constant_obj would just set and get the objective attribute without solving.

atomictests["variablenames"] = variablenames

"""
Test the setting of an upper bound
Copy link
Member

Choose a reason for hiding this comment

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

Another example where "solve" in the name would be informative, e.g., solve_with_upperbound.

Copy link
Member

@mlubin mlubin left a comment

Choose a reason for hiding this comment

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

This is a big improvement for the tests. "Atomic" is a bit of a misnomer because some of the tests do more than one thing (e.g., delete_variables). You could call these small tests or unit tests.

@odow odow changed the title RFC: some more atomic tests RFC: unit tests Apr 30, 2018
"solve_with_lowerbound",
"solve_with_upperbound",
"getconstraint",
"getvariable",
Copy link
Member

@blegat blegat May 1, 2018

Choose a reason for hiding this comment

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

getconstraint, getvariable and variablenames should work now that #336 is merged.
You can test the solve tests with mock_optimize
https://github.com/JuliaOpt/MathOptInterface.jl/blob/da6e0910d382ce83b047991d0ba6c6bfece4ddc1/src/Utilities/mockoptimizer.jl#L271-L281
See https://github.com/JuliaOpt/MathOptInterface.jl/blob/master/test/contlinear.jl for example for using mock_optimize

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'm not sure that the mock optimizer implements the names correctly. I got some errors. I'm going to merge this as is, the outstanding tests can be addressed in later PR's.

unittests["variablenames"] = variablenames

"""
Test the setting of an upper bound
Copy link
Member

Choose a reason for hiding this comment

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

Also update the docstring to mention that the test calls optimize!.

unittests["solve_with_upperbound"] = solve_with_upperbound

"""
Test the setting of an lower bound
Copy link
Member

Choose a reason for hiding this comment

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

Same here

@odow odow merged commit cd3115d into master May 1, 2018
@odow odow deleted the odow/grb branch May 1, 2018 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants