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")
|
||||
}
|
||||
}
|
|
@ -3,9 +3,8 @@ package prolog.builtins
|
|||
import org.junit.jupiter.api.Assertions.assertFalse
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import prolog.components.terms.Atom
|
||||
import prolog.components.terms.Structure
|
||||
import prolog.ast.terms.Atom
|
||||
import prolog.ast.terms.Structure
|
||||
|
||||
/**
|
||||
* Based on [Predicates for analyzing/constructing terms](https://github.com/dtonhofer/prolog_notes/blob/master/swipl_notes/about_term_analysis_and_construction/term_analysis_construction.png)
|
||||
|
|
|
@ -3,12 +3,12 @@ package prolog.builtins
|
|||
import org.junit.jupiter.api.Assertions.assertFalse
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
import prolog.components.terms.Atom
|
||||
import prolog.components.terms.Structure
|
||||
import prolog.components.terms.Variable
|
||||
import prolog.ast.terms.Atom
|
||||
import prolog.ast.terms.Structure
|
||||
import prolog.ast.terms.Variable
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class BuiltinsTest {
|
||||
class VerificationBuiltinsTest {
|
||||
@Test
|
||||
fun unbound_variable_is_var() {
|
||||
val variable = Variable("X")
|
||||
|
|
Reference in a new issue