-
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
a3f907e
commit 0455535
Showing
3 changed files
with
242 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
solve-classic/src/commonTest/kotlin/it/unibo/tuprolog/solve/systemtest/TestClassicAtomic.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.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.AliasedLibrary | ||
import it.unibo.tuprolog.solve.library.Libraries | ||
import it.unibo.tuprolog.solve.stdlib.DefaultBuiltins | ||
import it.unibo.tuprolog.theory.Theory | ||
import kotlin.test.Test | ||
|
||
class TestClassicAtomic : TestAtomic, SolverFactory{ | ||
private val prototype = TestAtomic.prototype(this) | ||
|
||
override val defaultBuiltins: AliasedLibrary | ||
get() = DefaultBuiltins | ||
|
||
override fun solverOf( | ||
libraries: Libraries, | ||
flags: FlagStore, | ||
staticKb: Theory, | ||
dynamicKb: Theory, | ||
stdIn: InputChannel<String>, | ||
stdOut: OutputChannel<String>, | ||
stdErr: OutputChannel<String>, | ||
warnings: OutputChannel<PrologWarning> | ||
) = Solver.classic( | ||
libraries, flags, staticKb, dynamicKb, stdIn, stdOut, stdErr, warnings | ||
) | ||
|
||
override fun mutableSolverOf( | ||
libraries: Libraries, | ||
flags: FlagStore, | ||
staticKb: Theory, | ||
dynamicKb: Theory, | ||
stdIn: InputChannel<String>, | ||
stdOut: OutputChannel<String>, | ||
stdErr: OutputChannel<String>, | ||
warnings: OutputChannel<PrologWarning> | ||
) = MutableSolver.classic( | ||
libraries, flags, staticKb, dynamicKb, stdIn, stdOut, stdErr, warnings | ||
) | ||
|
||
@Test | ||
override fun testAtomicAtom(){ | ||
prototype.testAtomicAtom() | ||
} | ||
|
||
@Test | ||
override fun testAtomicAofB(){ | ||
prototype.testAtomicAofB() | ||
} | ||
|
||
@Test | ||
override fun testAtomicVar(){ | ||
prototype.testAtomicVar() | ||
} | ||
|
||
@Test | ||
override fun testAtomicEmptyList(){ | ||
prototype.testAtomicEmptyList() | ||
} | ||
|
||
@Test | ||
override fun testAtomicNum(){ | ||
prototype.testAtomicNum() | ||
} | ||
|
||
@Test | ||
override fun testAtomicNumDec(){ | ||
prototype.testAtomicNumDec() | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestAtomic.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,77 @@ | ||
package it.unibo.tuprolog.solve | ||
|
||
/** | ||
* Tests of atomic | ||
*/ | ||
interface TestAtomic { | ||
companion object{ | ||
fun prototype(solverFactory: SolverFactory): TestAtomic = | ||
TestAtomicImpl(solverFactory) | ||
} | ||
|
||
/** A short test max duration */ | ||
val shortDuration: TimeDuration | ||
get() = 250L | ||
|
||
/** A medium test max duration */ | ||
val mediumDuration: TimeDuration | ||
get() = 2 * shortDuration | ||
|
||
/** A long test max duration */ | ||
val longDuration: TimeDuration | ||
get() = 4 * mediumDuration | ||
|
||
/** | ||
* Tests the queries | ||
* ```prolog | ||
* ?- atomic(atom). | ||
* ``` | ||
* succeeds on a solver initialized with default built-ins and with and empty theory. | ||
*/ | ||
fun testAtomicAtom() | ||
|
||
/** | ||
* Tests the queries | ||
* ```prolog | ||
* ?- atomic(a(b)). | ||
* ``` | ||
* fails on a solver initialized with default built-ins and with and empty theory. | ||
*/ | ||
fun testAtomicAofB() | ||
|
||
/** | ||
* Tests the queries | ||
* ```prolog | ||
* ?- atomic(Var). | ||
* ``` | ||
* fails on a solver initialized with default built-ins and with and empty theory. | ||
*/ | ||
fun testAtomicVar() | ||
|
||
/** | ||
* Tests the queries | ||
* ```prolog | ||
* ?- atomic([]). | ||
* ``` | ||
* succeeds on a solver initialized with default built-ins and with and empty theory. | ||
*/ | ||
fun testAtomicEmptyList() | ||
|
||
/** | ||
* Tests the queries | ||
* ```prolog | ||
* ?- atomic(6). | ||
* ``` | ||
* succeeds on a solver initialized with default built-ins and with and empty theory. | ||
*/ | ||
fun testAtomicNum() | ||
|
||
/** | ||
* Tests the queries | ||
* ```prolog | ||
* ?- atomic(3.3). | ||
* ``` | ||
* succeeds on a solver initialized with default built-ins and with and empty theory. | ||
*/ | ||
fun testAtomicNumDec() | ||
} |
91 changes: 91 additions & 0 deletions
91
test-solve/src/commonMain/kotlin/it/unibo/tuprolog/solve/TestAtomicImpl.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,91 @@ | ||
package it.unibo.tuprolog.solve | ||
|
||
import it.unibo.tuprolog.dsl.theory.prolog | ||
import kotlin.collections.listOf as ktListOf | ||
|
||
internal class TestAtomicImpl(private val solverFactory: SolverFactory) : TestAtomic { | ||
|
||
override fun testAtomicAtom() { | ||
prolog { | ||
val solver = solverFactory.solverWithDefaultBuiltins() | ||
|
||
var query = atomic("atom") | ||
var solutions = solver.solve(query, mediumDuration).toList() | ||
|
||
assertSolutionEquals( | ||
ktListOf(query.yes()), | ||
solutions | ||
) | ||
} | ||
} | ||
|
||
override fun testAtomicAofB() { | ||
prolog { | ||
val solver = solverFactory.solverWithDefaultBuiltins() | ||
|
||
var query = atomic("a"("b")) | ||
var solutions = solver.solve(query, mediumDuration).toList() | ||
|
||
assertSolutionEquals( | ||
ktListOf(query.no()), | ||
solutions | ||
) | ||
} | ||
} | ||
|
||
override fun testAtomicVar() { | ||
prolog { | ||
val solver = solverFactory.solverWithDefaultBuiltins() | ||
|
||
var query = atomic("Var") | ||
var solutions = solver.solve(query, mediumDuration).toList() | ||
|
||
assertSolutionEquals( | ||
ktListOf(query.no()), | ||
solutions | ||
) | ||
} | ||
} | ||
|
||
override fun testAtomicEmptyList() { | ||
prolog { | ||
val solver = solverFactory.solverWithDefaultBuiltins() | ||
|
||
var query = atomic(emptyList) | ||
var solutions = solver.solve(query, mediumDuration).toList() | ||
|
||
assertSolutionEquals( | ||
ktListOf(query.yes()), | ||
solutions | ||
) | ||
} | ||
} | ||
|
||
override fun testAtomicNum() { | ||
prolog { | ||
val solver = solverFactory.solverWithDefaultBuiltins() | ||
|
||
var query = atomic(6) | ||
var solutions = solver.solve(query, mediumDuration).toList() | ||
|
||
assertSolutionEquals( | ||
ktListOf(query.yes()), | ||
solutions | ||
) | ||
} | ||
} | ||
|
||
override fun testAtomicNumDec() { | ||
prolog { | ||
val solver = solverFactory.solverWithDefaultBuiltins() | ||
|
||
var query = atomic(3.3) | ||
var solutions = solver.solve(query, mediumDuration).toList() | ||
|
||
assertSolutionEquals( | ||
ktListOf(query.yes()), | ||
solutions | ||
) | ||
} | ||
} | ||
} |