Coverage Summary for Class: ContainsAny (it.unibo.tuprolog.argumentation.core.primitives.utils)
| Class |
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| ContainsAny |
100%
(2/2)
|
75%
(3/4)
|
68.8%
(11/16)
|
83.6%
(46/55)
|
| ContainsAny$solve$1 |
100%
(1/1)
|
|
100%
(2/2)
|
100%
(45/45)
|
| Total |
100%
(3/3)
|
75%
(3/4)
|
72.2%
(13/18)
|
91%
(91/100)
|
package it.unibo.tuprolog.argumentation.core.primitives.utils
import it.unibo.tuprolog.argumentation.core.runtime.Arg2pUnificator
import it.unibo.tuprolog.core.List
import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.Signature
import it.unibo.tuprolog.solve.exception.error.TypeError
import it.unibo.tuprolog.solve.primitive.Primitive
import it.unibo.tuprolog.solve.primitive.Solve
/**
* containsAny(+Elements, +List): an element of List matches one of Elements (without binding them)
*/
internal object ContainsAny : Primitive {
val signature: Signature = Signature("containsAny", 2)
override fun solve(request: Solve.Request<ExecutionContext>): Sequence<Solve.Response> {
val elemList: Term = request.arguments[0]
val list: Term = request.arguments[1]
if (list !is List) {
throw TypeError.forGoal(
request.context,
request.signature,
TypeError.Expected.LIST,
list,
)
}
if (elemList !is List) {
throw TypeError.forGoal(
request.context,
request.signature,
TypeError.Expected.LIST,
elemList,
)
}
return sequence {
yield(
request.replyWith(list.toSequence().any { elemList.toSequence().any { elem -> Arg2pUnificator.match(it, elem) } }),
)
}
}
}