test: Cut not_equal

This commit is contained in:
Tibo De Peuter 2025-04-15 16:40:52 +02:00
parent 229a8bbc3c
commit 2fcab52f65
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
7 changed files with 75 additions and 18 deletions

View file

@ -17,6 +17,8 @@ class ControlOperatorsTests {
Program.clear()
}
// See also: https://stackoverflow.com/a/23292126
@Test
fun `simple cut program`() {
// First an example without cut
@ -149,6 +151,32 @@ class ControlOperatorsTests {
assertEquals(1, result.size, "Expected 1 result")
}
@Test
fun `not_equal cut test`() {
Program.load(
listOf(
Rule(
CompoundTerm(Atom("not_equal"), listOf(Variable("X"), Variable("Y"))),
Conjunction(
Unify(Variable("X"), Variable("Y")),
Conjunction(Cut(), Fail)
)
),
Fact(CompoundTerm(Atom("not_equal"), listOf(Variable("_1"), Variable("_2"))))
)
)
var goal = CompoundTerm(Atom("not_equal"), listOf(Integer(1), Integer(1)))
var result = Program.query(goal).toList()
assertTrue(result.none(), "Expected no results")
goal = CompoundTerm(Atom("not_equal"), listOf(Integer(1), Integer(2)))
result = Program.query(goal).toList()
assertEquals(1, result.size, "Expected 1 result")
}
@Test
fun not_atom() {
val success = Fact(Atom("a"))