Skip to content

Commit

Permalink
Test Atomic implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideGreco committed Aug 27, 2020
1 parent a3f907e commit 0455535
Show file tree
Hide file tree
Showing 3 changed files with 242 additions and 0 deletions.
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()
}
}
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()
}
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
)
}
}
}

0 comments on commit 0455535

Please sign in to comment.