From 36d9b69a1882edfcfa45a598049f38daced32d90 Mon Sep 17 00:00:00 2001 From: Davide Greco Date: Fri, 28 Aug 2020 17:25:08 +0200 Subject: [PATCH] Test Cut implementation --- .../solve/systemtest/TestClassicCut.kt | 26 ++++++++++ .../solve/systemtest/TestStreamsCut.kt | 26 ++++++++++ .../kotlin/it/unibo/tuprolog/solve/TestCut.kt | 37 +++++++++++++++ .../it/unibo/tuprolog/solve/TestCutImpl.kt | 47 +++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicCut.kt create mode 100644 solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsCut.kt create mode 100644 test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestCut.kt create mode 100644 test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestCutImpl.kt diff --git a/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicCut.kt b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicCut.kt new file mode 100644 index 000000000..0792ab157 --- /dev/null +++ b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicCut.kt @@ -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() + } +} \ No newline at end of file diff --git a/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsCut.kt b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsCut.kt new file mode 100644 index 000000000..5ca3de22c --- /dev/null +++ b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsCut.kt @@ -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() + } +} \ No newline at end of file diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestCut.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestCut.kt new file mode 100644 index 000000000..47a10db22 --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestCut.kt @@ -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() +} \ No newline at end of file diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestCutImpl.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestCutImpl.kt new file mode 100644 index 000000000..c158b11d1 --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestCutImpl.kt @@ -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 + ) + } + } +} \ No newline at end of file