66 lines
No EOL
1.6 KiB
Kotlin
66 lines
No EOL
1.6 KiB
Kotlin
package prolog.builtins
|
|
|
|
import org.junit.jupiter.api.Assertions.assertFalse
|
|
import org.junit.jupiter.api.Assertions.assertTrue
|
|
import org.junit.jupiter.api.BeforeEach
|
|
import org.junit.jupiter.api.Test
|
|
import prolog.Program
|
|
import prolog.ast.logic.Fact
|
|
import prolog.ast.terms.Atom
|
|
|
|
class ControlTest {
|
|
@BeforeEach
|
|
fun setUp() {
|
|
Program.clear()
|
|
}
|
|
|
|
@Test
|
|
fun not_atom() {
|
|
val success = Fact(Atom("a"))
|
|
|
|
Program.load(listOf(success))
|
|
|
|
val goal = Atom("a")
|
|
val notGoal = Not(goal)
|
|
|
|
val result1 = Program.query(goal)
|
|
val result2 = Program.query(notGoal)
|
|
|
|
assertTrue(result1.any(), "Expected query to succeed")
|
|
assertFalse(result2.any(), "Expected query to fail")
|
|
}
|
|
|
|
@Test
|
|
fun not_compound() {
|
|
val success = Fact(Atom("f"))
|
|
val failure = Fact(Atom("g"))
|
|
|
|
Program.load(listOf(success, failure))
|
|
|
|
val goal = Atom("f")
|
|
val notGoal = Not(Atom("g"))
|
|
|
|
val result1 = Program.query(goal)
|
|
val result2 = Program.query(notGoal)
|
|
|
|
assertTrue(result1.any(), "Expected query to succeed")
|
|
assertFalse(result2.any(), "Expected query to fail")
|
|
}
|
|
|
|
@Test
|
|
fun fail_should_cause_fails() {
|
|
val success = Fact(Atom("a"))
|
|
val failure = Fact(Atom("b"))
|
|
|
|
Program.load(listOf(success, failure))
|
|
|
|
val goal = Atom("a")
|
|
val failGoal = Fail
|
|
|
|
val result1 = Program.query(goal)
|
|
val result2 = Program.query(failGoal)
|
|
|
|
assertTrue(result1.any(), "Expected query to succeed")
|
|
assertFalse(result2.any(), "Expected query to fail")
|
|
}
|
|
} |