Checkpoint
This commit is contained in:
parent
e3c84e1761
commit
e73e5cbfc8
32 changed files with 1354 additions and 92 deletions
|
@ -1,66 +0,0 @@
|
|||
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 ControlBuiltinsTest {
|
||||
@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")
|
||||
}
|
||||
}
|
Reference in a new issue