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-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicInteger.kt b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicInteger.kt new file mode 100644 index 000000000..7e3fbb375 --- /dev/null +++ b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicInteger.kt @@ -0,0 +1,41 @@ +package it.unibo.tuprolog.solve.systemtest + +import it.unibo.tuprolog.solve.* +import it.unibo.tuprolog.solve.channel.InputChannel +import it.unibo.tuprolog.solve.channel.OutputChannel +import it.unibo.tuprolog.solve.exception.PrologWarning +import it.unibo.tuprolog.solve.library.AliasedLibrary +import it.unibo.tuprolog.solve.library.Libraries +import it.unibo.tuprolog.solve.stdlib.DefaultBuiltins +import it.unibo.tuprolog.theory.Theory +import kotlin.test.Test + +class TestClassicInteger : TestInteger, SolverFactory by ClassicSolverFactory { + + private val prototype = TestInteger.prototype(this) + + @Test + override fun testIntPositiveNum() { + prototype.testIntPositiveNum() + } + + @Test + override fun testIntNegativeNum() { + prototype.testIntNegativeNum() + } + + @Test + override fun testIntDecNum() { + prototype.testIntDecNum() + } + + @Test + override fun testIntX() { + prototype.testIntX() + } + + @Test + override fun testIntAtom() { + prototype.testIntAtom() + } +} \ No newline at end of file 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-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicTerm.kt b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicTerm.kt new file mode 100644 index 000000000..a250fa4ab --- /dev/null +++ b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicTerm.kt @@ -0,0 +1,42 @@ +package it.unibo.tuprolog.solve.systemtest + +import it.unibo.tuprolog.solve.ClassicSolverFactory +import it.unibo.tuprolog.solve.SolverFactory +import it.unibo.tuprolog.solve.TestInteger +import it.unibo.tuprolog.solve.TestTerm +import kotlin.test.Test + +class TestClassicTerm : TestTerm, SolverFactory by ClassicSolverFactory { + + private val prototype = TestTerm.prototype(this) + + @Test + override fun testTermDiff() { + prototype.testTermDiff() + } + + @Test + override fun testTermEq() { + prototype.testTermEq() + } + + @Test + override fun testTermGreaterThan() { + prototype.testTermGreaterThan() + } + + @Test + override fun testTermGreaterThanEq() { + prototype.testTermGreaterThanEq() + } + + @Test + override fun testTermLessThan() { + prototype.testTermLessThan() + } + + @Test + override fun testTermLessThanEq() { + prototype.testTermLessThanEq() + } +} \ 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/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsInteger.kt b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsInteger.kt new file mode 100644 index 000000000..d6b2f3d6b --- /dev/null +++ b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsInteger.kt @@ -0,0 +1,41 @@ +package it.unibo.tuprolog.solve.systemtest + +import it.unibo.tuprolog.solve.* +import it.unibo.tuprolog.solve.channel.InputChannel +import it.unibo.tuprolog.solve.channel.OutputChannel +import it.unibo.tuprolog.solve.exception.PrologWarning +import it.unibo.tuprolog.solve.library.AliasedLibrary +import it.unibo.tuprolog.solve.library.Libraries +import it.unibo.tuprolog.solve.stdlib.DefaultBuiltins +import it.unibo.tuprolog.theory.Theory +import kotlin.test.Test + +class TestStreamsInteger : TestInteger, SolverFactory by StreamsSolverFactory { + + private val prototype = TestInteger.prototype(this) + + @Test + override fun testIntPositiveNum() { + prototype.testIntPositiveNum() + } + + @Test + override fun testIntNegativeNum() { + prototype.testIntNegativeNum() + } + + @Test + override fun testIntDecNum() { + prototype.testIntDecNum() + } + + @Test + override fun testIntX() { + prototype.testIntX() + } + + @Test + override fun testIntAtom() { + prototype.testIntAtom() + } +} \ 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/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsTerm.kt b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsTerm.kt new file mode 100644 index 000000000..2a2f278d8 --- /dev/null +++ b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsTerm.kt @@ -0,0 +1,42 @@ +package it.unibo.tuprolog.solve.systemtest + +import it.unibo.tuprolog.solve.StreamsSolverFactory +import it.unibo.tuprolog.solve.SolverFactory +import it.unibo.tuprolog.solve.TestInteger +import it.unibo.tuprolog.solve.TestTerm +import kotlin.test.Test + +class TestStreamsTerm : TestTerm, SolverFactory by StreamsSolverFactory { + + private val prototype = TestTerm.prototype(this) + + @Test + override fun testTermDiff() { + prototype.testTermDiff() + } + + @Test + override fun testTermEq() { + prototype.testTermEq() + } + + @Test + override fun testTermGreaterThan() { + prototype.testTermGreaterThan() + } + + @Test + override fun testTermGreaterThanEq() { + prototype.testTermGreaterThanEq() + } + + @Test + override fun testTermLessThan() { + prototype.testTermLessThan() + } + + @Test + override fun testTermLessThanEq() { + prototype.testTermLessThanEq() + } +} \ 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 diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestInteger.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestInteger.kt new file mode 100644 index 000000000..2631d66e5 --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestInteger.kt @@ -0,0 +1,56 @@ +package it.unibo.tuprolog.solve + +/** + * Tests of Integer + */ +interface TestInteger : SolverTest{ + companion object { + fun prototype(solverFactory: SolverFactory): TestInteger = + TestIntegerImpl(solverFactory) + } + + /** + * Tests the query + * ```prolog + * ?- integer(3). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + */ + fun testIntPositiveNum() + + /** + * Tests the query + * ```prolog + * ?- integer(-3). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + */ + fun testIntNegativeNum() + + /** + * Tests the query + * ```prolog + * ?- integer(3.3). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + */ + fun testIntDecNum() + + /** + * Tests the query + * ```prolog + * ?- integer(X). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + */ + fun testIntX() + + /** + * Tests the query + * ```prolog + * ?- integer(atom). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + */ + fun testIntAtom() +} \ No newline at end of file diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIntegerImpl.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIntegerImpl.kt new file mode 100644 index 000000000..338133de6 --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIntegerImpl.kt @@ -0,0 +1,76 @@ +package it.unibo.tuprolog.solve + +import it.unibo.tuprolog.dsl.theory.prolog +import kotlin.collections.listOf as ktListOf + +internal class TestIntegerImpl(private val solverFactory: SolverFactory) : TestInteger{ + override fun testIntPositiveNum() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = integer(3) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + ktListOf(query.yes()), + solutions + ) + } + } + + override fun testIntNegativeNum() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = integer(-3) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + ktListOf(query.yes()), + solutions + ) + } + } + + override fun testIntDecNum() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = integer(3.3) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + ktListOf(query.no()), + solutions + ) + } + } + + override fun testIntX() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = integer("X") + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + ktListOf(query.no()), + solutions + ) + } + } + + override fun testIntAtom() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = integer("atom") + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + ktListOf(query.no()), + solutions + ) + } + } +} \ 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 diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestTerm.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestTerm.kt new file mode 100644 index 000000000..fecae644a --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestTerm.kt @@ -0,0 +1,255 @@ +package it.unibo.tuprolog.solve + +/** + * Tests of Term diff, eq, gt, gt_eq, lt, lt_eq + */ +interface TestTerm : SolverTest { + companion object { + fun prototype(solverFactory: SolverFactory): TestTerm = + TestTermImpl(solverFactory) + } + + /** + * Tests the queries + * ```prolog + * ?- '\\=='(1,1). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '\\=='(X,X). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '\\=='(1,2). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '\\=='(X,1). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '\\=='(X,Y). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '\\=='(_,_). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '\\=='(X,a(X)). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '\\=='(f(a),f(a)). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + */ + fun testTermDiff() + + /** + * Tests the queries + * ```prolog + * ?- '=='(1,1). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '=='(X,X). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '=='(1,2). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '=='(X,1). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '=='(X,Y). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '=='(_,_). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '=='(X,a(X)). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '=='(f(a),f(a)). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + */ + fun testTermEq() + + /** + * Tests the queries + * ```prolog + * ?- '@>'(1.0,1). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@>'(aardvark,zebra). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@>'(short,short). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@>'(short,shorter). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@>'(foo(b),foo(a)). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@>'(X,X). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@>'(foo(a,X),foo(b,Y)). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + */ + fun testTermGreaterThan() + + /** + * Tests the queries + * ```prolog + * ?- '@>='(1.0,1). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@>='(aardvark,zebra). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@>='(short,short). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@>='(short,shorter). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@>='(foo(b),foo(a)). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@>='(X,X). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@>='(foo(a,X),foo(b,Y)). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + */ + fun testTermGreaterThanEq() + + /** + * Tests the queries + * ```prolog + * ?- '@<'(1.0,1). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@<'(aardvark,zebra). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@<'(short,short). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@<'(short,shorter). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@<'(foo(b),foo(a)). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@<'(X,X). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@<'(foo(a,X),foo(b,Y)). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + */ + fun testTermLessThan() + + /** + * Tests the queries + * ```prolog + * ?- '@=<'(1.0,1). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@=<'(aardvark,zebra). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@=<'(short,short). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@=<'(short,shorter). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@=<'(foo(b),foo(a)). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@=<'(X,X). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + * + * ```prolog + * ?- '@=<'(foo(a,X),foo(b,Y)). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + */ + fun testTermLessThanEq() +} \ No newline at end of file diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestTermImpl.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestTermImpl.kt new file mode 100644 index 000000000..8dac23e9e --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestTermImpl.kt @@ -0,0 +1,395 @@ +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 TestTermImpl(private val solverFactory: SolverFactory) : TestTerm { + override fun testTermDiff() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + var query = "\\=="(1,1) + var solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + + query = "\\=="("X","X") + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + + query = "\\=="(1,2) + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + + query = "\\=="("X",1) + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + + query = "\\=="("X","Y") + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + + query = "\\=="(`_`,`_`) + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + + query = "\\=="("X","a"("X")) + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + + query = "\\=="("f"("a"),"f"("a")) + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + } + } + + override fun testTermEq() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + var query = "=="(1,1) + var solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + + query = "=="("X","X") + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + + query = "=="(1,2) + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + + query = "=="("X",1) + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + + query = "=="("X","Y") + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + + query = "=="(`_`,`_`) + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + + query = "=="("X","a"("X")) + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + + query = "=="("f"("a"),"f"("a")) + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + } + } + + override fun testTermGreaterThan() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + var query = "@>"(1.0,1) + var solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + + query = "@>"("aardvark","zebra") + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + + query = "@>"("short","short") + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + + query = "@>"("short","shorter") + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + + query = "@>"("foo"("b"),"foo"("a")) + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + + query = "@>"("X","X") + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + + query = "@>"("foo"("a", "X"),"foo"("b", "Y")) + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + } + } + + override fun testTermGreaterThanEq() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + var query = "@>="(1.0,1) + var solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + + query = "@>="("aardvark","zebra") + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + + query = "@>="("short","short") + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + + query = "@>="("short","shorter") + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + + query = "@>="("foo"("b"),"foo"("a")) + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + + query = "@>="("X","X") + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + + query = "@>="("foo"("a", "X"),"foo"("b", "Y")) + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + } + } + + override fun testTermLessThan() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + var query = "@<"(1.0,1) + var solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + + query = "@<"("aardvark","zebra") + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + + query = "@<"("short","short") + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + + query = "@<"("short","shorter") + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + + query = "@<"("foo"("b"),"foo"("a")) + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + + query = "@<"("X","X") + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + + query = "@<"("foo"("a", "X"),"foo"("b", "Y")) + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + } + } + + override fun testTermLessThanEq() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + var query = "@<="(1.0,1) + var solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + + query = "@<="("aardvark","zebra") + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + + query = "@<="("short","short") + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + + query = "@<="("short","shorter") + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + + query = "@<="("foo"("b"),"foo"("a")) + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + + query = "@<="("X","X") + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + + query = "@<="("foo"("a", "X"),"foo"("b", "Y")) + solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + } + } +} \ No newline at end of file