Unit tests for the core SMS++ library. Each test is registered as a separate
ctest target and exercises one of the core abstractions in isolation:
ClassFactory_testchecks the class factories used to constructBlock,Configuration,Solver,SolutionandStateobjects by name: each name is found, gives an object of the class asked for and of the sameclassname(), and a name that is not there throws.Configuration_unit_testcoversSimpleConfiguration,ComputeConfigwith its cascade override,BlockConfigandOCRBlockConfig, andBlockSolverConfig: read from text, written and read back in netCDF, cloned, got from aBlockand applied to another, and cleared; and, compared field by field, the pairs and the nestedSimpleConfiguration, the meta-configuration with the*file.txtand*file.txt +entries, theComputeConfigapplied to aThinComputeInterface, the ten slots of aBlockConfigand what itsprint()writes, the:BlockConfigwith the handlers of the Objective, of the Constraint and of the sub-Block, andRBlockSolverConfig.AbstractBlock_testcoversBlockandAbstractBlock: the groups it registers, the LP, MPS and certificate writers, the netCDF round trip of an emptyBlock, of dynamic groups, ofOneVarConstraint, of nestedBlockand of anObjectivethat is not linear (which is refused),set_objective()replacing anObjective,mirror()of an emptyBlock,read_lp()on an empty model, on constants and bounds at the edges of the format and on malformed input, and the edges of adding and removing dynamicVariableandConstraint(empty, reversed and out-of-rangeRange, empty and unorderedSubset, adding nothing, removing everything, lists in the cells of a vector) with theBlockModAddandBlockModRmv*each of them issues.ColVariable_testcoversVariableandColVariable.Constraint_unit_testcoversFRowConstraintwith aLinearFunction, with the value of a row of every sense, theRowConstraintModandFRowConstraintModit issues and the registration in theVariableof itsFunction, and theOneVarConstraintfamily, with the sides each of them fixes and the setters it refuses.LinearConstraint_unit_testcoversLinearConstraint, whose header no file of the library includes, so that the test is also what compiles it.Function_testcovers theFunctioninterface.LinearFunction_testcoversLinearFunction: its value and linearization, the changes of its Variable and coefficients, and theModificationit issues from anFRowConstraintor anFRealObjectiveof aBlock.DQuadFunction_testcoversDQuadFunction: its value, linearization and Hessian, the changes of its coefficients and of itsVariablebyRangeand bySubset, at their edges, and theModificationeach of them issues.QuadFunction_testcoversQuadFunctionandDQuadFunction, the latter both on its own and as the diagonal part of the former: value, gradient, Hessian, convexity, the changes of the coefficients and theModificationthey issue.C05SumFunction_testcoversC05SumFunction: the translation of theModificationof its members into its own, and its value and linearization as the sums of those of the members.AbstractPath_testcoversAbstractPath, and in particular its edges: empty ranges and subsets on the last node, indices out of range, paths toOneVarConstraint, paths after a dynamic removal and an empty vector of paths through netCDF.PolyhedralFunction_unit_testcoversPolyhedralFunction, i.e., its value and linearizations, the Modification each of its mutators issues, itsStateand its netCDF format, and the primal and dual abstract representations of aPolyhedralFunctionBlockkept in step with it; and the edges of every method taking aRangeor aSubset, the degenerate functions with no row or noVariable, the vertical rows, the names of the global pool, which follow the rows and theStateputs back, and the netCDF round trip of the vertical flags.PolyhedralFunctionBlock_unit_testcovers the size variable of aPolyhedralFunctionBlock, given before or after its abstract representation exists and kept in step by a change of the global scale.Group_testcovers the groups ofVariableandConstraintof aBlock, and the two consumers that copy them, theSolutionand the abstract copy of aBlock; also grids of rank 3 and with a zero extent, indices and names after a dynamic removal, groups asked for out of range and walks of empty groups.Modification_testcovers theModificationissued by the modifying methods ofColVariable,FRowConstraint, theOneVarConstraintfamily,FRealObjective,LinearFunctionand the dynamicVariableandConstraintof aBlock: whether the change is done and what is issued under each value of theModParam, with or without aSolverlistening and on a channel, and the type and content of theModification; and that under eDryRun the modifying methods of those classes and ofDQuadFunction,QuadFunction,PolyhedralFunction,LagBFunction,BendersBFunctionandC05SumFunctionchange nothing and issue nothing.BlockModification_unit_testcovers the Modification aBlockissues when dynamicVariableandConstraintare added and removed, the parameter that says if, how and where a Modification is issued, the channels that pack them into aGroupModification, and the way they reach theSolverof theBlockand of its ancestors.Objective_unit_testcoversObjectiveandFRealObjective: the change of sense, the replacement of theFunction, the Modification of theFunctionreaching theSolver, and the removal of itsVariable.Solution_testcovers what aSolutiondoes when the dynamicRowConstraintof theBlockit was read from are removed, i.e., the dual values it has to drop for whoever holds a dual solution to see whether what is left of it is still feasible; and the netCDF round trip ofRowConstraintSolutionandColRowSolution,clone(),scale(),sum(),is_direction()through all of them, the refusal to be written into aBlockof another shape, and the factory.LagBFunction_unit_testcoversLagBFunctionover a box inner Block solved byBoxSolver: an empty Lagrangian term, the term removed all at once and given again, the Modification these changes issue, the value and the linearizations against their closed form (on the kinks too), and the copy of the global pool a State holds; and the by-column representation of the Lagrangian term that the Lagrangian costs are computed from, asget_A_by_col()gives it, when the Lagrangian pairs are set (once or twice), added and removed (all of them, aRange, aSubset, a single one), and on the edge cases of those methods.BendersBFunction_unit_testcoversBendersBFunctionandBendersBlock: the rows added, modified and deleted with the Modification they issue, the sides written bycompute()over a box inner Block solved byBoxSolver, and the serialization with the matrix in dense and sparse form.Misc_unit_testcoversGlobalInformation,SimpleDataMapping,ChangeandGroupChange,BoxSolver(box LPs and QPs in both senses, empty boxes, unbounded directions, dual values),UpdateSolver, and what the baseSolverdoes by itself: registration, the queue of Modification and the tables of the parameters.NetCDF_testcovers the round trips through the netCDF format of the rows, the bounds and theFRealObjectiveof anAbstractBlock, of thePolyhedralFunctionBlock, of theBendersBFunctionwith its sub-Block and of theLagBFunctionwith its inner Block and its Lagrangian term, the empty cases included, the LP filesread_lp()has to refuse, and those of theStateof thePolyhedralFunction, of theBendersBFunctionand of theLagBFunction, both the one ofget_State()and the one written byserialize_State().
These are built and run through CMake / ctest (there is no makefile here);
all of them passing is a good sign that no regressions have been introduced
in the SMS++ core. A test is named <Component>_unit_test rather than
<Component>_test where the tests repository has a battery of tests with
the latter name (e.g., LagBFunction_test, PolyhedralFunction_test and
PolyhedralFunctionBlock_test), so that the two executables do not clash
in a build of the whole project.
The checks of a test are assert(), and they hold in every build type, the
Release one included: each test includes TestAssert.h after every header of
the library, which undefines NDEBUG for the test alone while the library
headers are read as the library was compiled.
-
Donato Meoli
Dipartimento di Informatica
Università di Pisa -
Niccolò Iardella
Dipartimento di Informatica
Università di Pisa -
Rafael Durbano Lobato
Dipartimento di Informatica
Università di Pisa -
Wim van Ackooij
EDF Lab Paris-Saclay
This code is provided free of charge under the GNU Lesser General Public License version 3.0, see the LICENSE file for details.