diff --git a/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicIs.kt b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicIs.kt new file mode 100644 index 000000000..43772d62d --- /dev/null +++ b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicIs.kt @@ -0,0 +1,40 @@ +package it.unibo.tuprolog.solve.systemtest + +import it.unibo.tuprolog.solve.ClassicSolverFactory +import it.unibo.tuprolog.solve.SolverFactory +import it.unibo.tuprolog.solve.TestIs +import kotlin.test.Test + +class TestClassicIs : TestIs, SolverFactory by ClassicSolverFactory { + private val prototype = TestIs.prototype(this) + + @Test + override fun testIsResult() { + prototype.testIsResult() + } + + @Test + override fun testIsXY(){ + prototype.testIsXY() + } + + @Test + override fun testIsFoo() { + prototype.testIsFoo() + } + + @Test + override fun testIsNNumber() { + prototype.testIsNNumber() + } + + @Test + override fun testIsNumberFoo() { + prototype.testIsNumberFoo() + } + + @Test + override fun testIsXFloat() { + prototype.testIsXFloat() + } +} \ No newline at end of file diff --git a/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsIs.kt b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsIs.kt new file mode 100644 index 000000000..12455e9d1 --- /dev/null +++ b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsIs.kt @@ -0,0 +1,40 @@ +package it.unibo.tuprolog.solve.systemtest + +import it.unibo.tuprolog.solve.StreamsSolverFactory +import it.unibo.tuprolog.solve.SolverFactory +import it.unibo.tuprolog.solve.TestIs +import kotlin.test.Test + +class TestStreamsIs : TestIs, SolverFactory by StreamsSolverFactory { + private val prototype = TestIs.prototype(this) + + @Test + override fun testIsResult() { + prototype.testIsResult() + } + + @Test + override fun testIsXY(){ + prototype.testIsXY() + } + + @Test + override fun testIsFoo() { + prototype.testIsFoo() + } + + @Test + override fun testIsNNumber() { + prototype.testIsNNumber() + } + + @Test + override fun testIsNumberFoo() { + prototype.testIsNumberFoo() + } + + @Test + override fun testIsXFloat() { + prototype.testIsXFloat() + } +} \ No newline at end of file diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIs.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIs.kt new file mode 100644 index 000000000..20184b937 --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIs.kt @@ -0,0 +1,67 @@ +package it.unibo.tuprolog.solve + +interface TestIs : SolverTest { + companion object { + fun prototype(solverFactory: SolverFactory): TestIs = + TestIsImpl(solverFactory) + } + + /** + * Tests the queries + * ```prolog + * ?- 'is'(Result,3 + 11.0). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory, + * producing 1 solution which binds variable `Result` to `14.0`. + */ + fun testIsResult() + + /** + * Tests the queries + * ```prolog + * ?- (X = 1 + 2, 'is'(Y, X * 3)). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory, + * producing 2 solutions which binds variable `X` to `1+2` and `Y` to `9`. + */ + fun testIsXY() + + /** + * Tests the queries + * ```prolog + * ?- 'is'(foo,77). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + */ + fun testIsFoo() + + /** + * Tests the queries + * ```prolog + * ?- 'is'(77, N). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + * producing exception `instantiation_error`. + */ + fun testIsNNumber() + + /** + * Tests the queries + * ```prolog + * ?- 'is'(77, foo). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + * producing exception `type_error(foo/0)`. + */ + fun testIsNumberFoo() + + /** + * Tests the queries + * ```prolog + * ?- 'is'(X,float(3)). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory, + * producing 1 solution which binds variable `X` to `3.0`. + */ + fun testIsXFloat() +} \ No newline at end of file diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIsImpl.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIsImpl.kt new file mode 100644 index 000000000..33186d5d2 --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIsImpl.kt @@ -0,0 +1,109 @@ +package it.unibo.tuprolog.solve + +import it.unibo.tuprolog.dsl.theory.prolog +import it.unibo.tuprolog.solve.exception.error.InstantiationError +import it.unibo.tuprolog.solve.exception.error.TypeError + +internal class TestIsImpl(private val solverFactory: SolverFactory) : TestIs { + override fun testIsResult() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = "Result" `is` numOf(3) + 11.0 + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes("Result" to 14.0)), + solutions + ) + } + } + + override fun testIsXY() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = ("X" `=` numOf(1) + 2) and ("Y" `is` "X" * 3) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes("X" to numOf(1)+2, "Y" to 9)), + solutions + ) + } + } + + override fun testIsFoo() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = "foo" `is` 77 + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + } + } + + override fun testIsNNumber() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = 77 `is` "N" + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.halt( + InstantiationError.forGoal( + DummyInstances.executionContext, + Signature("is", 2), + varOf("N") + ) + ) + ), + solutions + ) + } + } + + override fun testIsNumberFoo() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = 77 `is` "foo" + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.halt( + TypeError.forGoal( + DummyInstances.executionContext, + Signature("is", 2), + TypeError.Expected.EVALUABLE, + atomOf("foo") + + ) + ) + ), + solutions + ) + } + } + + override fun testIsXFloat() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = "X" `is` float(3) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes("X" to 3.0)), + solutions + ) + } + } +} \ No newline at end of file