Remove extra operator when simplifying nested domains
issue11406 review390621002
This commit is contained in:
@@ -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]])
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user