From f9950a3fd39c90f33f78cd514661e7588999a4de Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Tue, 15 Apr 2025 17:03:14 +0200 Subject: [PATCH] test: Cut with disjunction --- examples/scratchpad.pl | 3 +-- .../prolog/builtins/ControlOperatorsTests.kt | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/examples/scratchpad.pl b/examples/scratchpad.pl index 2959dee..357e09b 100644 --- a/examples/scratchpad.pl +++ b/examples/scratchpad.pl @@ -1,2 +1 @@ -not_equal(X, Y) :- X = Y, !, fail. -not_equal(_, _). \ No newline at end of file +choice(X) :- X = 1, !; X = 2. diff --git a/tests/prolog/builtins/ControlOperatorsTests.kt b/tests/prolog/builtins/ControlOperatorsTests.kt index 7b5be77..598d3fd 100644 --- a/tests/prolog/builtins/ControlOperatorsTests.kt +++ b/tests/prolog/builtins/ControlOperatorsTests.kt @@ -177,6 +177,30 @@ class ControlOperatorsTests { assertEquals(1, result.size, "Expected 1 result") } + @Test + fun `cut with disjunction`() { + Program.load( + listOf( + Rule( + CompoundTerm(Atom("choice"), listOf(Variable("X"))), + Conjunction( + Unify(Variable("X"), Integer(1)), + Disjunction( + Cut(), + Unify(Variable("X"), Integer(2)) + ) + ) + ) + ) + ) + + val goal = CompoundTerm(Atom("choice"), listOf(Variable("X"))) + + val result = Program.query(goal).toList() + + assertEquals(1, result.size, "Expected 1 result") + } + @Test fun not_atom() { val success = Fact(Atom("a"))