com.rapatao.projects.ruleset.engine.helper.Helper.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tests Show documentation
Show all versions of tests Show documentation
Simple yet powerful rules engine that offers the flexibility of using the built-in engine and creating a custom one.
The newest version!
package com.rapatao.projects.ruleset.engine.helper
import com.rapatao.projects.ruleset.engine.Evaluator
import com.rapatao.projects.ruleset.engine.cases.TestData
import com.rapatao.projects.ruleset.engine.types.Expression
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
object Helper {
fun doEvaluationTest(evaluator: Evaluator, ruleSet: Expression, expected: Boolean) {
assertThat(
evaluator.evaluate(expression = ruleSet, inputData = TestData.inputData),
equalTo(expected)
)
}
fun compareMatcher(source: Expression, target: Expression) {
target.takeIf { it.parseable() }?.run {
assertThat(target.left, equalTo(source.left))
assertThat(target.operator, equalTo(source.operator))
assertThat(target.right, equalTo(source.right))
assertThat(target.onFailure, equalTo(source.onFailure))
}
compareMatcherList(source.allMatch, target.allMatch)
compareMatcherList(source.anyMatch, target.anyMatch)
compareMatcherList(source.noneMatch, target.noneMatch)
}
private fun compareMatcherList(source: List?, target: List?) {
assertThat(source?.size, equalTo(target?.size))
source?.forEachIndexed { index, matcher ->
compareMatcher(matcher, target!![index])
}
}
}