diff --git a/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicCall.kt b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicCall.kt new file mode 100644 index 000000000..2060b7458 --- /dev/null +++ b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicCall.kt @@ -0,0 +1,69 @@ +package it.unibo.tuprolog.solve.systemtest + +import it.unibo.tuprolog.solve.ClassicSolverFactory +import it.unibo.tuprolog.solve.SolverFactory +import it.unibo.tuprolog.solve.TestCall +import kotlin.test.Ignore +import kotlin.test.Test + +class TestClassicCall : TestCall, SolverFactory by ClassicSolverFactory { + private val prototype = TestCall.prototype(this) + + @Test + override fun testCallCut(){ + prototype.testCallCut() + } + + @Test + override fun testCallFail() { + prototype.testCallFail() + } + + @Test + override fun testCallFailX() { + prototype.testCallFailX() + } + + @Test + override fun testCallFailCall() { + prototype.testCallFailCall() + } + + @Test + override fun testCallWriteX() { + prototype.testCallWriteX() + } + + @Test + override fun testCallWriteCall() { + prototype.testCallWriteCall() + } + + @Test + override fun testCallX() { + prototype.testCallX() + } + + @Test + override fun testCallOne() { + prototype.testCallOne() + } + + @Test + @Ignore + override fun testCallFailOne() { + prototype.testCallFailOne() + } + + @Test + @Ignore + override fun testCallWriteOne() { + prototype.testCallWriteOne() + } + + @Test + @Ignore + override fun testCallTrue() { + prototype.testCallTrue() + } +} \ No newline at end of file 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-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicFunctor.kt b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicFunctor.kt new file mode 100644 index 000000000..77b7f2378 --- /dev/null +++ b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicFunctor.kt @@ -0,0 +1,99 @@ +package it.unibo.tuprolog.solve.systemtest + +import it.unibo.tuprolog.solve.ClassicSolverFactory +import it.unibo.tuprolog.solve.SolverFactory +import it.unibo.tuprolog.solve.TestFunctor +import kotlin.test.Ignore +import kotlin.test.Test + +class TestClassicFunctor : TestFunctor, SolverFactory by ClassicSolverFactory { + private val prototype = TestFunctor.prototype(this) + + @Test + override fun testFunArity(){ + prototype.testFunArity() + } + + @Test + override fun testFunArityWithSub() { + prototype.testFunArityWithSub() + } + + @Test + override fun testFunMats() { + prototype.testFunMats() + } + + @Test + override fun testFunArityZero() { + prototype.testFunArityZero() + } + + @Test + override fun testFunWrongArity() { + prototype.testFunWrongArity() + } + + @Test + override fun testFunWrongName() { + prototype.testFunWrongName() + } + + @Test + @Ignore + override fun testFunXNameYArity() { + prototype.testFunXNameYArity() + } + + @Test + @Ignore + override fun testFunDecNum() { + prototype.testFunDecNum() + } + + @Test + override fun testFunConsOf() { + prototype.testFunConsOf() + } + + @Test + override fun testFunEmptyList() { + prototype.testFunEmptyList() + } + + @Test + override fun testFunXYWrongArity() { + prototype.testFunXYWrongArity() + } + + @Test + override fun testFunXNArity() { + prototype.testFunXNArity() + } + + @Test + override fun testFunXAArity() { + prototype.testFunXAArity() + } + + @Test + override fun testFunNumName() { + prototype.testFunNumName() + } + + @Test + override fun testFunFooName() { + prototype.testFunFooName() + } + + @Test + override fun testFunFlag() { + prototype.testFunFlag() + } + + @Test + @Ignore + override fun testFunNegativeArity() { + prototype.testFunNegativeArity() + } +} \ No newline at end of file diff --git a/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicIfThen.kt b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicIfThen.kt new file mode 100644 index 000000000..114995e03 --- /dev/null +++ b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicIfThen.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.TestIfThen +import kotlin.test.Test + +class TestClassicIfThen : TestIfThen, SolverFactory by ClassicSolverFactory { + private val prototype = TestIfThen.prototype(this) + + @Test + override fun testIfThenFail() { + prototype.testIfThenFail() + } + + @Test + override fun testIfThenFailTrue() { + prototype.testIfThenFailTrue() + } + + @Test + override fun testIfThenOrWithDoubleSub() { + prototype.testIfThenOrWithDoubleSub() + } + + @Test + override fun testIfThenTrue() { + prototype.testIfThenTrue() + } + + @Test + override fun testIfThenXOr() { + prototype.testIfThenXOr() + } + + @Test + override fun testIfThenXtoOne() { + prototype.testIfThenXtoOne() + } +} \ No newline at end of file diff --git a/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicIfThenElse.kt b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicIfThenElse.kt new file mode 100644 index 000000000..c4ef3e875 --- /dev/null +++ b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicIfThenElse.kt @@ -0,0 +1,50 @@ +package it.unibo.tuprolog.solve.systemtest + +import it.unibo.tuprolog.solve.ClassicSolverFactory +import it.unibo.tuprolog.solve.SolverFactory +import it.unibo.tuprolog.solve.TestIfThenElse +import kotlin.test.Test + +class TestClassicIfThenElse : TestIfThenElse, SolverFactory by ClassicSolverFactory { + private val prototype = TestIfThenElse.prototype(this) + + @Test + override fun testIfTrueElseFail() { + prototype.testIfTrueElseFail() + } + + @Test + override fun testIfFailElseTrue() { + prototype.testIfFailElseTrue() + } + + @Test + override fun testIfTrueThenElseFail() { + prototype.testIfTrueThenElseFail() + } + + @Test + override fun testIfFailElseFail() { + prototype.testIfFailElseFail() + } + + @Test + override fun testIfXTrueElseX() { + prototype.testIfXTrueElseX() + } + + @Test + override fun testIfFailElseX() { + prototype.testIfFailElseX() + } + + @Test + override fun testIfThenElseOrWithDoubleSub() { + prototype.testIfThenElseOrWithDoubleSub() + } + + @Test + override fun testIfOrElseTrue() { + prototype.testIfOrElseTrue() + } +} \ No newline at end of file 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-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicNotProvable.kt b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicNotProvable.kt new file mode 100644 index 000000000..95a5f5a0d --- /dev/null +++ b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicNotProvable.kt @@ -0,0 +1,48 @@ +package it.unibo.tuprolog.solve.systemtest + +import it.unibo.tuprolog.solve.ClassicSolverFactory +import it.unibo.tuprolog.solve.SolverFactory +import it.unibo.tuprolog.solve.TestNotProvable +import kotlin.test.Ignore +import kotlin.test.Test + +class TestClassicNotProvable : TestNotProvable, SolverFactory by ClassicSolverFactory { + private val prototype = TestNotProvable.prototype(this) + + @Test + override fun testNPTrue() { + prototype.testNPTrue() + } + + @Test + override fun testNPCut() { + prototype.testNPCut() + } + + @Test + @Ignore //solver returns no + override fun testNPCutFail() { + prototype.testNPCutFail() + } + + @Test + override fun testNPEquals() { + prototype.testNPEquals() + } + + @Test + override fun testNPNum() { + prototype.testNPNum() + } + + @Test + override fun testNPX() { + prototype.testNPX() + } + + @Test + @Ignore //solver returns no + override fun testOrNotCutFail() { + prototype.testOrNotCutFail() + } +} \ No newline at end of file diff --git a/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicRetract.kt b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicRetract.kt new file mode 100644 index 000000000..6e9646f09 --- /dev/null +++ b/solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicRetract.kt @@ -0,0 +1,23 @@ +package it.unibo.tuprolog.solve.systemtest + +import it.unibo.tuprolog.solve.ClassicSolverFactory +import it.unibo.tuprolog.solve.SolverFactory +import it.unibo.tuprolog.solve.TestRetract +import kotlin.test.Ignore +import kotlin.test.Test + +class TestClassicRetract : TestRetract, SolverFactory by ClassicSolverFactory { + private val prototype = TestRetract.prototype(this) + + @Test + @Ignore + override fun testRetractNumIfX() { + prototype.testRetractNumIfX() + } + + @Test + @Ignore + override fun testRetractAtomEmptyList() { + prototype.testRetractAtomEmptyList() + } +} \ No newline at end of file diff --git a/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsCall.kt b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsCall.kt new file mode 100644 index 000000000..f7ed44195 --- /dev/null +++ b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsCall.kt @@ -0,0 +1,69 @@ +package it.unibo.tuprolog.solve.systemtest + +import it.unibo.tuprolog.solve.StreamsSolverFactory +import it.unibo.tuprolog.solve.SolverFactory +import it.unibo.tuprolog.solve.TestCall +import kotlin.test.Ignore +import kotlin.test.Test + +class TestClassicCall : TestCall, SolverFactory by StreamsSolverFactory { + private val prototype = TestCall.prototype(this) + + @Test + override fun testCallCut(){ + prototype.testCallCut() + } + + @Test + override fun testCallFail() { + prototype.testCallFail() + } + + @Test + override fun testCallFailX() { + prototype.testCallFailX() + } + + @Test + override fun testCallFailCall() { + prototype.testCallFailCall() + } + + @Test + override fun testCallWriteX() { + prototype.testCallWriteX() + } + + @Test + override fun testCallWriteCall() { + prototype.testCallWriteCall() + } + + @Test + override fun testCallX() { + prototype.testCallX() + } + + @Test + override fun testCallOne() { + prototype.testCallOne() + } + + @Test + @Ignore + override fun testCallFailOne() { + prototype.testCallFailOne() + } + + @Test + @Ignore + override fun testCallWriteOne() { + prototype.testCallWriteOne() + } + + @Test + @Ignore + override fun testCallTrue() { + prototype.testCallTrue() + } +} \ 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/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsFunctor.kt b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsFunctor.kt new file mode 100644 index 000000000..4527aafaf --- /dev/null +++ b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsFunctor.kt @@ -0,0 +1,102 @@ +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.Libraries +import it.unibo.tuprolog.theory.Theory +import kotlin.test.Ignore +import kotlin.test.Test + +class TestStreamsFunctor : TestFunctor, SolverFactory by StreamsSolverFactory { + private val prototype = TestFunctor.prototype(this) + + @Test + override fun testFunArity(){ + prototype.testFunArity() + } + + @Test + override fun testFunArityWithSub() { + prototype.testFunArityWithSub() + } + + @Test + override fun testFunMats() { + prototype.testFunMats() + } + + @Test + override fun testFunArityZero() { + prototype.testFunArityZero() + } + + @Test + override fun testFunWrongArity() { + prototype.testFunWrongArity() + } + + @Test + override fun testFunWrongName() { + prototype.testFunWrongName() + } + + @Test + @Ignore + override fun testFunXNameYArity() { + prototype.testFunXNameYArity() + } + + @Test + @Ignore + override fun testFunDecNum() { + prototype.testFunDecNum() + } + + @Test + override fun testFunConsOf() { + prototype.testFunConsOf() + } + + @Test + override fun testFunEmptyList() { + prototype.testFunEmptyList() + } + + @Test + override fun testFunXYWrongArity() { + prototype.testFunXYWrongArity() + } + + @Test + override fun testFunXNArity() { + prototype.testFunXNArity() + } + + @Test + override fun testFunXAArity() { + prototype.testFunXAArity() + } + + @Test + override fun testFunNumName() { + prototype.testFunNumName() + } + + @Test + override fun testFunFooName() { + prototype.testFunFooName() + } + + @Test + override fun testFunFlag() { + prototype.testFunFlag() + } + + @Test + @Ignore + override fun testFunNegativeArity() { + prototype.testFunNegativeArity() + } +} \ No newline at end of file diff --git a/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsIfThen.kt b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsIfThen.kt new file mode 100644 index 000000000..6261e097d --- /dev/null +++ b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsIfThen.kt @@ -0,0 +1,40 @@ +package it.unibo.tuprolog.solve.systemtest + +import it.unibo.tuprolog.solve.SolverFactory +import it.unibo.tuprolog.solve.StreamsSolverFactory +import it.unibo.tuprolog.solve.TestIfThen +import kotlin.test.Test + +class TestStreamsIfThen : TestIfThen, SolverFactory by StreamsSolverFactory { + private val prototype = TestIfThen.prototype(this) + + @Test + override fun testIfThenFail() { + prototype.testIfThenFail() + } + + @Test + override fun testIfThenFailTrue() { + prototype.testIfThenFailTrue() + } + + @Test + override fun testIfThenOrWithDoubleSub() { + prototype.testIfThenOrWithDoubleSub() + } + + @Test + override fun testIfThenTrue() { + prototype.testIfThenTrue() + } + + @Test + override fun testIfThenXOr() { + prototype.testIfThenXOr() + } + + @Test + override fun testIfThenXtoOne() { + prototype.testIfThenXtoOne() + } +} \ No newline at end of file diff --git a/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsIfThenElse.kt b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsIfThenElse.kt new file mode 100644 index 000000000..896c475c9 --- /dev/null +++ b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsIfThenElse.kt @@ -0,0 +1,50 @@ +package it.unibo.tuprolog.solve.systemtest + +import it.unibo.tuprolog.solve.StreamsSolverFactory +import it.unibo.tuprolog.solve.SolverFactory +import it.unibo.tuprolog.solve.TestIfThenElse +import kotlin.test.Test + +class TestStreamsIfThenElse : TestIfThenElse, SolverFactory by StreamsSolverFactory { + private val prototype = TestIfThenElse.prototype(this) + + @Test + override fun testIfTrueElseFail() { + prototype.testIfTrueElseFail() + } + + @Test + override fun testIfFailElseTrue() { + prototype.testIfFailElseTrue() + } + + @Test + override fun testIfTrueThenElseFail() { + prototype.testIfTrueThenElseFail() + } + + @Test + override fun testIfFailElseFail() { + prototype.testIfFailElseFail() + } + + @Test + override fun testIfXTrueElseX() { + prototype.testIfXTrueElseX() + } + + @Test + override fun testIfFailElseX() { + prototype.testIfFailElseX() + } + + @Test + override fun testIfThenElseOrWithDoubleSub() { + prototype.testIfThenElseOrWithDoubleSub() + } + + @Test + override fun testIfOrElseTrue() { + prototype.testIfOrElseTrue() + } +} \ 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/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsNotProvable.kt b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsNotProvable.kt new file mode 100644 index 000000000..c7d12ae20 --- /dev/null +++ b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsNotProvable.kt @@ -0,0 +1,48 @@ +package it.unibo.tuprolog.solve.systemtest + +import it.unibo.tuprolog.solve.SolverFactory +import it.unibo.tuprolog.solve.StreamsSolverFactory +import it.unibo.tuprolog.solve.TestNotProvable +import kotlin.test.Ignore +import kotlin.test.Test + +class TestStreamsNotProvable : TestNotProvable, SolverFactory by StreamsSolverFactory { + private val prototype = TestNotProvable.prototype(this) + + @Test + override fun testNPTrue() { + prototype.testNPTrue() + } + + @Test + override fun testNPCut() { + prototype.testNPCut() + } + + @Test + @Ignore //solver returns no + override fun testNPCutFail() { + prototype.testNPCutFail() + } + + @Test + override fun testNPEquals() { + prototype.testNPEquals() + } + + @Test + override fun testNPNum() { + prototype.testNPNum() + } + + @Test + override fun testNPX() { + prototype.testNPX() + } + + @Test + @Ignore //solver returns no + override fun testOrNotCutFail() { + prototype.testOrNotCutFail() + } +} \ No newline at end of file diff --git a/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsRetract.kt b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsRetract.kt new file mode 100644 index 000000000..26336bf51 --- /dev/null +++ b/solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsRetract.kt @@ -0,0 +1,23 @@ +package it.unibo.tuprolog.solve.systemtest + +import it.unibo.tuprolog.solve.SolverFactory +import it.unibo.tuprolog.solve.StreamsSolverFactory +import it.unibo.tuprolog.solve.TestRetract +import kotlin.test.Ignore +import kotlin.test.Test + +class TestStreamsRetract : TestRetract, SolverFactory by StreamsSolverFactory { + private val prototype = TestRetract.prototype(this) + + @Test + @Ignore + override fun testRetractNumIfX() { + prototype.testRetractNumIfX() + } + + @Test + @Ignore + override fun testRetractAtomEmptyList() { + prototype.testRetractAtomEmptyList() + } +} \ No newline at end of file diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestCall.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestCall.kt new file mode 100644 index 000000000..7a8c24762 --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestCall.kt @@ -0,0 +1,114 @@ +package it.unibo.tuprolog.solve + +interface TestCall : SolverTest { + companion object { + fun prototype(solverFactory: SolverFactory): TestCall = + TestCallImpl(solverFactory) + } + + /** + * Tests the queries + * ```prolog + * ?- call(!). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory, + */ + fun testCallCut() + + /** + * Tests the queries + * ```prolog + * ?- call(fail). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + */ + fun testCallFail() + + /** + * Tests the queries + * ```prolog + * ?- call(fail,X). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + */ + fun testCallFailX() + + /** + * Tests the queries + * ```prolog + * ?- call(fail, call(1)). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + */ + fun testCallFailCall() + + /** + * Tests the queries + * ```prolog + * ?- call((write(3), X)). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + * producing exception `instantiation_error`. + */ + fun testCallWriteX() + + /** + * Tests the queries + * ```prolog + * ?- call((write(3), call(1))). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + * producing exception `type_error(callable,1)`. + */ + fun testCallWriteCall() + + /** + * Tests the queries + * ```prolog + * ?- call(X). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + * producing exception `instantiation_error`. + */ + fun testCallX() + + /** + * Tests the queries + * ```prolog + * ?- call(1). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + * producing exception `type_error(callable,1)`. + */ + fun testCallOne() + + /** + * Tests the queries + * ```prolog + * ?- call((fail,1)). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + * producing exception `type_error(callable,(fail,1))`. + */ + fun testCallFailOne() + + /** + * Tests the queries + * ```prolog + * ?- call((write(3),1)). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + * producing exception `type_error(callable,(write(3),1))`. + */ + fun testCallWriteOne() + + /** + * Tests the queries + * ```prolog + * ?- call((1; true)). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + * producing exception `type_error(callable,(1; true))`. + */ + fun testCallTrue() +} \ No newline at end of file diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestCallImpl.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestCallImpl.kt new file mode 100644 index 000000000..3584b6c09 --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestCallImpl.kt @@ -0,0 +1,229 @@ +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 TestCallImpl(private val solverFactory: SolverFactory) : TestCall { + override fun testCallCut() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = call("!") + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + } + } + + override fun testCallFail() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = call(fail) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + } + } + + override fun testCallFailX() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = call(fail and "X") + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + } + } + + override fun testCallFailCall() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = call(fail and call(1)) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + } + } + + override fun testCallWriteX() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = call(write(3) and "X") + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.halt( + InstantiationError.forGoal( + DummyInstances.executionContext, + Signature("call", 2), + varOf("X") + ) + ) + ), + solutions + ) + } + } + + override fun testCallWriteCall() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = call(write(3) and call(1)) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.halt( + TypeError.forGoal( + DummyInstances.executionContext, + Signature("call", 2), + TypeError.Expected.CALLABLE, + numOf(1) + + ) + ) + ), + solutions + ) + } + } + + override fun testCallX() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = call("X") + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.halt( + InstantiationError.forGoal( + DummyInstances.executionContext, + Signature("call", 1), + varOf("X") + ) + ) + ), + solutions + ) + } + } + + override fun testCallOne() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = call(1) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.halt( + TypeError.forGoal( + DummyInstances.executionContext, + Signature("call", 1), + TypeError.Expected.CALLABLE, + numOf(1) + + ) + ) + ), + solutions + ) + } + } + + override fun testCallFailOne() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = call(fail and 1) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.halt( + TypeError.forGoal( + DummyInstances.executionContext, + Signature("call", 2), + TypeError.Expected.CALLABLE, + fail and 1 //solver returns 1 + + + ) + ) + ), + solutions + ) + } + } + + override fun testCallWriteOne() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = call(write(3) and 1) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.halt( + TypeError.forGoal( + DummyInstances.executionContext, + Signature("call", 2), + TypeError.Expected.CALLABLE, + write(3) and 1 //solver returns 1 + + + ) + ) + ), + solutions + ) + } + } + + override fun testCallTrue() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = call(1 or true) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.halt( + TypeError.forGoal( + DummyInstances.executionContext, + Signature("call", 2), + TypeError.Expected.CALLABLE, + (1 or true) //solver returns 1 + + ) + ) + ), + solutions + ) + } + } +} \ 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 diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestFunctor.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestFunctor.kt new file mode 100644 index 000000000..e08f5e821 --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestFunctor.kt @@ -0,0 +1,173 @@ +package it.unibo.tuprolog.solve + +interface TestFunctor : SolverTest { + companion object { + fun prototype(solverFactory: SolverFactory): TestFunctor = + TestFunctorImpl(solverFactory) + } + + /** + * Tests the queries + * ```prolog + * ?- functor(foo(a,b,c),foo,3). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + */ + fun testFunArity() + + /** + * Tests the queries + * ```prolog + * ?- functor(foo(a,b,c),X,Y). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory, + * producing 2 solutions which binds the variable `X` to `foo` and the variable `Y` to `3` . + */ + fun testFunArityWithSub() + + /** + * Tests the queries + * ```prolog + * ?- functor(X,foo,0). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory, + * producing 1 solution which binds the variable `X` to `foo`. + */ + fun testFunArityZero() + + /** + * Tests the queries + * ```prolog + * ?- functor(mats(A,B),A,B). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory, + * producing 2 solutions which binds the variable `A` to `mats` and the variable `B` to `2` . + */ + fun testFunMats() + + /** + * Tests the queries + * ```prolog + * ?- functor(foo(a),foo,2). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + */ + fun testFunWrongArity() + + /** + * Tests the queries + * ```prolog + * ?- functor(foo(a),fo,1). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + */ + fun testFunWrongName() + + /** + * Tests the queries + * ```prolog + * ?- functor(1,X,Y). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory, + * producing 2 solutions which binds the variable `X` to `1` and the variable `Y` to `0` . + */ + fun testFunXNameYArity() + + /** + * Tests the queries + * ```prolog + * ?- functor(X,1.1,0). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory, + * producing 1 solution which binds the variable `X` to `1.1`. + */ + fun testFunDecNum() + + /** + * Tests the queries + * ```prolog + * ?- functor([_|_],'.',2). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + */ + fun testFunConsOf() + + /** + * Tests the queries + * ```prolog + * ?- functor([],[],0). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + */ + fun testFunEmptyList() + + /** + * Tests the query + * ```prolog + * ?- functor(X, Y, 3). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + * producing exception `instantiation_error`. + */ + fun testFunXYWrongArity() + + /** + * Tests the query + * ```prolog + * ?- functor(X, foo, N). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + * producing exception `instantiation_error`. + */ + fun testFunXNArity() + + /** + * Tests the query + * ```prolog + * ?- functor(X, foo, a). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + * producing exception `type_error(integer,a)`. + */ + fun testFunXAArity() + + /** + * Tests the query + * ```prolog + * ?- functor(X, 1.5, 1). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + * producing exception `type_error(atom,1.5)`. + */ + fun testFunNumName() + + /** + * Tests the query + * ```prolog + * ?- functor(X, foo, 1). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + * producing exception `type_error(atomic,foo(a))`. + */ + fun testFunFooName() + + /** + * Tests the query + * ```prolog + * ?- (current_prolog_flag(max_arity,A), X is A + 1, functor(T, foo, X)). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + * producing exception `representation_error(max_arity)`. + */ + fun testFunFlag() + + /** + * Tests the query + * ```prolog + * ?- functor(T, foo, -1). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + * producing exception `domain_error(not_less_than_zero,-1)`. + */ + fun testFunNegativeArity() +} \ No newline at end of file diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestFunctorImpl.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestFunctorImpl.kt new file mode 100644 index 000000000..3fa1eae0f --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestFunctorImpl.kt @@ -0,0 +1,299 @@ +package it.unibo.tuprolog.solve + +import it.unibo.tuprolog.dsl.theory.prolog +import it.unibo.tuprolog.solve.exception.error.DomainError +import it.unibo.tuprolog.solve.exception.error.InstantiationError +import it.unibo.tuprolog.solve.exception.error.TypeError + +internal class TestFunctorImpl(private val solverFactory: SolverFactory) : TestFunctor{ + override fun testFunArity() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = functor("foo"("a", "b", "c"), "foo", 3) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + } + } + + override fun testFunArityWithSub() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = functor("foo"("a", "b", "c"), "X", "Y") + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes("X" to "foo", "Y" to 3)), + solutions + ) + } + } + + override fun testFunArityZero() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = functor("X", "foo", 0) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes("X" to "foo")), + solutions + ) + } + } + + override fun testFunMats() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = functor("mats"("A", "B"), "A", "B") + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes("A" to "mats", "B" to 2)), + solutions + ) + } + } + + override fun testFunWrongArity() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = functor("foo"("a"), "foo", 2) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + } + } + + override fun testFunWrongName() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = functor("foo"("a"), "fo", 1) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + } + } + + override fun testFunXNameYArity() { //solver says exception_error + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = functor(1, "X", "Y") + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes("X" to 1, "Y" to 0)), + solutions + ) + } + } + + override fun testFunDecNum() { //solver says exception_error + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = functor("X", 1.1, 0) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes("X" to 1.1)), + solutions + ) + } + } + + override fun testFunConsOf() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = functor(consOf(`_`,`_`), ".", 2) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + } + } + + override fun testFunEmptyList() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = functor(emptyList, emptyList, 0) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + } + } + + override fun testFunXYWrongArity() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = functor("X", "Y", 3) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.halt( + InstantiationError.forGoal( + DummyInstances.executionContext, + Signature("functor", 3), + varOf("X") + ) + ) + ), + solutions + ) + } + } + + override fun testFunXNArity() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = functor("X", "foo", "N") + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.halt( + InstantiationError.forGoal( + DummyInstances.executionContext, + Signature("functor", 3), + varOf("N") + ) + ) + ), + solutions + ) + } + } + + override fun testFunXAArity() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = functor("X", "foo", "a") + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.halt( + TypeError.forGoal( + DummyInstances.executionContext, + Signature("functor", 3), + TypeError.Expected.INTEGER, + atomOf("a") + ) + ) + ), + solutions + ) + } + } + + override fun testFunNumName() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = functor("F", 1.5, 1) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.halt( + TypeError.forGoal( + DummyInstances.executionContext, + Signature("functor", 3), + TypeError.Expected.ATOM, + numOf(1.5) + ) + ) + ), + solutions + ) + } + } + + override fun testFunFooName() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = functor("F", "foo"("a"), 1) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.halt( + TypeError.forGoal( + DummyInstances.executionContext, + Signature("functor", 3), + TypeError.Expected.ATOM, // it has to ATOMIC + "foo"("a") + ) + ) + ), + solutions + ) + } + } + + override fun testFunFlag() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = ("current_prolog_flag"("max_arity", "A") and ("X" `is` "A" + 1) + and functor("T", "foo", "X")) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + } + } + + override fun testFunNegativeArity() { //solver returns yes(T to foo) + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = functor("T", "foo", -1) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.halt( + DomainError.forGoal( + DummyInstances.executionContext, + Signature("functor", 3), + DomainError.Expected.NOT_LESS_THAN_ZERO, + numOf(-1) + ) + ) + ), + solutions + ) + } + } +} \ No newline at end of file diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIfThen.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIfThen.kt new file mode 100644 index 000000000..23bd03f56 --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIfThen.kt @@ -0,0 +1,65 @@ +package it.unibo.tuprolog.solve + +interface TestIfThen : SolverTest { + companion object { + fun prototype(solverFactory: SolverFactory): TestIfThen = + TestIfThenImpl(solverFactory) + } + + /** + * Tests the queries + * ```prolog + * ?- '->'(true, true). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + */ + fun testIfThenTrue() + + /** + * Tests the queries + * ```prolog + * ?- '->'(true, fail). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + */ + fun testIfThenFail() + + /** + * Tests the queries + * ```prolog + * ?- '->'(fail, true). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + */ + fun testIfThenFailTrue() + + /** + * Tests the queries + * ```prolog + * ?- '->'(true, X=1). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory, + * producing 1 solution which binds variable `X` to `1`. + */ + fun testIfThenXtoOne() + + /** + * Tests the queries + * ```prolog + * ?- '->'(';'(X=1, X=2), true). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory, + * producing 1 solution which binds variable `X` to `1`. + */ + fun testIfThenXOr() + + /** + * Tests the queries + * ```prolog + * ?- '->'(true, ';'(X=1, X=2)). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory, + * producing 2 solutions which binds variable `X` to `1` and `X` to `2` . + */ + fun testIfThenOrWithDoubleSub() +} \ No newline at end of file diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIfThenElse.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIfThenElse.kt new file mode 100644 index 000000000..4fa07fd69 --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIfThenElse.kt @@ -0,0 +1,84 @@ +package it.unibo.tuprolog.solve + +interface TestIfThenElse : SolverTest { + companion object { + fun prototype(solverFactory: SolverFactory): TestIfThenElse = + TestIfThenElseImpl(solverFactory) + } + + /** + * Tests the queries + * ```prolog + * ?- ';'('->'(true, true), fail). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + */ + fun testIfTrueElseFail() + + /** + * Tests the queries + * ```prolog + * ?- ';'('->'(fail, true), true). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory. + */ + fun testIfFailElseTrue() + + /** + * Tests the queries + * ```prolog + * ?- ';'('->'(true, fail), fail). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory. + */ + fun testIfTrueThenElseFail() + + /** + * Tests the queries + * ```prolog + * ?- ';'('->'(fail, true), fail). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + */ + fun testIfFailElseFail() + + /** + * Tests the queries + * ```prolog + * ?- ';'('->'(true, X=1), X=2). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory, + * producing 1 solution which binds variable `X` to `1`. + */ + fun testIfXTrueElseX() + + /** + * Tests the queries + * ```prolog + * ?- ';'('->'(fail, X=1), X=2). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory, + * producing 1 solution which binds variable`X` to `2` . + */ + fun testIfFailElseX() + + /** + * Tests the queries + * ```prolog + * ?- ';'('->'(true, ';'(X=1, X=2)), true). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory, + * producing 2 solutions which binds variable `X` to `1` and `X` to `2`. + */ + fun testIfThenElseOrWithDoubleSub() + + /** + * Tests the queries + * ```prolog + * ?- ';'('->'(';'(X=1, X=2), true), true). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory, + * producing 1 solution which binds variable `X` to `1`. + */ + fun testIfOrElseTrue() +} \ No newline at end of file diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIfThenElseImpl.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIfThenElseImpl.kt new file mode 100644 index 000000000..438d9c505 --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIfThenElseImpl.kt @@ -0,0 +1,122 @@ +package it.unibo.tuprolog.solve + +import it.unibo.tuprolog.dsl.theory.prolog + +internal class TestIfThenElseImpl(private val solverFactory: SolverFactory) : TestIfThenElse{ + override fun testIfTrueElseFail() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = ";"("->"(true, true), fail) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + } + } + + override fun testIfFailElseTrue() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = ";"("->"(fail, true), true) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + } + } + + override fun testIfTrueThenElseFail() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = ";"("->"(true, fail), fail) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + } + } + + override fun testIfFailElseFail() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = ";"("->"(fail, true), fail) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + } + } + + override fun testIfXTrueElseX() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = ";"("->"(true, ("X" `=` 1)), "X" `=` 2) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes("X" to 1)), + solutions + ) + } + } + + override fun testIfFailElseX() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = ";"("->"(fail, ("X" `=` 1)), "X" `=` 2) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes("X" to 2)), + solutions + ) + } + } + + override fun testIfThenElseOrWithDoubleSub() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = ";"("->"(true,("X" `=` 1) or ("X" `=` 2)), true) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + with(query) { + kotlin.collections.listOf( + yes("X" to 1), + yes("X" to 2) + ) + }, + solutions + ) + } + } + + override fun testIfOrElseTrue() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = ";"("->"(("X" `=` 1) or ("X" `=` 2), true), true) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes("X" to 1)), + solutions + ) + } + } +} \ No newline at end of file diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIfThenImpl.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIfThenImpl.kt new file mode 100644 index 000000000..c13967717 --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIfThenImpl.kt @@ -0,0 +1,94 @@ +package it.unibo.tuprolog.solve + +import it.unibo.tuprolog.dsl.theory.prolog + +internal class TestIfThenImpl(private val solverFactory: SolverFactory) : TestIfThen{ + override fun testIfThenTrue() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = "->"(true, true) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes()), + solutions + ) + } + } + + override fun testIfThenFail() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = "->"(true, fail) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + } + } + + override fun testIfThenFailTrue() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = "->"(fail, true) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.no()), + solutions + ) + } + } + + override fun testIfThenXtoOne() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = "->"(true, "X" `=` 1) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes("X" to 1)), + solutions + ) + } + } + + override fun testIfThenXOr() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = "->"(("X" `=` 1) or ("X" `=` 2), true) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf(query.yes("X" to 1)), + solutions + ) + } + } + + override fun testIfThenOrWithDoubleSub() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = "->"(true,("X" `=` 1) or ("X" `=` 2)) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + with(query) { + kotlin.collections.listOf( + yes("X" to 1), + yes("X" to 2) + ) + }, + solutions + ) + } + } +} \ 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 diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestNotProvable.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestNotProvable.kt new file mode 100644 index 000000000..4ede4fa4b --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestNotProvable.kt @@ -0,0 +1,74 @@ +package it.unibo.tuprolog.solve + +interface TestNotProvable : SolverTest { + companion object { + fun prototype(solverFactory: SolverFactory): TestNotProvable = + TestNotProvableImpl(solverFactory) + } + + /** + * Tests the queries + * ```prolog + * ?- \+(true). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + */ + fun testNPTrue() + + /** + * Tests the queries + * ```prolog + * ?- \+(!). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + */ + fun testNPCut() + + /** + * Tests the queries + * ```prolog + * ?- \+(!,fail). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory, + */ + fun testNPCutFail() + + /** + * Tests the queries + * ```prolog + * ?- ((X = 1;X = 2), \+((!,fail))). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory, + * producing 2 solutions which binds variable `X` to `1` and `X` to `2`. + */ + fun testOrNotCutFail() + + /** + * Tests the queries + * ```prolog + * ?- \+(4 = 5). + * ``` + * succeeds on a solver initialized with default built-ins and with and empty theory, + */ + fun testNPEquals() + + /** + * Tests the queries + * ```prolog + * ?- \+(3). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + * producing exception `type_error(callable, 3)`. + */ + fun testNPNum() + + /** + * Tests the queries + * ```prolog + * ?- \+(X). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + * producing exception `instantiation_error`. + */ + fun testNPX() +} \ No newline at end of file diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestNotProvableImpl.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestNotProvableImpl.kt new file mode 100644 index 000000000..3424c4021 --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestNotProvableImpl.kt @@ -0,0 +1,133 @@ +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 + +class TestNotProvableImpl(private val solverFactory: SolverFactory) : TestNotProvable { + override fun testNPTrue() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = "not"(true) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.no()), + solutions + ) + } + } + + override fun testNPCut() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = "not"("!") + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.no()), + solutions + ) + } + } + + override fun testNPCutFail() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = "not"(("!" and fail)) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.yes()), + solutions + ) + } + } + + override fun testOrNotCutFail() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = ((("X" `=` 1) or ("X" `=` 2)) and "not"(("!" and fail))) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + with(query) { + kotlin.collections.listOf( + yes("X" to 1), + yes("X" to 2) + ) + }, + solutions + ) + } + } + + override fun testNPEquals() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = "not"(4 `=` 5) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.yes() + ), + solutions + ) + } + } + + override fun testNPNum() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = "not"(3) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.halt( + TypeError.forGoal( + DummyInstances.executionContext, + Signature("not", 1), + TypeError.Expected.CALLABLE, + numOf(3) + + ) + ) + ), + solutions + ) + } + } + + override fun testNPX() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = "not"("X") + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.halt( + InstantiationError.forGoal( + DummyInstances.executionContext, + Signature("not", 1), + varOf("X") + ) + ) + ), + solutions + ) + } + } +} \ No newline at end of file diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestRetract.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestRetract.kt new file mode 100644 index 000000000..a4bec1566 --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestRetract.kt @@ -0,0 +1,28 @@ +package it.unibo.tuprolog.solve + +interface TestRetract : SolverTest { + companion object { + fun prototype(solverFactory: SolverFactory): TestRetract = + TestRetractImpl(solverFactory) + } + + /** + * Tests the queries + * ```prolog + * ?- retract((4 :- X)). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + * producing exception `type_error(callable, 4))`. + */ + fun testRetractNumIfX() + + /** + * Tests the queries + * ```prolog + * ?- retract((atom(_) :- X == '[]')). + * ``` + * fails on a solver initialized with default built-ins and with and empty theory, + * producing exception `permission_error(modify,static_procedure,atom/1)`. + */ + fun testRetractAtomEmptyList() +} \ No newline at end of file diff --git a/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestRetractImpl.kt b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestRetractImpl.kt new file mode 100644 index 000000000..2703ccf13 --- /dev/null +++ b/test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestRetractImpl.kt @@ -0,0 +1,45 @@ +package it.unibo.tuprolog.solve + +import it.unibo.tuprolog.dsl.theory.prolog +import it.unibo.tuprolog.solve.exception.error.TypeError + +internal class TestRetractImpl(private val solverFactory: SolverFactory) : TestRetract { + override fun testRetractNumIfX() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = retract((4 `if` "X")) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.halt( + TypeError.forGoal( + DummyInstances.executionContext, + Signature("retract", 2), + TypeError.Expected.CALLABLE, + numOf(4) + + ) + ) + ), + solutions + ) + } + } + + override fun testRetractAtomEmptyList() { + prolog { + val solver = solverFactory.solverWithDefaultBuiltins() + + val query = retract((atom(`_`) `if` "X" `==` emptyList)) + val solutions = solver.solve(query, mediumDuration).toList() + + assertSolutionEquals( + kotlin.collections.listOf( + query.no()), //Permission_error + solutions + ) + } + } +} \ No newline at end of file