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

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

There is a newer version: 1.0.4
Show newest version
package it.unibo.tuprolog.solve

import it.unibo.tuprolog.dsl.theory.logicProgramming

internal class TestCompoundImpl(private val solverFactory: SolverFactory) : TestCompound {
    override fun testCompoundDec() {
        logicProgramming {
            val solver = solverFactory.solverWithDefaultBuiltins()

            val query = compound(33.3)
            val solutions = solver.solve(query, mediumDuration).toList()

            assertSolutionEquals(
                listOf(query.no()),
                solutions,
            )
        }
    }

    override fun testCompoundNegDec() {
        logicProgramming {
            val solver = solverFactory.solverWithDefaultBuiltins()

            val query = compound(-33.3)
            val solutions = solver.solve(query, mediumDuration).toList()

            assertSolutionEquals(
                listOf(query.no()),
                solutions,
            )
        }
    }

    override fun testCompoundNegA() {
        logicProgramming {
            val solver = solverFactory.solverWithDefaultBuiltins()

            val query = compound("-"("a"))
            val solutions = solver.solve(query, mediumDuration).toList()

            assertSolutionEquals(
                listOf(query.yes()),
                solutions,
            )
        }
    }

    override fun testCompoundAny() {
        logicProgramming {
            val solver = solverFactory.solverWithDefaultBuiltins()

            val query = compound(`_`)
            val solutions = solver.solve(query, mediumDuration).toList()

            assertSolutionEquals(
                listOf(query.no()),
                solutions,
            )
        }
    }

    override fun testCompoundA() {
        logicProgramming {
            val solver = solverFactory.solverWithDefaultBuiltins()

            val query = compound("a")
            val solutions = solver.solve(query, mediumDuration).toList()

            assertSolutionEquals(
                listOf(query.no()),
                solutions,
            )
        }
    }

    override fun testCompoundAOfB() {
        logicProgramming {
            val solver = solverFactory.solverWithDefaultBuiltins()

            val query = compound("a"("b"))
            val solutions = solver.solve(query, mediumDuration).toList()

            assertSolutionEquals(
                listOf(query.yes()),
                solutions,
            )
        }
    }

    override fun testCompoundListA() {
        logicProgramming {
            val solver = solverFactory.solverWithDefaultBuiltins()

            val query = compound(logicListOf("a"))
            val solutions = solver.solve(query, mediumDuration).toList()

            assertSolutionEquals(
                listOf(query.yes()),
                solutions,
            )
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy