Skip to content

Commit

Permalink
Separate unit test for overlapping conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffmay committed Feb 21, 2022
1 parent 0c05312 commit f1a248e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
16 changes: 13 additions & 3 deletions core-v1/src/test/scala/SimpleJustifiedMatchSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,26 @@ class SimpleJustifiedMatchSpec extends FunSuite {
test("Expr.Match only evaluates the expression when the guard expression returns true") {
val expr = valuesOfType(FactTypes.RoleClass).filter {
_.matching(
Case[Author].when(_.get(_.select(_.articles)) < 5.const) ==> false.const,
Case[Author].when(_.get(_.select(_.articles)) > 4.const) ==> true.const,
Case[Author].when(_.get(_.select(_.articles)) >= 5.const) ==> true.const,
).getOrElse(false.const)
}
val matched = expr.run(FactTable(all))
val expected = Seq(admin, editor).map(v => Justified.byFact(FactTypes.RoleClass(v)))
assertEquals(matched, expected)
}

test("Expr.Match only evaluates the expression when the guard expression returns true") {
test("Expr.Match does not evaluate the expression when the guard expression returns false") {
val expr = valuesOfType(FactTypes.RoleClass).filter {
_.matching(
Case[Author].when(_.get(_.select(_.articles)) < 5.const) ==> true.const,
).getOrElse(false.const)
}
val matched = expr.run(FactTable(all))
val expected = Seq(author).map(v => Justified.byFact(FactTypes.RoleClass(v)))
assertEquals(matched, expected)
}

test("Expr.Match only evaluates overlapping guard expressions in sequence") {
val expr = valuesOfType(FactTypes.RoleClass).filter {
_.matching(
Case[Author].when(_.get(_.select(_.articles)) > 5.const) ==> false.const,
Expand Down
15 changes: 12 additions & 3 deletions core-v1/src/test/scala/SimpleMatchSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,24 @@ class SimpleMatchSpec extends FunSuite {
test("Expr.Match only evaluates the expression when the guard expression returns true") {
val expr = valuesOfType(FactTypes.RoleClass).filter {
_.matching(
Case[Author].when(_.get(_.select(_.articles)) < 5.const) ==> false.const,
Case[Author].when(_.get(_.select(_.articles)) > 4.const) ==> true.const,
Case[Author].when(_.get(_.select(_.articles)) >= 5.const) ==> true.const,
).getOrElse(false.const)
}
val matched = expr.run(FactTable(all))
assertEquals(matched, Seq(admin, editor))
}

test("Expr.Match only evaluates guard expressions in sequence") {
test("Expr.Match does not evaluate the expression when the guard expression returns false") {
val expr = valuesOfType(FactTypes.RoleClass).filter {
_.matching(
Case[Author].when(_.get(_.select(_.articles)) < 5.const) ==> true.const,
).getOrElse(false.const)
}
val matched = expr.run(FactTable(all))
assertEquals(matched, Seq(author))
}

test("Expr.Match only evaluates overlapping guard expressions in sequence") {
val expr = valuesOfType(FactTypes.RoleClass).filter {
_.matching(
Case[Author].when(_.get(_.select(_.articles)) > 5.const) ==> false.const,
Expand Down

0 comments on commit f1a248e

Please sign in to comment.