[BUG] NOR expression + matchAny fails
Closed this issue · 2 comments
ZeLonewolf commented
Describe the bug
"NOR" logic fails to match when combining Expression.not
+ Expression.or
+ matchAny
. This issue is similar to #200 and is not corrected by the fix in #201.
To Reproduce
The following unit test added to MultiExpressionTest recreates this behavior:
@Test
void testNor() {
var index = MultiExpression.of(List.of(
entry("a", not(or(
matchAny("key1", "val1"),
matchAny("key2", "val2")
)))
)).index();
assertSameElements(List.of(), index.getMatches(featureWithTags("key1", "val1", "key2", "val2")));
assertSameElements(List.of(), index.getMatches(featureWithTags("key1", "val1", "key2", "val2", "key3", "val3")));
assertSameElements(List.of(), index.getMatches(featureWithTags("key1", "no", "key2", "val2")));
assertSameElements(List.of(), index.getMatches(featureWithTags("key1", "val1", "key2", "no")));
assertSameElements(List.of(), index.getMatches(featureWithTags("key1", "val1")));
assertSameElements(List.of(), index.getMatches(featureWithTags("key2", "val2")));
assertSameElements(List.of("a"), index.getMatches(featureWithTags()));
assertSameElements(List.of("a"), index.getMatches(featureWithTags("key1", "no", "key2", "no")));
}
The test case fails on the very last assertSameElements test.
Expected behavior
Test case pases
Environment (please complete the following information):
- Hardware: [HP Laptop]
- OS: [Windows 11]
- Java version and distribution: [Oracle JDK 17]
ZeLonewolf commented
While we're at it, a NAND operation fails also:
@Test
void testNand() {
var index = MultiExpression.of(List.of(
entry("a", not(and(
matchAny("key1", "val1"),
matchAny("key2", "val2")
)))
)).index();
assertSameElements(List.of(), index.getMatches(featureWithTags("key1", "val1", "key2", "val2")));
assertSameElements(List.of(), index.getMatches(featureWithTags("key1", "val1", "key2", "val2", "key3", "val3")));
assertSameElements(List.of("a"), index.getMatches(featureWithTags("key1", "no", "key2", "val2")));
assertSameElements(List.of("a"), index.getMatches(featureWithTags("key1", "val1", "key2", "no")));
assertSameElements(List.of("a"), index.getMatches(featureWithTags("key1", "val1")));
assertSameElements(List.of("a"), index.getMatches(featureWithTags("key2", "val2")));
assertSameElements(List.of("a"), index.getMatches(featureWithTags()));
}