refactor: Herstructurering
This commit is contained in:
parent
1acd1cfb67
commit
e3c84e1761
33 changed files with 290 additions and 178 deletions
66
tests/prolog/builtins/ControlBuiltinsTest.kt
Normal file
66
tests/prolog/builtins/ControlBuiltinsTest.kt
Normal file
|
@ -0,0 +1,66 @@
|
|||
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