Skip to content

Commit

Permalink
Add test that checks for regression in 3.9.1
Browse files Browse the repository at this point in the history
This test checks for the fix made in 5803d1.
  • Loading branch information
amolenaar committed Dec 21, 2022
1 parent 0448fa5 commit 2718f1c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gaphas/solver/solver.py
Expand Up @@ -133,6 +133,11 @@ def request_resolve_constraint(self, c: Constraint) -> None:
elif self._marked_cons.count(c) < self._resolve_limit:
self._marked_cons.append(c)

@property
def needs_solving(self) -> bool:
"""Return if there are constraints that need solving."""
return bool(self._marked_cons)

def solve(self) -> None: # sourcery skip: while-to-for
"""
Example:
Expand Down Expand Up @@ -164,6 +169,7 @@ def solve(self) -> None: # sourcery skip: while-to-for
>>> c._value
10.0
"""
# NB. marked_cons is updated during the solving process
marked_cons = self._marked_cons
notify = self._notify
try:
Expand Down
19 changes: 19 additions & 0 deletions tests/test_solver.py
Expand Up @@ -141,3 +141,22 @@ def handler(constraint):
solver.solve()

assert outer in events


def test_needs_solving():
solver = Solver()
a = Variable()
b = Variable()
eq = EqualsConstraint(a, b)

solver.add_constraint(eq)
assert solver.needs_solving

solver.solve()
assert not solver.needs_solving

a.value = 3
assert solver.needs_solving

solver.solve()
assert not solver.needs_solving

0 comments on commit 2718f1c

Please sign in to comment.