-
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
fda1f57
commit e631afb
Showing
4 changed files
with
256 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicIs.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,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() | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
solve-streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsIs.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,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() | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIs.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,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() | ||
} |
109 changes: 109 additions & 0 deletions
109
test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIsImpl.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,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 | ||
) | ||
} | ||
} | ||
} |