Skip to content

Commit

Permalink
update tests for member/2, showing that 92 is fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
gciatto committed Jun 20, 2020
1 parent bc2fafa commit 3c2312f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,20 @@ object CustomTheories {
)
}
}

val memberGoalToSolution by lazy {
prolog {
ktListOf(
"member"("X", listOf("a", "b", "c")).hasSolutions(
{ yes("X" to "a") },
{ yes("X" to "b") },
{ yes("X" to "c") },
{ no() }
),
"member"("f"("X"), listOf("a"(1), "b"(2), "c"(3))).hasSolutions(
{ no() }
)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import it.unibo.tuprolog.solve.CustomTheories.ifThenElse1ToSolution
import it.unibo.tuprolog.solve.CustomTheories.ifThenElse2ToSolution
import it.unibo.tuprolog.solve.CustomTheories.ifThenTheory1
import it.unibo.tuprolog.solve.CustomTheories.ifThenTheory2
import it.unibo.tuprolog.solve.CustomTheories.memberGoalToSolution
import it.unibo.tuprolog.solve.PrologStandardExampleTheories.callStandardExampleTheory
import it.unibo.tuprolog.solve.PrologStandardExampleTheories.callStandardExampleTheoryGoalsToSolution
import it.unibo.tuprolog.solve.PrologStandardExampleTheories.catchAndThrowTheoryExample
Expand Down Expand Up @@ -855,26 +856,11 @@ internal class SolverTestImpl(private val solverFactory: SolverFactory) : Solver
}
}

private fun <T> ktListConcat(l1: List<T>, l2: List<T>): List<T> = l1 + l2

override fun testMember() {
prolog {
val solver = solverFactory.solverWithDefaultBuiltins()

val constants = ktListOf("a", "b", "c")
val goal = "member"("X", constants.toTerm())

val solutions = solver.solve(goal, mediumDuration).toList()

assertSolutionEquals(
ktListConcat(
constants.map { goal.yes("X" to it) },
ktListOf(goal.no())
),
solutions
)

assertEquals(constants.size + 1, solutions.size)
assertSolverSolutionsCorrect(solver, memberGoalToSolution, mediumDuration)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import kotlin.test.fail

private inline val loggingOn get() = false

fun <T> ktListConcat(l1: List<T>, l2: List<T>): List<T> = l1 + l2

/** Utility function to help writing tests; it creates a mapping between the receiver goal struct and the list of given solutions */
fun <S : Solution> Struct.hasSolutions(vararg solution: Struct.() -> S) =
this to solution.map { it() }
Expand Down

0 comments on commit 3c2312f

Please sign in to comment.