-
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
0481b6d
commit fda1f57
Showing
4 changed files
with
306 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicIfThenElse.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,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() | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...streams/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestStreamsIfThenElse.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,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() | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIfThenElse.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,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() | ||
} |
122 changes: 122 additions & 0 deletions
122
test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestIfThenElseImpl.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,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 | ||
) | ||
} | ||
} | ||
} |