Checkpoint
This commit is contained in:
parent
ef8b82457c
commit
d702b9b081
13 changed files with 114 additions and 63 deletions
|
@ -1,7 +1,6 @@
|
|||
package prolog
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertFalse
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import prolog.builtins.Conjunction
|
||||
|
@ -11,6 +10,7 @@ import prolog.components.expressions.Fact
|
|||
import prolog.components.expressions.Rule
|
||||
import prolog.components.terms.Atom
|
||||
import prolog.components.terms.Structure
|
||||
import prolog.components.terms.Variable
|
||||
|
||||
class EvaluationTest {
|
||||
@BeforeEach
|
||||
|
@ -23,7 +23,9 @@ class EvaluationTest {
|
|||
val fact = Fact(Atom("a"))
|
||||
Program.load(listOf(fact))
|
||||
|
||||
assertTrue(Program.query(Atom("a")))
|
||||
val result = Program.query(Atom("a"))
|
||||
|
||||
assertTrue(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -75,14 +77,14 @@ class EvaluationTest {
|
|||
val mother = Fact(Structure(Atom("mother"), listOf(Atom("jane"), Atom("jimmy"))))
|
||||
|
||||
val parent1 = Rule(
|
||||
Structure(Atom("parent"), listOf(Atom("X"), Atom("Y"))),
|
||||
Structure(Atom("parent"), listOf(Variable("X"), Variable("Y"))),
|
||||
/* :- */
|
||||
Structure(Atom("father"), listOf(Atom("X"), Atom("Y")))
|
||||
Structure(Atom("father"), listOf(Variable("X"), Variable("Y")))
|
||||
)
|
||||
val parent2 = Rule(
|
||||
Structure(Atom("parent"), listOf(Atom("X"), Atom("Y"))),
|
||||
Structure(Atom("parent"), listOf(Variable("X"), Variable("Y"))),
|
||||
/* :- */
|
||||
Structure(Atom("mother"), listOf(Atom("X"), Atom("Y")))
|
||||
Structure(Atom("mother"), listOf(Variable("X"), Variable("Y")))
|
||||
)
|
||||
|
||||
Program.load(listOf(father, mother, parent1, parent2))
|
||||
|
@ -100,11 +102,11 @@ class EvaluationTest {
|
|||
val mother = Fact(Structure(Atom("mother"), listOf(Atom("jane"), Atom("jimmy"))))
|
||||
|
||||
val parent = Rule(
|
||||
Structure(Atom("parent"), listOf(Atom("X"), Atom("Y"))),
|
||||
Structure(Atom("parent"), listOf(Variable("X"), Variable("Y"))),
|
||||
/* :- */ Disjunction(
|
||||
Structure(Atom("father"), listOf(Atom("X"), Atom("Y"))),
|
||||
Structure(Atom("father"), listOf(Variable("X"), Variable("Y"))),
|
||||
/* ; */
|
||||
Structure(Atom("mother"), listOf(Atom("X"), Atom("Y")))
|
||||
Structure(Atom("mother"), listOf(Variable("X"), Variable("Y")))
|
||||
))
|
||||
|
||||
Program.load(listOf(father, mother, parent))
|
||||
|
@ -129,17 +131,17 @@ class EvaluationTest {
|
|||
val parent2 = Fact(Structure(Atom("parent"), listOf(Atom("jane"), Atom("jimmy"))))
|
||||
|
||||
val isFather = Rule(
|
||||
Structure(Atom("isFather"), listOf(Atom("X"), Atom("Y"))),
|
||||
Structure(Atom("isFather"), listOf(Variable("X"), Variable("Y"))),
|
||||
Conjunction(
|
||||
Structure(Atom("parent"), listOf(Atom("X"), Atom("Y"))),
|
||||
Structure(Atom("male"), listOf(Atom("X")))
|
||||
Structure(Atom("parent"), listOf(Variable("X"), Variable("Y"))),
|
||||
Structure(Atom("male"), listOf(Variable("X")))
|
||||
)
|
||||
)
|
||||
val isMother = Rule(
|
||||
Structure(Atom("isMother"), listOf(Atom("X"), Atom("Y"))),
|
||||
Structure(Atom("isMother"), listOf(Variable("X"), Variable("Y"))),
|
||||
Conjunction(
|
||||
Structure(Atom("parent"), listOf(Atom("X"), Atom("Y"))),
|
||||
Structure(Atom("female"), listOf(Atom("X")))
|
||||
Structure(Atom("parent"), listOf(Variable("X"), Variable("Y"))),
|
||||
Structure(Atom("female"), listOf(Variable("X")))
|
||||
)
|
||||
)
|
||||
|
||||
|
|
Reference in a new issue