Skip to content

Commit

Permalink
refactor: Group test cases by operation
Browse files Browse the repository at this point in the history
Group the test cases by their list operation to have a better overview.
  • Loading branch information
saig0 committed Aug 23, 2024
1 parent 5985552 commit 65cf32d
Showing 1 changed file with 80 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,89 @@ class InterpreterListExpressionTest
with FeelEngineTest
with EvaluationResultMatchers {

"A list" should "be checked with 'some'" in {
"A list" should "contain null if a variable doesn't exist" in {
evaluateExpression("[1, x]") should returnResult(List(1, null))
}

it should "be compared with '='" in {
evaluateExpression("[] = []") should returnResult(true)
evaluateExpression("[1] = [1]") should returnResult(true)
evaluateExpression("[[1]] = [[1]]") should returnResult(true)
evaluateExpression("[{x:1}] = [{x:1}]") should returnResult(true)

evaluateExpression("[] = [1]") should returnResult(false)
evaluateExpression("[1] = []") should returnResult(false)
evaluateExpression("[1] = [2]") should returnResult(false)
evaluateExpression("[[1]] = [[2]]") should returnResult(false)
evaluateExpression("[{x:1}] = [{x:2}]") should returnResult(false)

evaluateExpression("[1] = [true]") should returnResult(false)
}

it should "be compared with '!='" in {
evaluateExpression("[] != []") should returnResult(false)
evaluateExpression("[1] != [1]") should returnResult(false)
evaluateExpression("[[1]] != [[1]]") should returnResult(false)
evaluateExpression("[{x:1}] != [{x:1}]") should returnResult(false)

evaluateExpression("[] != [1]") should returnResult(true)
evaluateExpression("[1] != []") should returnResult(true)
evaluateExpression("[1] != [2]") should returnResult(true)
evaluateExpression("[[1]] != [[2]]") should returnResult(true)
evaluateExpression("[{x:1}] != [{x:2}]") should returnResult(true)

evaluateExpression("[1] != [true]") should returnResult(true)
}

it should "be accessed and compared" in {
evaluateExpression("[1][1] = 1") should returnResult(true)
}

it should "return null if compare to not a list" in {
evaluateExpression("[] = 1") should (returnNull() and reportFailure(
failureType = EvaluationFailureType.NOT_COMPARABLE,
failureMessage = "Can't compare '[]' with '1'"
))
}

"A some-expression" should "return true if one item satisfies the condition" in {

evaluateExpression("some x in [1,2,3] satisfies x > 2") should returnResult(true)
evaluateExpression("some x in [1,2,3] satisfies x > 3") should returnResult(false)

evaluateExpression(
expression = "some x in xs satisfies x > 2",
expression = "some x in xs satisfies x > 1",
variables = Map("xs" -> List(1, 2, 3))
) should returnResult(true)

evaluateExpression(
expression = "some x in xs satisfies x > 2",
variables = Map("xs" -> List(1, 2))
) should returnResult(false)
expression = "some x in xs satisfies count(xs) > 2",
variables = Map("xs" -> List(1, 2, 3))
) should returnResult(true)

evaluateExpression("some x in [1,2], y in [2,3] satisfies x < y") should returnResult(true)
}

it should "return false if no item satisfies the condition" in {

evaluateExpression("some x in [1,2,3] satisfies x > 3") should returnResult(false)

evaluateExpression(
expression = "some x in xs satisfies count(xs) > 2",
expression = "some x in xs satisfies x > 2",
variables = Map("xs" -> List(1, 2))
) should returnResult(false)

evaluateExpression("some x in [1,2], y in [2,3] satisfies x < y") should returnResult(true)
evaluateExpression("some x in [1,2], y in [1,1] satisfies x < y") should returnResult(false)
}

it should "be checked with 'some' (range)" in {
it should "return true if the range satisfies the condition" in {
evaluateExpression("some x in 1..5 satisfies x > 3") should returnResult(true)
}

it should "return null if the value is not a list (some)" in {
it should "return false if the range doesn't satisfy the condition" in {
evaluateExpression("some x in 1..5 satisfies x > 10") should returnResult(false)
}

it should "return null if the value is not a list" in {
evaluateExpression(
expression = "some item in x satisfies x > 10"
) should (returnNull() and reportFailure(
Expand All @@ -80,30 +134,39 @@ class InterpreterListExpressionTest
))
}

it should "be checked with 'every'" in {
"An every-expression" should "return true if all items satisfy the condition" in {

evaluateExpression("every x in [1,2,3] satisfies x >= 1") should returnResult(true)
evaluateExpression("every x in [1,2,3] satisfies x >= 2") should returnResult(false)

evaluateExpression(
expression = "every x in xs satisfies x >= 1",
variables = Map("xs" -> List(1, 2, 3))
) should returnResult(true)

evaluateExpression("every x in [1,2], y in [3,4] satisfies x < y") should returnResult(true)
}

it should "return false if one item doesn't satisfy the condition" in {

evaluateExpression("every x in [1,2,3] satisfies x >= 2") should returnResult(false)

evaluateExpression(
expression = "every x in xs satisfies x >= 1",
variables = Map("xs" -> List(0, 1, 2, 3))
) should returnResult(false)

evaluateExpression("every x in [1,2], y in [3,4] satisfies x < y") should returnResult(true)
evaluateExpression("every x in [1,2], y in [2,3] satisfies x < y") should returnResult(false)
}

it should "be checked with 'every' (range)" in {
it should "return true if the range satisfies the condition" in {
evaluateExpression("every x in 1..5 satisfies x < 10") should returnResult(true)
}

it should "return null if the value is not a list (every)" in {
it should "return false if the range doesn't satisfy the condition" in {
evaluateExpression("every x in 1..10 satisfies x < 5") should returnResult(false)
}

it should "return null if the value is not a list" in {
evaluateExpression(
expression = "every item in x satisfies x > 10"
) should (returnNull() and reportFailure(
Expand All @@ -120,8 +183,7 @@ class InterpreterListExpressionTest
))
}

it should "be processed in a for-expression" in {

"A for-expression" should "iterate over a list" in {
evaluateExpression("for x in [1,2] return x * 2") should returnResult(
List(2, 4)
)
Expand All @@ -141,58 +203,7 @@ class InterpreterListExpressionTest
) should returnResult(List(List.empty, List(1)))
}

it should "be processed in a for-expression (range)" in {
evaluateExpression("for x in 1..3 return x") should returnResult(
List(1, 2, 3)
)
}

it should "contain null if a variable doesn't exist" in {
evaluateExpression("[1, x]") should returnResult(List(1, null))
}

it should "be compared with '='" in {
evaluateExpression("[] = []") should returnResult(true)
evaluateExpression("[1] = [1]") should returnResult(true)
evaluateExpression("[[1]] = [[1]]") should returnResult(true)
evaluateExpression("[{x:1}] = [{x:1}]") should returnResult(true)

evaluateExpression("[] = [1]") should returnResult(false)
evaluateExpression("[1] = []") should returnResult(false)
evaluateExpression("[1] = [2]") should returnResult(false)
evaluateExpression("[[1]] = [[2]]") should returnResult(false)
evaluateExpression("[{x:1}] = [{x:2}]") should returnResult(false)

evaluateExpression("[1] = [true]") should returnResult(false)
}

it should "be compared with '!='" in {
evaluateExpression("[] != []") should returnResult(false)
evaluateExpression("[1] != [1]") should returnResult(false)
evaluateExpression("[[1]] != [[1]]") should returnResult(false)
evaluateExpression("[{x:1}] != [{x:1}]") should returnResult(false)

evaluateExpression("[] != [1]") should returnResult(true)
evaluateExpression("[1] != []") should returnResult(true)
evaluateExpression("[1] != [2]") should returnResult(true)
evaluateExpression("[[1]] != [[2]]") should returnResult(true)
evaluateExpression("[{x:1}] != [{x:2}]") should returnResult(true)

evaluateExpression("[1] != [true]") should returnResult(true)
}

it should "be accessed and compared" in {
evaluateExpression("[1][1] = 1") should returnResult(true)
}

it should "return null if compare to not a list" in {
evaluateExpression("[] = 1") should (returnNull() and reportFailure(
failureType = EvaluationFailureType.NOT_COMPARABLE,
failureMessage = "Can't compare '[]' with '1'"
))
}

"A for-expression" should "iterate over a range" in {
it should "iterate over a range" in {
evaluateExpression("for x in 1..3 return x * 2") should returnResult(List(2, 4, 6))

evaluateExpression("for x in 1..n return x * 2", Map("n" -> 3)) should returnResult(
Expand Down

0 comments on commit 65cf32d

Please sign in to comment.