Skip to content

Commit

Permalink
deeper and deeper
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfmurdock committed Jul 19, 2023
1 parent f722d59 commit 2b091c7
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import kotools.types.collection.toNotEmptyList

@ActionMint
data class FindNewPairsAction(val game: Game) {
interface Dispatcher<out D : NextPlayerAction.Dispatcher> : CannonProvider<D> {
interface Dispatcher<out D> : CannonProvider<D>
where D : CreatePairCandidateReportListAction.Dispatcher,
D : NextPlayerAction.Dispatcher<D> {

val wheel: Wheel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import com.zegreatrob.testmints.action.async.SimpleSuspendAction
import kotools.types.collection.NotEmptyList

data class NextPlayerAction(val gameSpin: GameSpin) :
SimpleSuspendAction<NextPlayerAction.Dispatcher, PairCandidateReport> {
override val performFunc = link(Dispatcher::perform)
SimpleSuspendAction<NextPlayerAction.Dispatcher<*>, PairCandidateReport> {
override val performFunc = link(Dispatcher<*>::perform)

interface Dispatcher {
interface Dispatcher<out D> {

val execute: ExecutableActionExecutor<CreatePairCandidateReportListAction.Dispatcher>

fun perform(action: NextPlayerAction): PairCandidateReport = with(action.createPairCandidateReports()) {
suspend fun perform(action: NextPlayerAction): PairCandidateReport = with(action.createPairCandidateReports()) {
toList().fold(head) { reportWithLongestTime, report ->
when {
reportWithLongestTime.timeResult == report.timeResult ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ interface ServerSpinCommandDispatcher<out D> :
PartyIdLoadPlayersSyntax,
PartyIdHistorySyntax,
PartyIdPinRecordsSyntax,
CannonProvider<D> where D : NextPlayerAction.Dispatcher,
CannonProvider<D> where D : CreatePairCandidateReportListAction.Dispatcher,
D : NextPlayerAction.Dispatcher<D>,
D : FindNewPairsAction.Dispatcher<D>,
D : AssignPinsAction.Dispatcher,
D : ShufflePairsAction.Dispatcher<D> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ data class ShufflePairsAction(
val history: List<PairAssignmentDocument>,
) {
interface Dispatcher<out D> : Clock, CannonProvider<D>
where D : NextPlayerAction.Dispatcher,
where D : CreatePairCandidateReportListAction.Dispatcher,
D : NextPlayerAction.Dispatcher<D>,
D : FindNewPairsAction.Dispatcher<D>,
D : AssignPinsAction.Dispatcher {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,27 @@ import com.zegreatrob.minassert.assertIsEqualTo
import com.zegreatrob.minspy.Spy
import com.zegreatrob.minspy.SpyData
import com.zegreatrob.minspy.spyFunction
import com.zegreatrob.testmints.action.ExecutableActionExecutor
import com.zegreatrob.testmints.async.asyncSetup
import kotlinx.coroutines.channels.Channel
import kotools.types.collection.notEmptyListOf
import kotlin.test.Test

class FindNewPairsActionTest {

interface FindNewPairsActionTestDispatcher :
NextPlayerAction.Dispatcher<FindNewPairsActionTestDispatcher>,
CreatePairCandidateReportListAction.Dispatcher,
CreatePairCandidateReportAction.Dispatcher {
override val execute: ExecutableActionExecutor<FindNewPairsActionTestDispatcher>
get() = TODO("Not yet implemented")
}

@Test
fun withTwoPlayersEachShouldBeRemovedFromWheelBeforeEachPlay() = asyncSetup(object :
FindNewPairsAction.Dispatcher<NextPlayerAction.Dispatcher> {
FindNewPairsAction.Dispatcher<FindNewPairsActionTestDispatcher> {
override val wheel = StubWheel()
override val cannon = StubCannon<NextPlayerAction.Dispatcher>(mutableListOf(), Channel<Any>())
override val cannon = StubCannon<FindNewPairsActionTestDispatcher>(mutableListOf(), Channel<Any>())
val bill: Player = Player(id = "Bill", avatarType = null)
val ted: Player = Player(id = "Ted", avatarType = null)
val players = notEmptyListOf(bill, ted)
Expand All @@ -39,8 +48,8 @@ class FindNewPairsActionTest {

@Test
fun shouldRemoveAPlayerFromTheWheelBeforeEachPlay() = asyncSetup(object :
FindNewPairsAction.Dispatcher<NextPlayerAction.Dispatcher> {
override val cannon = StubCannon<NextPlayerAction.Dispatcher>(mutableListOf(), Channel<Any>())
FindNewPairsAction.Dispatcher<FindNewPairsActionTestDispatcher> {
override val cannon = StubCannon<FindNewPairsActionTestDispatcher>(mutableListOf(), Channel<Any>())
override val wheel = StubWheel()
val bill: Player = Player(id = "Bill", avatarType = null)
val ted: Player = Player(id = "Ted", avatarType = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class GameExamplesTest {
ShufflePairsAction.Dispatcher<Companion>,
FindNewPairsAction.Dispatcher<Companion>,
AssignPinsAction.Dispatcher,
NextPlayerAction.Dispatcher,
NextPlayerAction.Dispatcher<Companion>,
CreatePairCandidateReportAction.Dispatcher,
CreatePairCandidateReportListAction.Dispatcher,
DispatchingActionExecutor<Companion>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.zegreatrob.coupling.model.player.Player
import com.zegreatrob.coupling.stubmodel.stubPlayer
import com.zegreatrob.coupling.testaction.StubCannon
import com.zegreatrob.minassert.assertIsEqualTo
import com.zegreatrob.testmints.action.ExecutableActionExecutor
import com.zegreatrob.testmints.async.ScopeMint
import com.zegreatrob.testmints.async.asyncSetup
import kotlinx.coroutines.channels.Channel
Expand All @@ -25,8 +26,13 @@ class ShufflePairsActionTest {

interface ShufflePairsActionInner :
FindNewPairsAction.Dispatcher<ShufflePairsActionInner>,
AssignPinsAction.Dispatcher,
NextPlayerAction.Dispatcher
NextPlayerAction.Dispatcher<ShufflePairsActionInner>,
CreatePairCandidateReportListAction.Dispatcher,
CreatePairCandidateReportAction.Dispatcher,
AssignPinsAction.Dispatcher {
override val execute: ExecutableActionExecutor<ShufflePairsActionInner>
get() = TODO("Not yet implemented")
}

@Test
fun willBuildAGameRunWithAllAvailablePlayersAndThenReturnTheResults() = asyncSetup(object :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import com.zegreatrob.coupling.server.action.pairassignmentdocument.NextPlayerAc
import com.zegreatrob.coupling.server.action.pairassignmentdocument.PairCandidateReport
import com.zegreatrob.coupling.server.action.stubActionExecutor
import com.zegreatrob.minassert.assertIsEqualTo
import com.zegreatrob.testmints.setup
import com.zegreatrob.testmints.async.asyncSetup
import kotools.types.collection.NotEmptyList
import kotools.types.collection.notEmptyListOf
import kotlin.test.Test

class NextPlayerActionTest : NextPlayerAction.Dispatcher {
class NextPlayerActionTest : NextPlayerAction.Dispatcher<CreatePairCandidateReportListAction.Dispatcher> {

override val execute = stubActionExecutor(CreatePairCandidateReportListAction::class)

private val bill = Player(id = "Bill", avatarType = null)
Expand All @@ -24,7 +25,7 @@ class NextPlayerActionTest : NextPlayerAction.Dispatcher {
private val shorty = Player(id = "Napoleon", avatarType = null)

@Test
fun willUseHistoryToProduceSequenceInOrderOfLongestTimeSinceLastPairedToShortest() = setup(object {
fun willUseHistoryToProduceSequenceInOrderOfLongestTimeSinceLastPairedToShortest() = asyncSetup(object {
val players = notEmptyListOf(bill, ted, amadeus, shorty)

val billsPairCandidates = PairCandidateReport(bill, emptyList(), TimeResultValue(3))
Expand All @@ -42,7 +43,7 @@ class NextPlayerActionTest : NextPlayerAction.Dispatcher {
}

@Test
fun aPersonWhoJustPairedHasLowerPriorityThanSomeoneWhoHasNotPairedInALongTime() = setup(object {
fun aPersonWhoJustPairedHasLowerPriorityThanSomeoneWhoHasNotPairedInALongTime() = asyncSetup(object {
val players = notEmptyListOf(bill, ted, amadeus, shorty)
val amadeusPairCandidates = PairCandidateReport(amadeus, emptyList(), TimeResultValue(5))
val shortyPairCandidates = PairCandidateReport(shorty, emptyList(), TimeResultValue(0))
Expand All @@ -53,7 +54,7 @@ class NextPlayerActionTest : NextPlayerAction.Dispatcher {
} verify { it.assertIsEqualTo(amadeusPairCandidates) }

@Test
fun sequenceWillBeFromLongestToShortest() = setup(object {
fun sequenceWillBeFromLongestToShortest() = asyncSetup(object {
val players = notEmptyListOf(bill, amadeus, shorty)

val billsPairCandidates = PairCandidateReport(bill, emptyList(), TimeResultValue(3))
Expand All @@ -68,7 +69,7 @@ class NextPlayerActionTest : NextPlayerAction.Dispatcher {
} verify { it.assertIsEqualTo(shortyPairCandidates) }

@Test
fun sequenceWillPreferPlayerWhoHasNeverPaired() = setup(object {
fun sequenceWillPreferPlayerWhoHasNeverPaired() = asyncSetup(object {
val players = notEmptyListOf(bill, amadeus, shorty)

val billsPairCandidates = PairCandidateReport(bill, emptyList(), TimeResultValue(3))
Expand All @@ -83,7 +84,7 @@ class NextPlayerActionTest : NextPlayerAction.Dispatcher {
} verify { it.assertIsEqualTo(shortyPairCandidates) }

@Test
fun willPrioritizeTheReportWithFewestPlayersGivenEqualAmountsOfTime() = setup(object {
fun willPrioritizeTheReportWithFewestPlayersGivenEqualAmountsOfTime() = asyncSetup(object {
val players = notEmptyListOf(bill, amadeus, shorty)

val billsPairCandidates = PairCandidateReport(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.zegreatrob.coupling.server.action.connection.ConnectionsQuery
import com.zegreatrob.coupling.server.action.connection.DisconnectPartyUserCommand
import com.zegreatrob.coupling.server.action.connection.ReportDocCommand
import com.zegreatrob.coupling.server.action.pairassignmentdocument.CurrentPairAssignmentDocumentQuery
import com.zegreatrob.coupling.server.action.pairassignmentdocument.NextPlayerAction
import com.zegreatrob.coupling.server.action.pairassignmentdocument.PairAssignmentDocumentListQuery
import com.zegreatrob.coupling.server.action.pairassignmentdocument.ServerDeletePairAssignmentsCommandDispatcher
import com.zegreatrob.coupling.server.action.pairassignmentdocument.ServerSavePairAssignmentDocumentCommandDispatcher
Expand Down Expand Up @@ -122,6 +123,7 @@ class CurrentPartyDispatcher(
DispatchingActionExecutor<CurrentPartyDispatcher>,
ShufflePairsAction.Dispatcher<CurrentPartyDispatcher>,
AssignPinsAction.Dispatcher,
NextPlayerAction.Dispatcher<CurrentPartyDispatcher>,
PairAssignmentDispatcher<CurrentPartyDispatcher>,
ServerSpinCommandDispatcher<CurrentPartyDispatcher>,
ServerSaveSlackIntegrationCommandDispatcher,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import com.zegreatrob.testmints.action.ExecutableActionExecutor
interface PairAssignmentDispatcher<D> :
ShufflePairsAction.Dispatcher<D>,
FindNewPairsAction.Dispatcher<D>,
NextPlayerAction.Dispatcher,
NextPlayerAction.Dispatcher<D>,
CreatePairCandidateReportListAction.Dispatcher,
CreatePairCandidateReportAction.Dispatcher,
Wheel where D : NextPlayerAction.Dispatcher,
Wheel where D : CreatePairCandidateReportListAction.Dispatcher,
D : NextPlayerAction.Dispatcher<D>,
D : AssignPinsAction.Dispatcher,
D : FindNewPairsAction.Dispatcher<D> {
override val execute: ExecutableActionExecutor<PairAssignmentDispatcher<D>>
Expand Down

0 comments on commit 2b091c7

Please sign in to comment.