From 1d235256d122a8ff06dcffc21a45adc8a12a3ef8 Mon Sep 17 00:00:00 2001 From: Davide Greco Date: Fri, 28 Aug 2020 16:25:33 +0200 Subject: [PATCH] Test Number implementation --- .../solve/systemtest/TestClassicNumber.kt | 37 +++++++++ .../solve/systemtest/TestStreamsNumber.kt | 37 +++++++++ .../it/unibo/tuprolog/solve/TestNumber.kt | 56 ++++++++++++++ .../it/unibo/tuprolog/solve/TestNumberImpl.kt | 75 +++++++++++++++++++ 4 files changed, 205 insertions(+) create mode 100644 solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicNumber.kt create mode 100644 solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsNumber.kt create mode 100644 test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestNumber.kt create mode 100644 test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestNumberImpl.kt diff --git a/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicNumber.kt b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicNumber.kt new file mode 100644 index 000000000..97fedfc12 --- /dev/null +++ b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicNumber.kt @@ -0,0 +1,37 @@ +package it.unibo.tuprolog.solve.systemtest + +import it.unibo.tuprolog.solve.ClassicSolverFactory +import it.unibo.tuprolog.solve.SolverFactory +import it.unibo.tuprolog.solve.TestNumber +import kotlin.test.Test + +class TestClassicNumber : TestNumber, SolverFactory by ClassicSolverFactory { + + private val prototype = TestNumber.prototype(this) + + @Test + override fun testBasicNum() { + prototype.testBasicNum() + } + + @Test + override fun testDecNum() { + prototype.testDecNum() + } + + @Test + override fun testNegNum() { + prototype.testNegNum() + } + + @Test + override fun testLetterNum() { + prototype.testLetterNum() + } + + @Test + override fun testXNum() { + prototype.testXNum() + } + +} \ No newline at end of file diff --git a/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsNumber.kt b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsNumber.kt new file mode 100644 index 000000000..0abe430c4 --- /dev/null +++ b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsNumber.kt @@ -0,0 +1,37 @@ +package it.unibo.tuprolog.solve.systemtest + +import it.unibo.tuprolog.solve.SolverFactory +import it.unibo.tuprolog.solve.StreamsSolverFactory +import it.unibo.tuprolog.solve.TestNumber +import kotlin.test.Test + +class TestStreamsNumber : TestNumber, SolverFactory by StreamsSolverFactory { + + private val prototype = TestNumber.prototype(this) + + @Test + override fun testBasicNum() { + prototype.testBasicNum() + } + + @Test + override fun testDecNum() { + prototype.testDecNum() + } + + @Test + override fun testNegNum() { + prototype.testNegNum() + } + + @Test + override fun testLetterNum() { + prototype.testLetterNum() + } + + @Test + override fun testXNum() { + prototype.testXNum() + } + +} \ No newline at end of file diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestNumber.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestNumber.kt new file mode 100644 index 000000000..77fc8a329 --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestNumber.kt @@ -0,0 +1,56 @@ +package it.unibo.tuprolog.solve + +/** + * Tests of number + */ +interface TestNumber : SolverTest{ + companion object { + fun prototype(solverFactory: SolverFactory): TestNumber = + TestNumberImpl(solverFactory) + } + + /** + * Tests the query + * ```prolog + * ?- number(3). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + */ + fun testBasicNum() + + /** + * Tests the query + * ```prolog + * ?- number(3.3). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + */ + fun testDecNum() + + /** + * Tests the query + * ```prolog + * ?- number(-3). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + */ + fun testNegNum() + + /** + * Tests the query + * ```prolog + * ?- number(a). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + */ + fun testLetterNum() + + /** + * Tests the query + * ```prolog + * ?- number(X). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + */ + fun testXNum() +} \ No newline at end of file diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestNumberImpl.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestNumberImpl.kt new file mode 100644 index 000000000..e6f0ada26 --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestNumberImpl.kt @@ -0,0 +1,75 @@ +package it.unibo.tuprolog.solve + +import it.unibo.tuprolog.dsl.theory.prolog + +internal class TestNumberImpl(private val solverFactory: SolverFactory) : TestNumber { + override fun testBasicNum() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = number(3) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + } + } + + override fun testDecNum() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = number(3.3) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + } + } + + override fun testNegNum() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = number(-3) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + } + } + + override fun testLetterNum() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = number("a") + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + } + } + + override fun testXNum() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = number("X") + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + } + } +} \ No newline at end of file