Skip to content

Commit

Permalink
Implement to make failing test pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
sageserpent-open committed Oct 19, 2023
1 parent 96821c3 commit 08af67f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ class TrialsApiImplementation extends CommonApi with ScalaTrialsApi {
new TrialsImplementation(NoteComplexity)

override def uniqueIds: TrialsImplementation[Int] = {
// NASTY HACK: add an additional level of gratuitous complexity after
// retrieving the context's complexity. That forces uniqueness.
complexities.flatMap(id => choose(Iterable.single(())).map(_ => id))
new TrialsImplementation(UniqueId)
}

def resetComplexity(complexity: Int): TrialsImplementation[Unit] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ case object NoteComplexity extends GenerationOperation[Int]

case class ResetComplexity[Case](complexity: Int)
extends GenerationOperation[Unit]

case object UniqueId extends GenerationOperation[Int]
Original file line number Diff line number Diff line change
Expand Up @@ -234,27 +234,32 @@ trait SupplyToSyntaxSkeletalImplementation[Case]
decisionStagesToGuideShrinkage: Option[DecisionStages],
decisionStagesInReverseOrder: DecisionStagesInReverseOrder,
complexity: Int,
cost: BigInt
cost: BigInt,
nextUniqueId: Int
) {
def update(
remainingGuidance: Option[DecisionStages],
decision: Decision,
costIncrement: BigInt = BigInt(0)
): State = State(
): State = copy(
decisionStagesToGuideShrinkage = remainingGuidance,
decisionStagesInReverseOrder =
decisionStagesInReverseOrder.addLatest(decision),
complexity = 1 + complexity,
cost = cost + costIncrement
)

def uniqueId(): (State, Int) =
copy(nextUniqueId = 1 + nextUniqueId) -> nextUniqueId
}

object State {
val initial = new State(
decisionStagesToGuideShrinkage = decisionStagesToGuideShrinkage,
decisionStagesInReverseOrder = NoDecisionStages,
complexity = 0,
cost = BigInt(0)
cost = BigInt(0),
nextUniqueId = 0
)
}

Expand Down Expand Up @@ -521,6 +526,9 @@ trait SupplyToSyntaxSkeletalImplementation[Case]

case ResetComplexity(_) =>
StateT.pure(())

case UniqueId =>
StateT[Option, State, Int](state => Some(state.uniqueId()))
}
}

Expand Down Expand Up @@ -574,7 +582,7 @@ trait SupplyToSyntaxSkeletalImplementation[Case]
.run(State.initial) match {
case Some(
(
State(_, decisionStages, _, factoryInputsCost),
State(_, decisionStages, _, factoryInputsCost, _),
caze
)
)
Expand Down

0 comments on commit 08af67f

Please sign in to comment.