Repository navigation
Unit tests of Increasing and Decreasing - #135
Merged
Merged
Conversation
The functions Increasing() and Decreasing() of the section Constraints (Global) are tested together (the four orderings: increasing, strictly increasing, decreasing, strictly decreasing), as the previous global constraints: forms of the arguments, sizes, matrices, domains, holes, the examples of the documentation, the parameter lengths (integers, ranges, tuples, negative values, variables), expressions, the option -mini, groups, logical contexts, degenerated cases, XCSP3 files and invalid cases, each constraint being solved with ACE, CHOCO and cosoco and compared with brute force (semantics of ordered in XCSP3-core: x[i] + l[i] op x[i+1]). The known bugs are marked as expected failures, to be reported.
This was referenced Sep 29, 2026
…sing and Decreasing The provisional marks '(to be reported)' now give the issues: #136 to #140 for PyCSP3, and section 6 of chocoteam/choco-solver#1248 for CHOCO.
Decreasing(strict=True) used in a logical expression (~, |, &, imply(), either(), If()) raised AttributeError, because of the typo Strictly_DECREASING in ConstraintOrdered.to_list(). Fixes #136
…reasing() Increasing(None) and Decreasing(None) were silently ignored, and a number of lengths different from the number of terms minus 1 (or the number of terms, the last length being ignored) was reported by an assert without message. Explicit errors are now reported, as for AllEqual(None). Fixes #137
…wo terms With a single term, an element <ordered> with a single variable was generated, whereas the syntax requires at least two variables. With less than two terms, _ordered() now returns ConstraintDummyConstant(1), the terms being always ordered. So that such a constraint can still be used in a logical expression (Increasing(x[0]) | (x[1] == 1) was accepted before), the operator | of ConstraintDummyConstant now accepts 1 (true) and an expression as second operand, which also fixes NotAllEqual(x[0]) | (x[1] == 1). Fixes #138
…easing() The lengths mixing integers and variables generated an invalid element <lengths> (either all integers or all variables, according to XCSP3-core), on which the parser of ACE and CHOCO fails. An explicit error is now reported. Fixes #139
A term given several times was accepted; on x[0] op x[0], ACE fails, CHOCO accepts x[0] < x[0], and cosoco reports its own solution as invalid. An explicit error is now reported, as for AllDifferent() (#119): the variables are compared by identity (== being redefined for building expressions), and the expressions by their textual forms. Fixes #140
This was referenced Sep 29, 2026
This was referenced Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Unit tests of the constraints Increasing and Decreasing of the section Constraints (Global) of the API (https://pycsp.org/documentation/api/constraints-global/#Increasing and https://pycsp.org/documentation/api/constraints-global/#Decreasing), written as for the previous global constraints (#66, #130), with the same harness.
This PR adds tests (
pycsp3/tests/test_constraints_global_increasing_decreasing.py). The bugs found are reported in issues, and the tests concerned are marked as strict expected failures with the numbers of these issues. It also contains the fixes of #136 to #140 (8f8fcba, ad186a2, 289a264, 474d5ff, bb2b86a, one commit per issue), which remove the marks of these issues.Tests
Increasing()andDecreasing()post an element<ordered>with the operatorle,lt,georgt(withstrict=Trueforltandgt); according to XCSP3-core,ordered(X, L, ⊙)holds iffx[i] + l[i] ⊙ x[i+1]for eachi. Most tests are run for the four orderings. The tests cover:lengths: an integer, a list, a tuple, a range, zero or negative values, as many lengths as terms (the last one being ignored), variables, and integers mixed with variables;-mini(decomposition into intensional constraints);~,|,&,imply(),either());Each constraint is solved with ACE, CHOCO and cosoco, and all the solutions are compared with the ones computed by brute force.
test_constraints_global_increasing_decreasing.pytest_constraints_global_increasing_decreasing.pyWhole suite with the fixes (run locally, master not having moved since the creation of the branch): 3356 passed, 137 skipped and 224 expected failures, no failure. The 46 model files of PyCSP3-models using
Increasing()orDecreasing()(58 compilations, with their variants and at most two data files each) give the same results before and after the fixes, except two XCSP3 files where an element<ordered>with a single variable is no longer generated (#138): ProductShelves (toy.json) and Blackhole_z (example.json).Known bugs
Each issue has the labels
bug,unit-tests,Constraints (Global)and the labels of the functions (Increasing,Decreasing).Decreasing(strict=True)raisesAttributeErrorin a logical expression (typoStrictly_DECREASINGinConstraintOrdered.to_list())Noneis ignored, and lengths of a wrong size are reported by anassertwithout message<ordered>with a single variable (now no constraint;ConstraintDummyConstant.__or__extended accordingly)<lengths>(now forbidden)x[0] ⊙ x[0], ACE fails, CHOCO acceptsx[0] < x[0], and cosoco reports its own solution as invalid)orderedwith lengths, CHOCO orders the whole sequencex[0], x[0] + l[0], x[1], ..., which loses solutions for some lengthsDecisions: integers among the terms are refused (
TypeError: Wrong type for [x[0], 1, x[1]], accepted by the tests as an explicit error), and as many lengths as terms are tolerated (the last length being ignored).Cases not handled by the solvers
The constraints on symbolic variables are skipped (
orderedon symbolic variables is not part of XCSP3-core; 12 tests).