commonMain.it.unibo.tuprolog.solve.TestSolutionPresentationImpl.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of test-solve Show documentation
Show all versions of test-solve Show documentation
Common testing facilities for 2P-Kt-based logic solvers
package it.unibo.tuprolog.solve
import it.unibo.tuprolog.core.Var
import it.unibo.tuprolog.dsl.theory.logicProgramming
import kotlin.test.assertEquals
import kotlin.test.assertTrue
class TestSolutionPresentationImpl(private val solverFactory: SolverFactory) : TestSolutionPresentation {
override fun testSolutionWithDandlingVars() {
logicProgramming {
val theory =
theoryOf(
fact { "append"("seq"(X), X) },
)
val solver = solverFactory.solverOf(staticKb = theory)
val query = "append"(A, B)
val sol = solver.solveOnce(query)
assertTrue { sol is Solution.Yes }
assertTrue { setOf(A, B).all { it in sol.substitution.keys } }
assertTrue { sol.substitution[A]!! matches "seq"(`_`) }
assertEquals("X", (sol.substitution[B] as? Var)?.name)
}
}
}