Compare leaf values only of the same type to sort domain

Closes #12792
This commit is contained in:
Cédric Krier committed 2023-12-12 18:02:14 +01:00
1 parent f978cf0f73
commit 2b0d50afc4
5 files changed
+7 -13

No files matched your search

-4
View File
@@ -2438,10 +2438,6 @@
if (!domain.length) {
return [0, domain];
} else if (this.is_leaf(domain)) {
if (domain[2] === null) {
domain = domain.slice();
domain[2] = Number.NEGATIVE_INFINITY;
}
return [1, domain];
} else if (~['AND', 'OR'].indexOf(domain)) {
return [0, domain];
+3 -1
View File
@@ -3140,9 +3140,11 @@
['AND', ['bar', '=', 2], ['baz', '=', 3]]],
['OR', ['foo', '=', null], ['foo', '=', 1],
['AND', ['bar', '=', 2], ['baz', '=', 3]]]],
[[['foo', '=', 'bar'], ['foo', '=', null]],
[['foo', '=', 'bar'], ['foo', '=', null]]],
];
for (const [domain, expected] of tests) {
QUnit.deepEqual(expected, sort(domain));
QUnit.deepEqual(sort(domain), expected);
}
});
+1 -4
View File
@@ -288,10 +288,7 @@ def _sort_key(domain):
if not domain:
return (0, tuple())
elif is_leaf(domain):
if domain[2] is None:
domain = list(domain).copy()
domain[2] = float('-inf')
return (1, tuple(domain))
return (1, tuple((type(x).__name__, x) for x in domain))
elif domain in ['AND', 'OR']:
return (0, domain)
else:
+2
View File
@@ -1146,6 +1146,8 @@ class DomainInversionTestCase(unittest.TestCase):
['AND', ('bar', '=', 2), ('baz', '=', 3)]],
['OR', ('foo', '=', None), ('foo', '=', 1),
['AND', ('bar', '=', 2), ('baz', '=', 3)]]),
([('foo', '=', 'bar'), ('foo', '=', None)],
[('foo', '=', None), ('foo', '=', 'bar')]),
]:
with self.subTest(domain=domain):
self.assertEqual(sort(domain), expected)
+1 -4
View File
@@ -288,10 +288,7 @@ def _sort_key(domain):
if not domain:
return (0, tuple())
elif is_leaf(domain):
if domain[2] is None:
domain = list(domain).copy()
domain[2] = float('-inf')
return (1, tuple(domain))
return (1, tuple((type(x).__name__, x) for x in domain))
elif domain in ['AND', 'OR']:
return (0, domain)
else: