#20323: Common TestSuite for MIP backends
-------------------------------------+-------------------------------------
Reporter: mkoeppe | Owner:
Type: enhancement | Status: needs_review
Priority: major | Milestone: sage-7.2
Component: numerical | Resolution:
Keywords: lp | Merged in:
Authors: | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
u/mkoeppe/common_testsuite_for_mip_backends|
65afba2d6bc7fdd31ea54e05845f5eb07b57fb5c
Dependencies: | Stopgaps:
-------------------------------------+-------------------------------------
Changes (by mkoeppe):
* status: new => needs_review
Comment:
There are two types of `_test_...` methods, which are illustrated by the
following examples:
{{{
## This test method is written as an instance method that works
## even if variables and constraints have already been added to the
backend.
## The test makes changes to the backend.
def _test_add_linear_constraints(self, **options):
"""
Run tests on the method :meth:`.add_linear_constraints`.
TESTS:
Test, with an actual working backend, that the test works even if
the problem
is not empty at the beginning::
sage: from sage.numerical.backends.generic_backend import
get_solver
sage: p = get_solver(solver='GLPK')
sage: p.add_variables(2)
1
sage: p.add_linear_constraint([[0, 17], [1, 89]], None, 42)
sage: p._test_add_linear_constraints()
"""
tester = self._tester(**options)
nrows_before = self.nrows()
nrows_added = 5
self.add_linear_constraints(nrows_added, None, 2)
nrows_after = self.nrows()
# Test correct number of rows
tester.assertEqual(nrows_after, nrows_before+nrows_added, "Added
the wrong number of rows")
# Test contents of the new rows are correct (sparse zero)
for i in range(nrows_before, nrows_after):
tester.assertEqual(self.row(i), ([], []))
tester.assertEqual(self.row_bounds(i), (None, 2.0))
## Any test methods involving calls to 'solve' are set up as class
methods,
## which make a fresh instance of the backend.
@classmethod
def _test_solve(cls, tester=None, **options):
"""
Trivial test for the solve method.
TEST::
sage: from sage.numerical.backends.generic_backend import
GenericBackend
sage: p = GenericBackend()
sage: p._test_solve()
Traceback (most recent call last):
...
NotImplementedError: ...
"""
p = cls() # fresh instance of the backend
if tester is None:
tester = p._tester(**options)
# From doctest of GenericBackend.solve:
tester.assertIsNone(p.add_linear_constraints(5, 0, None))
tester.assertIsNone(p.add_col(range(5), range(5)))
tester.assertEqual(p.solve(), 0)
tester.assertIsNone(p.objective_coefficient(0,1))
from sage.numerical.mip import MIPSolverException
#with tester.assertRaisesRegexp(MIPSolverException, "unbounded")
as cm: ## --- too specific
with tester.assertRaises(MIPSolverException) as cm: # unbounded
p.solve()
}}}
I've translated these from existing doctests (either from `GenericBackend`
or some real backend) by hand. `_test_solve` already reveals another bug
in the CVXOPT backend.
The plan is to use #20376 to semi-automatically add new `_test` methods.
--
Ticket URL: <http://trac.sagemath.org/ticket/20323#comment:13>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.