diff --git a/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicFloat.kt b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicFloat.kt new file mode 100644 index 000000000..4a59e6d67 --- /dev/null +++ b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicFloat.kt @@ -0,0 +1,35 @@ +package it.unibo.tuprolog.solve.systemtest + +import it.unibo.tuprolog.solve.ClassicSolverFactory +import it.unibo.tuprolog.solve.SolverFactory +import it.unibo.tuprolog.solve.TestFloat +import kotlin.test.Test + +class TestClassicFloat : TestFloat, SolverFactory by ClassicSolverFactory { + private val prototype = TestFloat.prototype(this) + + @Test + override fun testFloatDec() { + prototype.testFloatDec() + } + + @Test + override fun testFloatDecNeg() { + prototype.testFloatDecNeg() + } + + @Test + override fun testFloatNat() { + prototype.testFloatNat() + } + + @Test + override fun testFloatAtom() { + prototype.testFloatAtom() + } + + @Test + override fun testFloatX() { + prototype.testFloatX() + } +} \ No newline at end of file diff --git a/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsFloat.kt b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsFloat.kt new file mode 100644 index 000000000..a70aa5540 --- /dev/null +++ b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsFloat.kt @@ -0,0 +1,35 @@ +package it.unibo.tuprolog.solve.systemtest + +import it.unibo.tuprolog.solve.StreamsSolverFactory +import it.unibo.tuprolog.solve.SolverFactory +import it.unibo.tuprolog.solve.TestFloat +import kotlin.test.Test + +class TestStreamsFloat : TestFloat, SolverFactory by StreamsSolverFactory { + private val prototype = TestFloat.prototype(this) + + @Test + override fun testFloatDec() { + prototype.testFloatDec() + } + + @Test + override fun testFloatDecNeg() { + prototype.testFloatDecNeg() + } + + @Test + override fun testFloatNat() { + prototype.testFloatNat() + } + + @Test + override fun testFloatAtom() { + prototype.testFloatAtom() + } + + @Test + override fun testFloatX() { + prototype.testFloatX() + } +} \ No newline at end of file diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestFloat.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestFloat.kt new file mode 100644 index 000000000..d7a77844f --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestFloat.kt @@ -0,0 +1,53 @@ +package it.unibo.tuprolog.solve + +interface TestFloat : SolverTest { + companion object { + fun prototype(solverFactory: SolverFactory): TestFloat = + TestFloatImpl(solverFactory) + } + + /** + * Tests the queries + * ```prolog + * ?- float(3.3). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory, + */ + fun testFloatDec() + + /** + * Tests the queries + * ```prolog + * ?- float(-3.3). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory, + */ + fun testFloatDecNeg() + + /** + * Tests the queries + * ```prolog + * ?- float(3). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + */ + fun testFloatNat() + + /** + * Tests the queries + * ```prolog + * ?- float(atom). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + */ + fun testFloatAtom() + + /** + * Tests the queries + * ```prolog + * ?- float(X). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + */ + fun testFloatX() +} \ No newline at end of file diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestFloatImpl.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestFloatImpl.kt new file mode 100644 index 000000000..45f1fbe87 --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestFloatImpl.kt @@ -0,0 +1,76 @@ +package it.unibo.tuprolog.solve + +import it.unibo.tuprolog.dsl.theory.prolog + +internal class TestFloatImpl(private val solverFactory: SolverFactory) : TestFloat { + override fun testFloatDec() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = float(3.3) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + } + } + + override fun testFloatDecNeg() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = float(- 3.3) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + } + } + + override fun testFloatNat() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = float(3) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + } + } + + override fun testFloatAtom() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = float("atom") + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + } + } + + override fun testFloatX() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = float("X") + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + } + } + +} \ No newline at end of file