-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c9477c
commit 5b348db
Showing
4 changed files
with
303 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...lassic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicNotProvable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...treams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsNotProvable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestNotProvable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} |
133 changes: 133 additions & 0 deletions
133
test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestNotProvableImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) | ||
} | ||
} | ||
} |