Functor
This commit is contained in:
parent
dff53b4e68
commit
65c4d925d3
15 changed files with 270 additions and 83 deletions
|
@ -15,6 +15,7 @@ import prolog.ast.terms.CompoundTerm
|
|||
import prolog.ast.terms.Structure
|
||||
import prolog.ast.terms.Variable
|
||||
import prolog.builtins.Conjunction
|
||||
import prolog.ast.terms.FunctorInfo
|
||||
|
||||
class LogicGrammarTests {
|
||||
private lateinit var parser: Grammar<List<Clause>>
|
||||
|
@ -94,13 +95,13 @@ class LogicGrammarTests {
|
|||
|
||||
assertTrue(rule.head is Structure, "Expected head to be a structure")
|
||||
val head = rule.head as Structure
|
||||
assertEquals("parent/2", head.functor, "Expected functor 'parent/2'")
|
||||
assertEquals(FunctorInfo.of("parent/2"), head.functor, "Expected functor 'parent/2'")
|
||||
assertEquals(Variable("X"), head.arguments[0], "Expected first argument 'X'")
|
||||
assertEquals(Variable("Y"), head.arguments[1], "Expected second argument 'Y'")
|
||||
|
||||
assertTrue(rule.body is Structure, "Expected body to be a structure")
|
||||
val body = rule.body as Structure
|
||||
assertEquals("father/2", body.functor, "Expected functor 'father/2'")
|
||||
assertEquals(FunctorInfo.of("father/2"), body.functor, "Expected functor 'father/2'")
|
||||
assertEquals(Variable("X"), body.arguments[0], "Expected first argument 'X'")
|
||||
assertEquals(Variable("Y"), body.arguments[1], "Expected second argument 'Y'")
|
||||
}
|
||||
|
@ -125,12 +126,12 @@ class LogicGrammarTests {
|
|||
|
||||
assertEquals(1, result.size, "Expected 1 rule")
|
||||
val rule = result[0] as Rule
|
||||
assertEquals("guest/2", rule.head.functor, "Expected functor 'guest/2'")
|
||||
assertEquals(",/2", (rule.body as CompoundTerm).functor, "Expected functor ',/2'")
|
||||
assertEquals(FunctorInfo.of("guest/2"), rule.head.functor, "Expected functor 'guest/2'")
|
||||
assertEquals(FunctorInfo.of(",/2"), (rule.body as CompoundTerm).functor, "Expected functor ',/2'")
|
||||
val l1 = (rule.body as CompoundTerm).arguments[0] as CompoundTerm
|
||||
assertEquals(",/2", l1.functor, "Expected functor ',/2'")
|
||||
assertEquals(FunctorInfo.of(",/2"), l1.functor, "Expected functor ',/2'")
|
||||
val l2 = l1.arguments[0] as CompoundTerm
|
||||
assertEquals("invited/2", l2.functor, "Expected functor 'invited/2'")
|
||||
assertEquals(FunctorInfo.of("invited/2"), l2.functor, "Expected functor 'invited/2'")
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -157,6 +158,6 @@ class LogicGrammarTests {
|
|||
assertEquals(1, result.size, "Expected 1 rule")
|
||||
assertTrue(result[0] is Rule, "Expected a rule")
|
||||
val rule = result[0] as Rule
|
||||
assertEquals("/_", rule.head.functor, "Expected a constraint")
|
||||
assertEquals(FunctorInfo.of("/0"), rule.head.functor, "Expected a constraint")
|
||||
}
|
||||
}
|
Reference in a new issue