Skip to content

Commit

Permalink
revert formatting of solve-streams/src/commonMain
Browse files Browse the repository at this point in the history
  • Loading branch information
gciatto committed Sep 14, 2020
1 parent b153124 commit 00b4b7d
Show file tree
Hide file tree
Showing 56 changed files with 236 additions and 213 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ internal class SolverStrategiesTest {
assertTrue { prologStandard.successCheckStrategy(Truth.TRUE, aContext) }
assertFalse { prologStandard.successCheckStrategy(Atom.of("ciao"), aContext) }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ internal class StreamsSolverTest {
assertEquals(Theory.empty(), toBeTested.staticKb)
assertEquals(Theory.empty(), toBeTested.dynamicKb)
}

}
Original file line number Diff line number Diff line change
@@ -1,33 +1,12 @@
package it.unibo.tuprolog.solve.solver

import it.unibo.tuprolog.core.Atom
import it.unibo.tuprolog.core.Clause
import it.unibo.tuprolog.core.Integer
import it.unibo.tuprolog.core.Scope
import it.unibo.tuprolog.core.Struct
import it.unibo.tuprolog.core.Substitution
import it.unibo.tuprolog.core.Truth
import it.unibo.tuprolog.core.Tuple
import it.unibo.tuprolog.core.Var
import it.unibo.tuprolog.solve.DummyInstances
import it.unibo.tuprolog.solve.FlagStore
import it.unibo.tuprolog.solve.Signature
import it.unibo.tuprolog.solve.currentTimeInstant
import it.unibo.tuprolog.core.*
import it.unibo.tuprolog.solve.*
import it.unibo.tuprolog.solve.exception.HaltException
import it.unibo.tuprolog.solve.extractSignature
import it.unibo.tuprolog.solve.halt
import it.unibo.tuprolog.solve.library.Libraries
import it.unibo.tuprolog.solve.no
import it.unibo.tuprolog.solve.primitive.Solve
import it.unibo.tuprolog.solve.yes
import it.unibo.tuprolog.theory.Theory
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertFalse
import kotlin.test.assertSame
import kotlin.test.assertTrue
import kotlin.test.fail
import kotlin.test.*

/**
* Test class for SolverUtils.kt
Expand Down Expand Up @@ -125,13 +104,11 @@ internal class SolverUtilsTest {
@Test
fun moreThanOneWorksLazily() {
assertTrue {
moreThanOne(
sequence {
yield(1)
yield(1)
fail("Should not evaluate entire sequence")
}
)
moreThanOne(sequence {
yield(1)
yield(1)
fail("Should not evaluate entire sequence")
})
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ internal class AlreadyExecutedStateTest {

assertSame(correct.wrappedState, toBeTested.wrappedState)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ import it.unibo.tuprolog.solve.solver.fsm.testutils.StateMachineExecutorUtils.th
import it.unibo.tuprolog.solve.solver.fsm.testutils.StateMachineExecutorUtils.threeShotStateAlreadyExecuted
import it.unibo.tuprolog.solve.solver.fsm.testutils.StateMachineExecutorUtils.toBehavedState
import it.unibo.tuprolog.solve.solver.fsm.testutils.StateMachineExecutorUtils.twoAlternativeState
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertSame
import kotlin.test.assertTrue
import kotlin.test.fail
import kotlin.test.*

/**
* Test class for [StateMachineExecutor]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package it.unibo.tuprolog.solve.solver.fsm.impl

import it.unibo.tuprolog.core.Truth
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.TimeDuration
import it.unibo.tuprolog.solve.TimeInstant
import it.unibo.tuprolog.solve.currentTimeInstant
import it.unibo.tuprolog.solve.*
import it.unibo.tuprolog.solve.exception.TimeOutException
import it.unibo.tuprolog.solve.primitive.Solve
import it.unibo.tuprolog.solve.solver.fsm.State
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ internal class StateGoalEvaluationTest {
assertOnlyOneNextState<StateEnd.Halt>(nextStates)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.core.Truth
import it.unibo.tuprolog.core.prepareForExecution
import it.unibo.tuprolog.solve.DummyInstances
import it.unibo.tuprolog.solve.SolverStrategies
import it.unibo.tuprolog.solve.primitive.Solve
import it.unibo.tuprolog.solve.SolverStrategies
import it.unibo.tuprolog.solve.solver.fsm.impl.testutils.StateInitUtils.allRequests
import it.unibo.tuprolog.solve.solver.fsm.impl.testutils.StateInitUtils.allWellFormedGoalRequests
import it.unibo.tuprolog.solve.solver.fsm.impl.testutils.StateInitUtils.nonWellFormedGoalRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package it.unibo.tuprolog.solve.solver.fsm.impl

import it.unibo.tuprolog.core.Var
import it.unibo.tuprolog.dsl.theory.prolog
import it.unibo.tuprolog.solve.primitive.Solve
import it.unibo.tuprolog.solve.extractSignature
import it.unibo.tuprolog.solve.library.Libraries
import it.unibo.tuprolog.solve.library.Library
import it.unibo.tuprolog.solve.primitive.Solve
import it.unibo.tuprolog.solve.solver.StreamsExecutionContext
import it.unibo.tuprolog.solve.solver.fsm.FinalState
import it.unibo.tuprolog.solve.solver.fsm.impl.testutils.StateRuleSelectionUtils.createRequest
Expand Down Expand Up @@ -33,20 +33,15 @@ internal class StateRuleSelectionTest {
private val theQuery = prolog { "f"(theQueryVariable) }

/** A Solve.Request with three databases and three different facts, to test how they should be used/combined in searching */
private val threeDBSolveRequest = Solve.Request(
theQuery.extractSignature(),
theQuery.argsList,
private val threeDBSolveRequest = Solve.Request(theQuery.extractSignature(), theQuery.argsList,
StreamsExecutionContext(
libraries = Libraries(
Library.aliased(
alias = "testLib",
theory = prolog { theory({ "f"("a") }) }
)
),
libraries = Libraries(Library.aliased(
alias = "testLib",
theory = prolog { theory({ "f"("a") }) }
)),
staticKb = prolog { theory({ "f"("b") }) },
dynamicKb = prolog { theory({ "f"("c") }) }
)
)
))

@Test
fun noMatchingRulesFoundMakeItGoIntoFalseState() {
Expand Down Expand Up @@ -120,4 +115,5 @@ internal class StateRuleSelectionTest {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import it.unibo.tuprolog.solve.PrologStandardExampleTheories.prologStandardExamp
import it.unibo.tuprolog.solve.PrologStandardExampleTheories.prologStandardExampleWithCutTheory
import it.unibo.tuprolog.solve.PrologStandardExampleTheories.prologStandardExampleWithCutTheoryNotableGoalToSolution
import it.unibo.tuprolog.solve.Solution
import it.unibo.tuprolog.solve.primitive.Solve
import it.unibo.tuprolog.solve.TestingClauseTheories.customReverseListTheory
import it.unibo.tuprolog.solve.TestingClauseTheories.customReverseListTheoryNotableGoalToSolution
import it.unibo.tuprolog.solve.TestingClauseTheories.cutConjunctionAndBacktrackingTheory
Expand All @@ -22,7 +23,6 @@ import it.unibo.tuprolog.solve.TestingClauseTheories.simpleFactTheory
import it.unibo.tuprolog.solve.TestingClauseTheories.simpleFactTheoryNotableGoalToSolutions
import it.unibo.tuprolog.solve.assertSolutionEquals
import it.unibo.tuprolog.solve.extractSignature
import it.unibo.tuprolog.solve.primitive.Solve
import it.unibo.tuprolog.solve.solver.StreamsExecutionContext
import it.unibo.tuprolog.solve.solver.fsm.FinalState
import it.unibo.tuprolog.solve.solver.fsm.State
Expand Down Expand Up @@ -67,8 +67,7 @@ internal class StateIntegrationTesting {
finalState.solve.solution.let {
// cleanUp as in StreamsSolver
(it as? Solution.Yes)?.copy(substitution = it.substitution.filter { _, t -> t !is Var }) ?: it
}
)
})
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.unibo.tuprolog.solve.solver.fsm.impl.testutils

import it.unibo.tuprolog.core.Var
import it.unibo.tuprolog.solve.primitive.Solve
import it.unibo.tuprolog.solve.StreamsSolver
import it.unibo.tuprolog.solve.exception.HaltException
import it.unibo.tuprolog.solve.exception.PrologError
Expand All @@ -9,7 +10,6 @@ import it.unibo.tuprolog.solve.exception.error.SystemError
import it.unibo.tuprolog.solve.exception.error.TypeError
import it.unibo.tuprolog.solve.primitive.Primitive
import it.unibo.tuprolog.solve.primitive.PrimitiveWrapper
import it.unibo.tuprolog.solve.primitive.Solve
import it.unibo.tuprolog.solve.solver.SideEffectManagerImpl
import it.unibo.tuprolog.solve.solver.StreamsExecutionContext
import it.unibo.tuprolog.solve.solver.fsm.impl.StateEnd
Expand Down Expand Up @@ -45,15 +45,15 @@ internal object StateGoalEvaluationUtils {
internal val primitiveRequestToNextStateList by lazy {
mapOf(
createRequestForPrimitiveResponding { sequenceOf(it.replySuccess(it.context.substitution)) }
to listOf(StateEnd.True::class),
to listOf(StateEnd.True::class),
createRequestForPrimitiveResponding { sequenceOf(it.replyFail()) }
to listOf(StateEnd.False::class),
to listOf(StateEnd.False::class),
createRequestForPrimitiveResponding { sequenceOf(it.replyWith(true), it.replyWith(false)) }
to listOf(StateEnd.True::class, StateEnd.False::class),
to listOf(StateEnd.True::class, StateEnd.False::class),
createRequestForPrimitiveResponding { sequenceOf(it.replyException(HaltException(context = it.context))) }
to listOf(StateEnd.Halt::class),
to listOf(StateEnd.Halt::class),
createRequestForPrimitiveResponding { throw HaltException(context = it.context) }
to listOf(StateEnd.Halt::class),
to listOf(StateEnd.Halt::class),
createRequestForPrimitiveResponding {
sequence {
yieldAll(StreamsSolver.solveToResponses(createRequestForPrimitiveResponding { throw HaltException(context = it.context) }))
Expand Down Expand Up @@ -85,4 +85,4 @@ internal object StateGoalEvaluationUtils {

/** All requests that should make [StateGoalEvaluation] transit in [StateRuleSelection] */
internal val nonPrimitiveRequests by lazy { StateInitUtils.allWellFormedGoalRequests }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal object StateInitUtils {
/** Collection of [Solve.Request] that should pass [StateInit] going into [StateGoalEvaluation] */
internal val allWellFormedGoalRequests by lazy {
wellFormedGoalRequestsNeedingPreparationForExecution +
wellFormedGoalRequestsNotNeedingPreparationForExecution
wellFormedGoalRequestsNotNeedingPreparationForExecution
}

/** Solve request with non well-formed goal */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ internal object StateUtils {
/** Utility function to assert that there's only one next state of given type */
internal inline fun <reified S : State> assertOnlyOneNextState(actualNextStateSequence: Sequence<State>) {
assertEquals(
1,
actualNextStateSequence.count(),
1, actualNextStateSequence.count(),
"Expected only one state, but ${actualNextStateSequence.toList()}"
)
assertTrue { actualNextStateSequence.single() is S }
Expand Down Expand Up @@ -51,5 +50,6 @@ internal object StateUtils {
internal fun Solve.getSideEffectsManager(): SideEffectManager = when (this) {
is Solve.Response -> sideEffectManager
is Solve.Request<*> -> context.getSideEffectManager()
} ?: fail("SideEffectManager is not present in $this")
} ?: fail("SideEffectManager is not present in ${this}")

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import it.unibo.tuprolog.solve.stdlib.primitive.testutils.CallUtils.assertErrorC
import it.unibo.tuprolog.solve.stdlib.primitive.testutils.CallUtils.requestSolutionMap
import it.unibo.tuprolog.solve.stdlib.primitive.testutils.CallUtils.requestToErrorSolutionMap
import it.unibo.tuprolog.solve.stdlib.primitive.testutils.CallUtils.requestToSolutionOfCallWithCut
import it.unibo.tuprolog.solve.stdlib.primitive.testutils.PrimitiveUtils.deepCause
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package it.unibo.tuprolog.solve.stdlib.primitive

import it.unibo.tuprolog.dsl.theory.prolog
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.assertSolutionEquals
import it.unibo.tuprolog.solve.extractSignature
import it.unibo.tuprolog.solve.*
import it.unibo.tuprolog.solve.library.Libraries
import it.unibo.tuprolog.solve.library.Library
import it.unibo.tuprolog.solve.no
import it.unibo.tuprolog.solve.primitive.PrimitiveWrapper
import it.unibo.tuprolog.solve.primitive.Solve
import it.unibo.tuprolog.solve.solver.StreamsExecutionContext
Expand All @@ -16,7 +13,6 @@ import it.unibo.tuprolog.solve.stdlib.primitive.testutils.ConjunctionUtils.trueA
import it.unibo.tuprolog.solve.stdlib.primitive.testutils.ConjunctionUtils.twoMatchesDB
import it.unibo.tuprolog.solve.stdlib.primitive.testutils.PrimitiveUtils.assertOnlyOneSolution
import it.unibo.tuprolog.solve.testutils.SolverTestUtils.createSolveRequest
import it.unibo.tuprolog.solve.yes
import kotlin.test.Test
import kotlin.collections.listOf as ktListOf

Expand Down Expand Up @@ -68,9 +64,7 @@ internal class ConjunctionTest {

val goal = "left" and "right"
val request = Solve.Request(
goal.extractSignature(),
goal.argsList,
StreamsExecutionContext(
goal.extractSignature(), goal.argsList, StreamsExecutionContext(
substitution = preRequestSubstitution,
libraries = Libraries(
Library.aliased(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ package it.unibo.tuprolog.solve.stdlib.primitive

import it.unibo.tuprolog.dsl.prolog
import it.unibo.tuprolog.dsl.theory.PrologScopeWithTheories
import it.unibo.tuprolog.solve.DummyInstances
import it.unibo.tuprolog.solve.assertSolutionEquals
import it.unibo.tuprolog.solve.*
import it.unibo.tuprolog.solve.exception.error.TypeError
import it.unibo.tuprolog.solve.halt
import it.unibo.tuprolog.solve.no
import it.unibo.tuprolog.solve.testutils.SolverTestUtils.createSolveRequest
import it.unibo.tuprolog.solve.yes
import kotlin.test.Ignore
import kotlin.test.Test

Expand Down Expand Up @@ -71,11 +67,10 @@ internal class NotTest {
DummyInstances.executionContext,
Not.signature,
TypeError.Expected.CALLABLE,
prolog { numOf(1) }
)
prolog { numOf(1) })
)
),
solutions
), solutions
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ internal class CutAndConjunctionIntegrationTest {

modifiedSimpleFactDatabaseGoals.forEach { (goal, solutionList) ->
val request = createSolveRequest(
goal,
simpleFactTheory,
goal, simpleFactTheory,
mapOf(Conjunction.descriptionPair, Cut.descriptionPair)
)
val solutions = Conjunction.wrappedImplementation(request).map { it.solution }.asIterable()
Expand All @@ -52,8 +51,7 @@ internal class CutAndConjunctionIntegrationTest {

modifiedSimpleFactDatabaseGoals.forEach { (goal, solutionList) ->
val request = createSolveRequest(
goal,
simpleFactTheory,
goal, simpleFactTheory,
mapOf(Conjunction.descriptionPair, Cut.descriptionPair)
)
val solutions = Conjunction.wrappedImplementation(request).map { it.solution }.asIterable()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package it.unibo.tuprolog.solve.stdlib.primitive.testutils

import it.unibo.tuprolog.dsl.theory.prolog
import it.unibo.tuprolog.solve.DummyInstances
import it.unibo.tuprolog.solve.Solution
import it.unibo.tuprolog.solve.*
import it.unibo.tuprolog.solve.TestingClauseTheories.simpleFactTheory
import it.unibo.tuprolog.solve.TestingClauseTheories.simpleFactTheoryNotableGoalToSolutions
import it.unibo.tuprolog.solve.changeQueriesTo
import it.unibo.tuprolog.solve.exception.PrologError
import it.unibo.tuprolog.solve.exception.error.InstantiationError
import it.unibo.tuprolog.solve.exception.error.TypeError
Expand Down Expand Up @@ -63,8 +61,7 @@ internal object CallUtils {
}.toTypedArray()
).mapKeys { (query, _) ->
createSolveRequest(
query,
database = simpleFactTheory,
query, database = simpleFactTheory,
primitives = mapOf(*ktListOf(Call, Cut, Conjunction).map { it.descriptionPair }.toTypedArray())
)
}
Expand Down Expand Up @@ -121,8 +118,7 @@ internal object CallUtils {
}.toTypedArray()
).mapKeys { (query, _) ->
createSolveRequest(
query,
database = simpleFactTheory,
query, database = simpleFactTheory,
primitives = mapOf(*ktListOf(Call, Cut, Conjunction).map { it.descriptionPair }.toTypedArray())
)
}
Expand Down
Loading

0 comments on commit 00b4b7d

Please sign in to comment.