DirectiveTestsUtils

Shared helpers for TestDirectives, covering directive-related behavior (dynamic/1, static/1, initialization/1, solve/1, flag/operator-setting directives, and how a Solver/MutableSolver reacts to loading a theory built from them) that would otherwise require boilerplate repeated across every test case.

Functions

Link copied to clipboard
fun bigTheory(size: Int = BIG_THEORY_SIZE, last: LogicProgrammingScope.() -> Clause? = null): Theory

Builds a theory of size facts f1., f2., ..., optionally followed by one last clause; used by TestDirectives.testDirectiveLoadingQuickly to check that loading a large static knowledge base does not incur pathological (e.g. quadratic) loading time.

Link copied to clipboard
fun dynamicDirective(functor: String, arity: Int): Sequence<Directive>

A single-clause sequence containing the directive dynamic(functor/arity)..

Link copied to clipboard
fun facts(functor: String, iterable: Iterable<Any>): Sequence<Fact>

A sequence of facts functor(e)., one for each element e of iterable.

Link copied to clipboard

The four equivalent ways a given can end up as a solver's knowledge base: as the static or dynamic theory passed to SolverFactory.solverOf, or loaded after the fact into a fresh MutableSolver via MutableSolver.loadStaticKb/MutableSolver.loadDynamicKb. TestDirectives runs its directive-loading assertions against every one of these, since a directive (e.g. dynamic/1) must behave the same way regardless of how its enclosing theory was loaded.

Link copied to clipboard

Same four loading strategies as solverInitializers, but built with default built-ins and each paired with the mutable event list its solver's stdOut/stdErr/warnings channels append to — so a caller can load a theory containing initialization/1/solve/1/writing directives and then assert on what was written or warned about during loading.

Link copied to clipboard
fun staticDirective(functor: String, arity: Int): Sequence<Directive>

A single-clause sequence containing the directive static(functor/arity)..