Skip to content

Commit

Permalink
improve tests for unification in clause retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
gciatto committed Jun 20, 2020
1 parent 0bbafa1 commit f338cd1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ object Retract : UnaryPredicate<ExecutionContext>("retract") {
is Clause -> (first mguWith result.firstClause) as Substitution.Unifier
else -> (first mguWith result.firstClause.head!!) as Substitution.Unifier
}
yield(
replySuccess(substitution = substitution, dynamicKb = dynamicKb)
)
yield(replySuccess(substitution = substitution, dynamicKb = dynamicKb))
} else {
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ internal abstract class PrototypeClauseCollectionTestImpl(

private val emptyCollection = emptyGenerator()

private fun member(first: Term, second: Term): Fact =
Fact.of(Struct.of("member", first, second))

protected abstract fun getClauses(collection: ClauseCollection, query: Clause): Sequence<Clause>

protected abstract fun retractClauses(collection: ClauseCollection, query: Clause): Sequence<Clause>
Expand All @@ -75,11 +78,29 @@ internal abstract class PrototypeClauseCollectionTestImpl(

assertClausesHaveSameLengthAndContent(
sequenceOf(member),
getClauses(collection, Fact.of(Struct.of("member", Atom.of("a"), LogicList.of(Atom.of("a")))))
getClauses(collection, Scope.empty {
member(
listOf(structOf("a", varOf("X"))),
listOf(listOf(structOf("a", numOf(1))))
)
})
)
assertClausesHaveSameLengthAndContent(
sequenceOf(member),
getClauses(collection, member(Atom.of("a"), LogicList.of(Atom.of("a"))))
)
assertClausesHaveSameLengthAndContent(
sequenceOf(),
getClauses(collection, Scope.empty {
member(
listOf(structOf("a", varOf("X"))),
listOf(listOf(structOf("b", numOf(1))))
)
})
)
assertClausesHaveSameLengthAndContent(
sequenceOf(),
getClauses(collection, Fact.of(Struct.of("member", Atom.of("a"), LogicList.of(Atom.of("b")))))
getClauses(collection, member(Atom.of("a"), LogicList.of(Atom.of("b"))))
)
}

Expand All @@ -88,14 +109,38 @@ internal abstract class PrototypeClauseCollectionTestImpl(

assertClausesHaveSameLengthAndContent(
sequenceOf(member),
retractClauses(collection, Fact.of(Struct.of("member", Atom.of("a"), LogicList.of(Atom.of("a")))))
retractClauses(collection, Scope.empty {
member(
listOf(structOf("a", varOf("X"))),
listOf(listOf(structOf("a", numOf(1))))
)
})
)

collection = collectionGenerator(listOf(member))

assertClausesHaveSameLengthAndContent(
sequenceOf(member),
retractClauses(collection, member(Atom.of("a"), LogicList.of(Atom.of("a"))))
)

collection = collectionGenerator(listOf(member))

assertClausesHaveSameLengthAndContent(
sequenceOf(),
retractClauses(collection, Scope.empty {
member(
listOf(structOf("a", varOf("X"))),
listOf(listOf(structOf("b", numOf(1))))
)
})
)

collection = collectionGenerator(listOf(member))

assertClausesHaveSameLengthAndContent(
sequenceOf(),
retractClauses(collection, Fact.of(Struct.of("member", Atom.of("a"), LogicList.of(Atom.of("b")))))
retractClauses(collection, member(Atom.of("a"), LogicList.of(Atom.of("b"))))
)
}

Expand Down Expand Up @@ -128,8 +173,7 @@ internal abstract class PrototypeClauseCollectionTestImpl(
}

override fun collectionIsEmptyAfterRemovingEveryElement() {
val emptiedCollection =
collectionGenerator(clauses).retrieveAll(fFamilySelector).collection
val emptiedCollection = collectionGenerator(clauses).retrieveAll(fFamilySelector).collection

assertTrue(emptiedCollection.isEmpty())
}
Expand Down

0 comments on commit f338cd1

Please sign in to comment.