From 2f9fd6dab980564dbd4614f3b3e41217db8eda95 Mon Sep 17 00:00:00 2001 From: Giuseppe Pisano Date: Fri, 19 Jun 2020 13:33:34 +0200 Subject: [PATCH 1/3] + retractall/1, @>/2, append/3 --- .../tuprolog/solve/stdlib/CommonBuiltins.kt | 2 + .../tuprolog/solve/stdlib/CommonRules.kt | 9 ++-- .../solve/stdlib/primitive/RetractAll.kt | 19 +++++++++ .../solve/stdlib/primitive/TermGreaterThan.kt | 13 ++++++ .../tuprolog/solve/stdlib/rule/Append.kt | 42 +++++++++++++++++++ 5 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/RetractAll.kt create mode 100644 solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermGreaterThan.kt create mode 100644 solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/rule/Append.kt diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/CommonBuiltins.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/CommonBuiltins.kt index cfcb97820..c3b9dc15f 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/CommonBuiltins.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/CommonBuiltins.kt @@ -42,7 +42,9 @@ object CommonBuiltins : AliasedLibrary by Library.of( Number, Op, Retract, + RetractAll, Sleep, + TermGreaterThan, TermIdentical, TermNotIdentical, UnifiesWith, diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/CommonRules.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/CommonRules.kt index e86200946..b88833e87 100644 --- a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/CommonRules.kt +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/CommonRules.kt @@ -2,10 +2,7 @@ package it.unibo.tuprolog.solve.stdlib import it.unibo.tuprolog.solve.ExecutionContext import it.unibo.tuprolog.solve.rule.RuleWrapper -import it.unibo.tuprolog.solve.stdlib.rule.Arrow -import it.unibo.tuprolog.solve.stdlib.rule.Member -import it.unibo.tuprolog.solve.stdlib.rule.Not -import it.unibo.tuprolog.solve.stdlib.rule.Semicolon +import it.unibo.tuprolog.solve.stdlib.rule.* import it.unibo.tuprolog.theory.Theory object CommonRules { @@ -17,7 +14,9 @@ object CommonRules { Semicolon.Or.Left, Semicolon.Or.Right, Member.Base, - Member.Recursive + Member.Recursive, + Append.Base, + Append.Recursive ) val theory: Theory diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/RetractAll.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/RetractAll.kt new file mode 100644 index 000000000..475aff593 --- /dev/null +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/RetractAll.kt @@ -0,0 +1,19 @@ +package it.unibo.tuprolog.solve.stdlib.primitive + +import it.unibo.tuprolog.core.* +import it.unibo.tuprolog.core.Var +import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.Solve +import it.unibo.tuprolog.solve.primitive.UnaryPredicate +import it.unibo.tuprolog.theory.RetractResult +import it.unibo.tuprolog.unify.Unificator.Companion.mguWith + +object RetractAll : UnaryPredicate.NonBacktrackable("retractall") { + override fun Solve.Request.computeOne(first: Term): Solve.Response { + ensuringArgumentIsStruct(0) + val clause = if (first is Clause) first else Rule.of(first as Struct, Var.anonymous()) + val dynamicKb = context.dynamicKb + val result = dynamicKb.retractAll(clause) + return replySuccess(dynamicKb = result.theory) + } +} \ No newline at end of file diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermGreaterThan.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermGreaterThan.kt new file mode 100644 index 000000000..c80c46b8a --- /dev/null +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermGreaterThan.kt @@ -0,0 +1,13 @@ +package it.unibo.tuprolog.solve.stdlib.primitive + +import it.unibo.tuprolog.core.Term +import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.Solve +import it.unibo.tuprolog.solve.primitive.BinaryRelation + +/** Implementation of '=='/2 predicate */ +object TermGreaterThan : BinaryRelation.Predicative("@>") { + override fun Solve.Request.compute(first: Term, second: Term): Boolean { + return first > second + } +} diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/rule/Append.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/rule/Append.kt new file mode 100644 index 000000000..8a355e09d --- /dev/null +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/rule/Append.kt @@ -0,0 +1,42 @@ +package it.unibo.tuprolog.solve.stdlib.rule + +import it.unibo.tuprolog.core.Scope +import it.unibo.tuprolog.core.Term +import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.Signature +import it.unibo.tuprolog.solve.rule.RuleWrapper +import kotlin.collections.List as KtList +import kotlin.collections.listOf as ktListOf + +sealed class Append : RuleWrapper(FUNCTOR, ARITY) { + + abstract override val Scope.head: KtList + + object Base : Append() { + override val Scope.head: KtList + get() = ktListOf( + emptyList(), + varOf("X"), + varOf("X") + ) + } + + object Recursive : Append() { + override val Scope.head: KtList + get() = ktListOf( + consOf(varOf("X"), varOf("Y")), + varOf("Z"), + consOf(varOf("X"), varOf("W")) + ) + + override val Scope.body: Term + get() = structOf("append", varOf("Y"), varOf("Z"), varOf("W")) + } + + companion object { + const val FUNCTOR: String = "append" + const val ARITY: Int = 3 + val SIGNATURE: Signature + get() = Signature(FUNCTOR, ARITY) + } +} \ No newline at end of file From 685b62ea4bb234f67550e9544ba7b97c9430dd80 Mon Sep 17 00:00:00 2001 From: Giovanni Ciatto Date: Sat, 20 Jun 2020 20:55:24 +0200 Subject: [PATCH 2/3] + @>=/2, @'/2 predicate */ object TermGreaterThan : BinaryRelation.Predicative("@>") { override fun Solve.Request.compute(first: Term, second: Term): Boolean { return first > second diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermGreaterThanOrEqualTo.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermGreaterThanOrEqualTo.kt new file mode 100644 index 000000000..7d3e6a418 --- /dev/null +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermGreaterThanOrEqualTo.kt @@ -0,0 +1,13 @@ +package it.unibo.tuprolog.solve.stdlib.primitive + +import it.unibo.tuprolog.core.Term +import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.Solve +import it.unibo.tuprolog.solve.primitive.BinaryRelation + +/** Implementation of '@>='/2 predicate */ +object TermGreaterThanOrEqualTo : BinaryRelation.Predicative("@>=") { + override fun Solve.Request.compute(first: Term, second: Term): Boolean { + return first >= second + } +} diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermLowerThan.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermLowerThan.kt new file mode 100644 index 000000000..a670ac77d --- /dev/null +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermLowerThan.kt @@ -0,0 +1,13 @@ +package it.unibo.tuprolog.solve.stdlib.primitive + +import it.unibo.tuprolog.core.Term +import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.Solve +import it.unibo.tuprolog.solve.primitive.BinaryRelation + +/** Implementation of '@<'/2 predicate */ +object TermLowerThan : BinaryRelation.Predicative("@<") { + override fun Solve.Request.compute(first: Term, second: Term): Boolean { + return first < second + } +} diff --git a/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermLowerThanOrEqualTo.kt b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermLowerThanOrEqualTo.kt new file mode 100644 index 000000000..931143dcd --- /dev/null +++ b/solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermLowerThanOrEqualTo.kt @@ -0,0 +1,13 @@ +package it.unibo.tuprolog.solve.stdlib.primitive + +import it.unibo.tuprolog.core.Term +import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.Solve +import it.unibo.tuprolog.solve.primitive.BinaryRelation + +/** Implementation of '@=<'/2 predicate */ +object TermLowerThanOrEqualTo : BinaryRelation.Predicative("@=<") { + override fun Solve.Request.compute(first: Term, second: Term): Boolean { + return first <= second + } +} From 852da4eaca7d1e610b250101866aa9150e325e21 Mon Sep 17 00:00:00 2001 From: Giuseppe Pisano Date: Sun, 21 Jun 2020 13:06:51 +0200 Subject: [PATCH 3/3] + retractall/1, append/3, ==/2, \==/2, @>/2, @>=/2, @ + assertCorrectResponse(TermGreaterThanOrEqualTo, input, result) + } + } +} diff --git a/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermGreaterThanTest.kt b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermGreaterThanTest.kt new file mode 100644 index 000000000..cdfe9f670 --- /dev/null +++ b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermGreaterThanTest.kt @@ -0,0 +1,20 @@ +package it.unibo.tuprolog.solve.stdlib.primitive + +import it.unibo.tuprolog.solve.stdlib.primitive.testutils.BinaryRelationUtils.assertCorrectResponse +import it.unibo.tuprolog.solve.stdlib.primitive.testutils.TermUtils.greaterQueryToResult +import kotlin.test.Test + +/** + * Test class for [TermGreaterThan] + * + */ +internal class TermGreaterThanTest { + + @Test + fun computesCorrectResult() { + greaterQueryToResult.forEach { (input, result) -> + assertCorrectResponse(TermGreaterThan, input, result) + } + } + +} diff --git a/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermIdenticalTest.kt b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermIdenticalTest.kt new file mode 100644 index 000000000..2af169a6d --- /dev/null +++ b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermIdenticalTest.kt @@ -0,0 +1,20 @@ +package it.unibo.tuprolog.solve.stdlib.primitive + +import it.unibo.tuprolog.solve.stdlib.primitive.testutils.BinaryRelationUtils.assertCorrectResponse +import it.unibo.tuprolog.solve.stdlib.primitive.testutils.TermUtils.equalQueryToResult +import kotlin.test.Test + +/** + * Test class for [TermIdentical] + * + */ +internal class TermIdenticalTest { + + @Test + fun computesCorrectResult() { + equalQueryToResult.forEach { (input, result) -> + assertCorrectResponse(TermIdentical, input, result) + } + } + +} diff --git a/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermLowerThanOrEqualToTest.kt b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermLowerThanOrEqualToTest.kt new file mode 100644 index 000000000..968a65009 --- /dev/null +++ b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermLowerThanOrEqualToTest.kt @@ -0,0 +1,19 @@ +package it.unibo.tuprolog.solve.stdlib.primitive + +import it.unibo.tuprolog.solve.stdlib.primitive.testutils.BinaryRelationUtils.assertCorrectResponse +import it.unibo.tuprolog.solve.stdlib.primitive.testutils.TermUtils.lowerOrEqualQueryToResult +import kotlin.test.Test + +/** + * Test class for [TermLowerThanOrEqualTo] + * + */ +internal class TermLowerThanOrEqualToTest { + + @Test + fun computesCorrectResult() { + lowerOrEqualQueryToResult.forEach { (input, result) -> + assertCorrectResponse(TermLowerThanOrEqualTo, input, result) + } + } +} diff --git a/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermLowerThanTest.kt b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermLowerThanTest.kt new file mode 100644 index 000000000..6886ef051 --- /dev/null +++ b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermLowerThanTest.kt @@ -0,0 +1,20 @@ +package it.unibo.tuprolog.solve.stdlib.primitive + +import it.unibo.tuprolog.solve.stdlib.primitive.testutils.BinaryRelationUtils.assertCorrectResponse +import it.unibo.tuprolog.solve.stdlib.primitive.testutils.TermUtils.lowerQueryToResult +import kotlin.test.Test + +/** + * Test class for [TermLowerThan] + * + */ +internal class TermLowerThanTest { + + @Test + fun computesCorrectResult() { + lowerQueryToResult.forEach { (input, result) -> + assertCorrectResponse(TermLowerThan, input, result) + } + } + +} diff --git a/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermNotIdenticalTest.kt b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermNotIdenticalTest.kt new file mode 100644 index 000000000..ec81fe602 --- /dev/null +++ b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/TermNotIdenticalTest.kt @@ -0,0 +1,20 @@ +package it.unibo.tuprolog.solve.stdlib.primitive + +import it.unibo.tuprolog.solve.stdlib.primitive.testutils.BinaryRelationUtils.assertCorrectResponse +import it.unibo.tuprolog.solve.stdlib.primitive.testutils.TermUtils.notEqualQueryToResult +import kotlin.test.Test + +/** + * Test class for [ArithmeticNotEqual] + * + */ +internal class TermNotIdenticalTest { + + @Test + fun computesCorrectResult() { + notEqualQueryToResult.forEach { (input, result) -> + assertCorrectResponse(TermNotIdentical, input, result) + } + } + +} diff --git a/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/ArithmeticUtils.kt b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/ArithmeticUtils.kt index b09806ea7..d85644837 100644 --- a/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/ArithmeticUtils.kt +++ b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/ArithmeticUtils.kt @@ -24,26 +24,6 @@ import kotlin.test.fail */ internal object ArithmeticUtils { - /** Utility method to check if the arithmetic relation responses are correct */ - @Suppress("IMPLICIT_CAST_TO_ANY") - internal fun assertCorrectResponse( - arithmeticRelation: ArithmeticRelation, - input: Solve.Request, - expectedResult: Any - ) = when (expectedResult) { - true -> assertTrue("Requesting ${input.query} should result in $expectedResult response!") { - arithmeticRelation.wrappedImplementation(input).single().solution is Solution.Yes - } - false -> assertTrue("Requesting ${input.query} should result in $expectedResult response!") { - arithmeticRelation.wrappedImplementation(input).single().solution is Solution.No - } - else -> - @Suppress("UNCHECKED_CAST") - (expectedResult as? KClass) - ?.let { assertFailsWith(expectedResult) { arithmeticRelation.wrappedImplementation(input) } } - ?: fail("Bad written test data!") - } - /** [Is] primitive test data (input, [Substitution | ErrorType]) */ internal val isQueryToResult by lazy { prolog { diff --git a/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/BinaryRelationUtils.kt b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/BinaryRelationUtils.kt new file mode 100644 index 000000000..315d3baf1 --- /dev/null +++ b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/BinaryRelationUtils.kt @@ -0,0 +1,34 @@ +package it.unibo.tuprolog.solve.stdlib.primitive.testutils + +import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.Solution +import it.unibo.tuprolog.solve.Solve +import it.unibo.tuprolog.solve.exception.TuPrologRuntimeException +import it.unibo.tuprolog.solve.primitive.BinaryRelation +import kotlin.reflect.KClass +import kotlin.test.assertFailsWith +import kotlin.test.assertTrue +import kotlin.test.fail + +object BinaryRelationUtils { + + /** Utility method to check if the term relation responses are correct */ + @Suppress("IMPLICIT_CAST_TO_ANY") + internal fun assertCorrectResponse( + termRelation: BinaryRelation, + input: Solve.Request, + expectedResult: Any + ) = when (expectedResult) { + true -> assertTrue("Requesting ${input.query} should result in $expectedResult response!") { + termRelation.wrappedImplementation(input).single().solution is Solution.Yes + } + false -> assertTrue("Requesting ${input.query} should result in $expectedResult response!") { + termRelation.wrappedImplementation(input).single().solution is Solution.No + } + else -> + @Suppress("UNCHECKED_CAST") + (expectedResult as? KClass) + ?.let { assertFailsWith(expectedResult) { termRelation.wrappedImplementation(input) } } + ?: fail("Bad written test data!") + } +} \ No newline at end of file diff --git a/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/TermUtils.kt b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/TermUtils.kt new file mode 100644 index 000000000..7e998de79 --- /dev/null +++ b/test-solve/src/commonTest/kotlin/it/unibo/tuprolog/solve/stdlib/primitive/testutils/TermUtils.kt @@ -0,0 +1,117 @@ +package it.unibo.tuprolog.solve.stdlib.primitive.testutils + +import it.unibo.tuprolog.dsl.prolog +import it.unibo.tuprolog.solve.ExecutionContext +import it.unibo.tuprolog.solve.Solution +import it.unibo.tuprolog.solve.Solve +import it.unibo.tuprolog.solve.exception.TuPrologRuntimeException +import it.unibo.tuprolog.solve.primitive.BinaryRelation +import it.unibo.tuprolog.solve.stdlib.primitive.* +import it.unibo.tuprolog.solve.stdlib.primitive.testutils.PrimitiveUtils.createSolveRequest +import kotlin.reflect.KClass +import kotlin.test.assertFailsWith +import kotlin.test.assertTrue +import kotlin.test.fail + +/** + * Utils singleton to help testing term comparison primitives + */ +internal object TermUtils { + + /** Equal functor test data (input, [true | false | ErrorType]) */ + internal val equalQueryToResult by lazy { + prolog { + mapOf( + TermIdentical.functor(structOf("a", atomOf("c")), + structOf("a", atomOf("c"))) to true, + TermIdentical.functor(structOf("a", atomOf("c")), + structOf("a", atomOf("x"))) to false, + TermIdentical.functor(varOf("X"), varOf("X")) to true, + TermIdentical.functor(varOf("X"), varOf("Y")) to false + ).mapKeys { (query, _) -> createSolveRequest(query) } + } + } + + /** NotEqual functor test data (input, [true | false | ErrorType]) */ + internal val notEqualQueryToResult by lazy { + prolog { + mapOf( + TermNotIdentical.functor(structOf("a", atomOf("c")), + structOf("a", atomOf("c"))) to false, + TermNotIdentical.functor(structOf("a", atomOf("c")), + structOf("a", atomOf("x"))) to true, + TermNotIdentical.functor(varOf("X"), varOf("X")) to false, + TermNotIdentical.functor(varOf("X"), varOf("Y")) to true + ).mapKeys { (query, _) -> createSolveRequest(query) } + } + } + + /** Greater functor test data (input, [true | false | ErrorType]) */ + internal val greaterQueryToResult by lazy { + prolog { + mapOf( + TermGreaterThan.functor(structOf("a", atomOf("a")), + structOf("a", atomOf("a"))) to false, + TermGreaterThan.functor(structOf("a", atomOf("a")), + structOf("a", atomOf("b"))) to false, + TermGreaterThan.functor(structOf("a", atomOf("b")), + structOf("a", atomOf("a"))) to true, + TermGreaterThan.functor(varOf("X"), varOf("X")) to false, + TermGreaterThan.functor(atomOf("a"), varOf("Y")) to true, + TermGreaterThan.functor(varOf("Y"), atomOf("a")) to false + ).mapKeys { (query, _) -> createSolveRequest(query) } + } + } + + /** Greater functor test data (input, [true | false | ErrorType]) */ + internal val greaterOrEqualQueryToResult by lazy { + prolog { + mapOf( + TermGreaterThanOrEqualTo.functor(structOf("a", atomOf("a")), + structOf("a", atomOf("a"))) to true, + TermGreaterThanOrEqualTo.functor(structOf("a", atomOf("a")), + structOf("a", atomOf("b"))) to false, + TermGreaterThanOrEqualTo.functor(structOf("a", atomOf("b")), + structOf("a", atomOf("a"))) to true, + TermGreaterThanOrEqualTo.functor(varOf("X"), varOf("X")) to true, + TermGreaterThanOrEqualTo.functor(atomOf("a"), varOf("Y")) to true, + TermGreaterThanOrEqualTo.functor(varOf("Y"), atomOf("a")) to false + ).mapKeys { (query, _) -> createSolveRequest(query) } + } + } + + /** Greater functor test data (input, [true | false | ErrorType]) */ + internal val lowerQueryToResult by lazy { + prolog { + mapOf( + TermLowerThan.functor(structOf("a", atomOf("a")), + structOf("a", atomOf("a"))) to false, + TermLowerThan.functor(structOf("a", atomOf("a")), + structOf("a", atomOf("b"))) to true, + TermLowerThan.functor(structOf("a", atomOf("b")), + structOf("a", atomOf("a"))) to false, + TermLowerThan.functor(varOf("X"), varOf("X")) to false, + TermLowerThan.functor(atomOf("a"), varOf("Y")) to false, + TermLowerThan.functor(varOf("Y"), atomOf("a")) to true + ).mapKeys { (query, _) -> createSolveRequest(query) } + } + } + + /** Greater functor test data (input, [true | false | ErrorType]) */ + internal val lowerOrEqualQueryToResult by lazy { + prolog { + mapOf( + TermLowerThanOrEqualTo.functor(structOf("a", atomOf("a")), + structOf("a", atomOf("a"))) to true, + TermLowerThanOrEqualTo.functor(structOf("a", atomOf("a")), + structOf("a", atomOf("b"))) to true, + TermLowerThanOrEqualTo.functor(structOf("a", atomOf("b")), + structOf("a", atomOf("a"))) to false, + TermLowerThanOrEqualTo.functor(varOf("X"), varOf("X")) to true, + TermLowerThanOrEqualTo.functor(atomOf("a"), varOf("Y")) to false, + TermLowerThanOrEqualTo.functor(varOf("Y"), atomOf("a")) to true + ).mapKeys { (query, _) -> createSolveRequest(query) } + } + } + +}