Call & Ignore
This commit is contained in:
parent
9b454a9669
commit
5bfeb96176
7 changed files with 118 additions and 28 deletions
34
tests/prolog/builtins/MetaOperatorsTests.kt
Normal file
34
tests/prolog/builtins/MetaOperatorsTests.kt
Normal file
|
@ -0,0 +1,34 @@
|
|||
package prolog.builtins
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
import prolog.ast.arithmetic.Integer
|
||||
import prolog.ast.lists.List.Cons
|
||||
import prolog.ast.lists.List.Empty
|
||||
import prolog.ast.terms.Variable
|
||||
|
||||
class MetaOperatorsTests {
|
||||
@Test
|
||||
fun `ignore of failing goal succeeds`() {
|
||||
val goal = Member(Integer(4), Cons(Integer(1), Cons(Integer(2), Cons(Integer(3), Empty))))
|
||||
|
||||
val result = Ignore(goal).satisfy(emptyMap()).toList()
|
||||
|
||||
assertEquals(1, result.size, "Should return one result")
|
||||
assertTrue(result[0].isSuccess, "Result should be successful")
|
||||
assertTrue(result[0].getOrNull()!!.isEmpty(), "Expected empty substitutions")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ignore of succeeding goal returns first solution`() {
|
||||
val goal = Member(Variable("X"), Cons(Integer(1), Cons(Integer(2), Cons(Integer(3), Empty))))
|
||||
|
||||
val result = Ignore(goal).satisfy(emptyMap()).toList()
|
||||
|
||||
assertEquals(1, result.size, "Should return one result")
|
||||
assertTrue(result[0].isSuccess, "Result should be successful")
|
||||
val subs = result[0].getOrNull()!!
|
||||
assertEquals(Integer(1), subs[Variable("X")], "Expected first solution to be 1")
|
||||
}
|
||||
}
|
Reference in a new issue