Skip to content

Commit

Permalink
Make negation normal form apply the propagated not statements in the …
Browse files Browse the repository at this point in the history
…leaf nodes (#1133)

This PR fixes this bug :
#1132
  • Loading branch information
uakyol authored Jul 26, 2023
1 parent 8d19b39 commit 0e31a95
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ object EventFilterValidator {
return if (negate) negate() else this
}
// Operative comparison node, valid statement that should not be altered.
return this
return if (negate) negate() else this
}

private fun getAst(celExpression: String, env: Env): Ast {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class EventFilterValidatorTest {
private val booleanVar = { name: String -> Decls.newVar(name, Decls.Bool) }
private val intVar = { name: String -> Decls.newVar(name, Decls.Int) }
private val stringVar = { name: String -> Decls.newVar(name, Decls.String) }

private fun bannerTemplateVar(): Decl {
return Decls.newVar(
"banner",
Expand Down Expand Up @@ -361,7 +362,7 @@ class EventFilterValidatorTest {
personTemplateVar(),
)
val expression = "!(person.gender == 2 && person.age_group == 1)"
val expectedNormalizedExpression = "person.gender == 2 || person.age_group == 1"
val expectedNormalizedExpression = "!(person.gender == 2) || !(person.age_group == 1)"

assertIgnoringId(compileToNormalForm(expression, env, OPERATIVE_FIELDS))
.isEqualTo(compile(expectedNormalizedExpression, env))
Expand All @@ -377,7 +378,7 @@ class EventFilterValidatorTest {

val expression =
"!(person.gender == 2 && person.age_group == 1) && " + "!(video.viewed_fraction > 0.25)"
val expectedNormalizedExpression = "(person.gender == 2 || person.age_group == 1) && true"
val expectedNormalizedExpression = "(!(person.gender == 2) || !(person.age_group == 1)) && true"

assertIgnoringId(compileToNormalForm(expression, env, OPERATIVE_FIELDS))
.isEqualTo(compile(expectedNormalizedExpression, env))
Expand All @@ -404,8 +405,8 @@ class EventFilterValidatorTest {
.trim()

val expectedNormalizedExpression =
"(person.gender == 2 && true) && (person.age_group == 1 && " +
"(person.age_group == 2 && ((true && true))) )"
"(!(person.gender == 2) && true) && (!(person.age_group == 1) && " +
"(!(person.age_group == 2) && ((true && true))) )"

assertIgnoringId(compileToNormalForm(expression, env, OPERATIVE_FIELDS))
.isEqualTo(compile(expectedNormalizedExpression, env))
Expand Down

0 comments on commit 0e31a95

Please sign in to comment.