Skip to content

Commit

Permalink
Test Cut implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideGreco committed Aug 28, 2020
1 parent 1d23525 commit 36d9b69
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package it.unibo.tuprolog.solve.systemtest

import it.unibo.tuprolog.solve.ClassicSolverFactory
import it.unibo.tuprolog.solve.SolverFactory
import it.unibo.tuprolog.solve.TestCut
import kotlin.test.Test

class TestClassicCut: TestCut, SolverFactory by ClassicSolverFactory {

private val prototype = TestCut.prototype(this)

@Test
override fun testCut() {
prototype.testCut()
}

@Test
override fun testCutFailTrue() {
prototype.testCutFailTrue()
}

@Test
override fun testCallCutFailTrue() {
prototype.testCallCutFailTrue()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package it.unibo.tuprolog.solve.systemtest

import it.unibo.tuprolog.solve.SolverFactory
import it.unibo.tuprolog.solve.StreamsSolverFactory
import it.unibo.tuprolog.solve.TestCut
import kotlin.test.Test

class TestStreamsCut: TestCut, SolverFactory by StreamsSolverFactory {

private val prototype = TestCut.prototype(this)

@Test
override fun testCut() {
prototype.testCut()
}

@Test
override fun testCutFailTrue() {
prototype.testCutFailTrue()
}

@Test
override fun testCallCutFailTrue() {
prototype.testCallCutFailTrue()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package it.unibo.tuprolog.solve

import it.unibo.tuprolog.solve.SolverTest

interface TestCut : SolverTest {
companion object {
fun prototype(solverFactory: SolverFactory): TestCut =
TestCutImpl(solverFactory)
}

/**
* Tests the queries
* ```prolog
* ?- !.
* ```
* succeeds on a solver initialized with default built-ins and with and empty theory.
*/
fun testCut()

/**
* Tests the queries
* ```prolog
* ?- (!,fail;true).
* ```
* succeeds on a solver initialized with default built-ins and with and empty theory.
*/
fun testCutFailTrue()

/**
* Tests the queries
* ```prolog
* ?- (call(!),fail;true).
* ```
* succeeds on a solver initialized with default built-ins and with and empty theory.
*/
fun testCallCutFailTrue()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package it.unibo.tuprolog.solve

import it.unibo.tuprolog.dsl.theory.prolog

internal class TestCutImpl(private val solverFactory: SolverFactory) : TestCut{
override fun testCut() {
prolog {
val solver = solverFactory.solverWithDefaultBuiltins()

val query = atomOf("!")
val solutions = solver.solve(query, mediumDuration).toList()

assertSolutionEquals(
kotlin.collections.listOf(query.yes()),
solutions
)
}
}

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

val query = ("!" and fail or true)
val solutions = solver.solve(query, mediumDuration).toList()

assertSolutionEquals(
kotlin.collections.listOf(query.no()),
solutions
)
}
}

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

val query = (call("!") and fail or true )
val solutions = solver.solve(query, mediumDuration).toList()

assertSolutionEquals(
kotlin.collections.listOf(query.yes()),
solutions
)
}
}
}

0 comments on commit 36d9b69

Please sign in to comment.