Remove extra operator when simplifying nested domains

issue11406
review390621002
This commit is contained in:
Nicolas Évrard
2022-04-14 10:21:54 +02:00
parent 69b60e4571
commit 86534e2116
2 changed files with 12 additions and 2 deletions
+5
View File
@@ -570,6 +570,11 @@ class DomainInversionTestCase(unittest.TestCase):
self.assertEqual(
simplify(domain), ['OR', ['x', '=', 3], ['y', '=', 5]])
domain = ['OR', ('x', '=', 1), ['OR', ('x', '=', 2), ('x', '=', 3)]]
self.assertEqual(
simplify(domain),
['OR', ('x', '=', 1), ('x', '=', 2), ('x', '=', 3)])
domain = [['x', '=', 3], ['OR']]
self.assertEqual(simplify(domain), [['x', '=', 3]])
+7 -2
View File
@@ -307,9 +307,14 @@ def simplify_nested(domain):
domain_op = bool_operator(domain)
for branch in domain:
simplified_branch = simplify_nested(branch)
if (bool_operator(branch) == domain_op
if (bool_operator(simplified_branch) == domain_op
or len(simplified_branch) == 1):
simplified.extend(simplified_branch)
if (simplified
and simplified_branch
and simplified_branch[0] in ['AND', 'OR']):
simplified.extend(simplified_branch[1:])
else:
simplified.extend(simplified_branch)
else:
simplified.append(simplified_branch)
return simplified