All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.it.unibo.tuprolog.solve.TestRetractImpl.kt Maven / Gradle / Ivy

package it.unibo.tuprolog.solve

import it.unibo.tuprolog.dsl.theory.prolog
import it.unibo.tuprolog.solve.exception.error.DomainError
import it.unibo.tuprolog.solve.exception.error.PermissionError

internal class TestRetractImpl(private val solverFactory: SolverFactory) : TestRetract {
    override fun testRetractNumIfX() {
        prolog {
            val solver = solverFactory.solverWithDefaultBuiltins()

            val query = retract(":-"(4, "X"))
            val solutions = solver.solve(query, mediumDuration).toList()

            assertSolutionEquals(
                kotlin.collections.listOf(
                    query.halt(
                        DomainError.forArgument(
                            DummyInstances.executionContext,
                            Signature("retract", 1),
                            DomainError.Expected.CLAUSE,
                            ":-"(4, "X"),
                            index = 0
                        )
                    )
                ),
                solutions
            )
        }
    }

    override fun testRetractAtomEmptyList() {
        prolog {
            val solver = solverFactory.solverWithDefaultBuiltins()

            val query = retract((atom(`_`) `if` ("X" `==` emptyList)))
            val solutions = solver.solve(query, mediumDuration).toList()

            assertSolutionEquals(
                kotlin.collections.listOf(
                    query.halt(
                        PermissionError.of(
                            DummyInstances.executionContext,
                            Signature("retract", 1),
                            PermissionError.Operation.MODIFY,
                            PermissionError.Permission.PRIVATE_PROCEDURE,
                            "atom" / 1
                        )
                    )
                ), // Permission_error
                solutions
            )
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy