From 900168d17ad1dc258025dc7b59f678a04539ed79 Mon Sep 17 00:00:00 2001 From: RoB Murdock Date: Tue, 18 Jul 2023 21:14:58 -0400 Subject: [PATCH] how are there still more layers --- .../CreatePairCandidateReportListAction.kt | 14 ++++----- .../FindNewPairsAction.kt | 3 +- .../NextPlayerAction.kt | 4 ++- .../ServerSpinCommandDispatcher.kt | 3 +- .../ShufflePairsAction.kt | 3 +- .../CreatePairCandidateReportsActionTest.kt | 17 +++++------ .../FindNewPairsActionTest.kt | 2 +- .../GameExamplesTest.kt | 6 ++-- .../ShufflePairsActionTest.kt | 2 +- .../action/player/NextPlayerActionTest.kt | 29 ++++++++++++------- .../coupling/server/CommandDispatcher.kt | 2 ++ .../PairAssignmentDispatcher.kt | 5 ++-- 12 files changed, 53 insertions(+), 37 deletions(-) diff --git a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/CreatePairCandidateReportListAction.kt b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/CreatePairCandidateReportListAction.kt index 32e3a080c4..b6d2076cb1 100644 --- a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/CreatePairCandidateReportListAction.kt +++ b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/CreatePairCandidateReportListAction.kt @@ -4,23 +4,23 @@ import com.zegreatrob.coupling.model.map import com.zegreatrob.coupling.model.party.PairingRule import com.zegreatrob.coupling.model.player.Player import com.zegreatrob.testmints.action.ExecutableActionExecutor -import com.zegreatrob.testmints.action.async.SimpleSuspendAction +import com.zegreatrob.testmints.action.annotation.ActionMint import kotools.types.collection.NotEmptyList -data class CreatePairCandidateReportListAction(val game: GameSpin) : - SimpleSuspendAction> { - override val performFunc = link(Dispatcher::perform) +@ActionMint +data class CreatePairCandidateReportListAction(val game: GameSpin) { - interface Dispatcher : PlayerCandidatesFinder { + interface Dispatcher : PlayerCandidatesFinder where D : CreatePairCandidateReportAction.Dispatcher { val execute: ExecutableActionExecutor - fun perform(action: CreatePairCandidateReportListAction) = action.createReports() + suspend fun perform(action: CreatePairCandidateReportListAction) = action.createReports() private fun CreatePairCandidateReportListAction.createReportsUsingLongestRule() = game.createReports(PairingRule.LongestTime) - private fun CreatePairCandidateReportListAction.createReports() = game.createReports(game.rule) + private fun CreatePairCandidateReportListAction.createReports(): NotEmptyList = + game.createReports(game.rule) private fun GameSpin.createReports(rule: PairingRule) = remainingPlayers.map { player -> pairCandidateReport(rule, player) } diff --git a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/FindNewPairsAction.kt b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/FindNewPairsAction.kt index f8e6b40cf3..e7e319c9c6 100644 --- a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/FindNewPairsAction.kt +++ b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/FindNewPairsAction.kt @@ -14,7 +14,8 @@ import kotools.types.collection.toNotEmptyList @ActionMint data class FindNewPairsAction(val game: Game) { interface Dispatcher : CannonProvider - where D : CreatePairCandidateReportListAction.Dispatcher, + where D : CreatePairCandidateReportAction.Dispatcher, + D : CreatePairCandidateReportListAction.Dispatcher, D : NextPlayerAction.Dispatcher { val wheel: Wheel diff --git a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/NextPlayerAction.kt b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/NextPlayerAction.kt index a0ad9107bd..38908e3170 100644 --- a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/NextPlayerAction.kt +++ b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/NextPlayerAction.kt @@ -8,7 +8,9 @@ import com.zegreatrob.testmints.action.annotation.ActionMint @ActionMint data class NextPlayerAction(val gameSpin: GameSpin) { - interface Dispatcher : CannonProvider where D : CreatePairCandidateReportListAction.Dispatcher { + interface Dispatcher : CannonProvider + where D : CreatePairCandidateReportAction.Dispatcher, + D : CreatePairCandidateReportListAction.Dispatcher { suspend fun perform(action: NextPlayerAction): PairCandidateReport = with(action.createPairCandidateReports()) { toList().fold(head) { reportWithLongestTime, report -> diff --git a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ServerSpinCommandDispatcher.kt b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ServerSpinCommandDispatcher.kt index e5cb829a19..0d14b90659 100644 --- a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ServerSpinCommandDispatcher.kt +++ b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ServerSpinCommandDispatcher.kt @@ -33,7 +33,8 @@ interface ServerSpinCommandDispatcher : PartyIdLoadPlayersSyntax, PartyIdHistorySyntax, PartyIdPinRecordsSyntax, - CannonProvider where D : CreatePairCandidateReportListAction.Dispatcher, + CannonProvider where D : CreatePairCandidateReportAction.Dispatcher, + D : CreatePairCandidateReportListAction.Dispatcher, D : NextPlayerAction.Dispatcher, D : FindNewPairsAction.Dispatcher, D : AssignPinsAction.Dispatcher, diff --git a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsAction.kt b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsAction.kt index e6be338134..6a0de80a49 100644 --- a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsAction.kt +++ b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsAction.kt @@ -22,7 +22,8 @@ data class ShufflePairsAction( val history: List, ) { interface Dispatcher : Clock, CannonProvider - where D : CreatePairCandidateReportListAction.Dispatcher, + where D : CreatePairCandidateReportAction.Dispatcher, + D : CreatePairCandidateReportListAction.Dispatcher, D : NextPlayerAction.Dispatcher, D : FindNewPairsAction.Dispatcher, D : AssignPinsAction.Dispatcher { diff --git a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/CreatePairCandidateReportsActionTest.kt b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/CreatePairCandidateReportsActionTest.kt index f1a5ca6c33..e3231f7d14 100644 --- a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/CreatePairCandidateReportsActionTest.kt +++ b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/CreatePairCandidateReportsActionTest.kt @@ -8,7 +8,7 @@ import com.zegreatrob.coupling.model.player.Player import com.zegreatrob.coupling.server.action.StubActionExecutor 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 @@ -16,11 +16,11 @@ import kotlin.test.Test class CreatePairCandidateReportsActionTest { class WhenThePartyPrefersPairingWithDifferentBadges : - CreatePairCandidateReportListAction.Dispatcher { + CreatePairCandidateReportListAction.Dispatcher { override val execute = stubActionExecutor(CreatePairCandidateReportAction::class) @Test - fun willReturnAllReportsForPlayersWithTheSameBadge() = setup(object { + fun willReturnAllReportsForPlayersWithTheSameBadge() = asyncSetup(object { val bill = Player(id = "Bill", badge = 1, avatarType = null) val ted = Player(id = "Ted", badge = 1, avatarType = null) val amadeus = Player(id = "Mozart", badge = 1, avatarType = null) @@ -47,7 +47,7 @@ class CreatePairCandidateReportsActionTest { } @Test - fun willReturnFilterCandidatesByUnlikeBadge() = setup(object { + fun willReturnFilterCandidatesByUnlikeBadge() = asyncSetup(object { val history = emptyList() val bill = Player(id = "Bill", badge = 1, avatarType = null) val ted = Player(id = "Ted", badge = 1, avatarType = null) @@ -76,7 +76,7 @@ class CreatePairCandidateReportsActionTest { } @Test - fun willReturnReportForOnePlayer() = setup(object { + fun willReturnReportForOnePlayer() = asyncSetup(object { val history = emptyList() val bill = Player(id = "Bill", badge = 1, avatarType = null) val players = notEmptyListOf(bill) @@ -92,8 +92,8 @@ class CreatePairCandidateReportsActionTest { } @Test - fun whenThePartyPrefersPairingByLongestTime() = setup(object : - CreatePairCandidateReportListAction.Dispatcher { + fun whenThePartyPrefersPairingByLongestTime() = asyncSetup(object : + CreatePairCandidateReportListAction.Dispatcher { override val execute = stubActionExecutor(CreatePairCandidateReportAction::class) val history = listOf() val bill = Player(id = "Bill", badge = 1, avatarType = null) @@ -131,8 +131,7 @@ class CreatePairCandidateReportsActionTest { players: List, history: List, ) = whenever( - receive = CreatePairCandidateReportAction(pairCandidateReport.player, history, players) - .also { println("expecting $it") }, + receive = CreatePairCandidateReportAction(pairCandidateReport.player, history, players), returnValue = pairCandidateReport, ) diff --git a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/FindNewPairsActionTest.kt b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/FindNewPairsActionTest.kt index 3711d27a35..66b022821d 100644 --- a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/FindNewPairsActionTest.kt +++ b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/FindNewPairsActionTest.kt @@ -21,7 +21,7 @@ class FindNewPairsActionTest { interface FindNewPairsActionTestDispatcher : NextPlayerAction.Dispatcher, - CreatePairCandidateReportListAction.Dispatcher, + CreatePairCandidateReportListAction.Dispatcher, CreatePairCandidateReportAction.Dispatcher { override val execute: ExecutableActionExecutor get() = TODO("Not yet implemented") diff --git a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/GameExamplesTest.kt b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/GameExamplesTest.kt index 16a6e9da2f..93e75146ca 100644 --- a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/GameExamplesTest.kt +++ b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/GameExamplesTest.kt @@ -30,13 +30,13 @@ import kotlin.test.Test class GameExamplesTest { companion object : + CreatePairCandidateReportListAction.Dispatcher, ShufflePairsAction.Dispatcher, FindNewPairsAction.Dispatcher, - AssignPinsAction.Dispatcher, + DispatchingActionExecutor, NextPlayerAction.Dispatcher, + AssignPinsAction.Dispatcher, CreatePairCandidateReportAction.Dispatcher, - CreatePairCandidateReportListAction.Dispatcher, - DispatchingActionExecutor, Wheel { override val wheel = this override val actionDispatcher = this diff --git a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsActionTest.kt b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsActionTest.kt index 71f5515d33..3c9da99526 100644 --- a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsActionTest.kt +++ b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsActionTest.kt @@ -27,7 +27,7 @@ class ShufflePairsActionTest { interface ShufflePairsActionInner : FindNewPairsAction.Dispatcher, NextPlayerAction.Dispatcher, - CreatePairCandidateReportListAction.Dispatcher, + CreatePairCandidateReportListAction.Dispatcher, CreatePairCandidateReportAction.Dispatcher, AssignPinsAction.Dispatcher { override val execute: ExecutableActionExecutor diff --git a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/player/NextPlayerActionTest.kt b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/player/NextPlayerActionTest.kt index 0a08f3f7e2..49735077f8 100644 --- a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/player/NextPlayerActionTest.kt +++ b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/player/NextPlayerActionTest.kt @@ -4,12 +4,14 @@ import com.zegreatrob.coupling.model.pairassignmentdocument.NeverPaired import com.zegreatrob.coupling.model.pairassignmentdocument.TimeResultValue import com.zegreatrob.coupling.model.party.PairingRule import com.zegreatrob.coupling.model.player.Player +import com.zegreatrob.coupling.server.action.pairassignmentdocument.CreatePairCandidateReportAction import com.zegreatrob.coupling.server.action.pairassignmentdocument.CreatePairCandidateReportListAction import com.zegreatrob.coupling.server.action.pairassignmentdocument.GameSpin import com.zegreatrob.coupling.server.action.pairassignmentdocument.NextPlayerAction import com.zegreatrob.coupling.server.action.pairassignmentdocument.PairCandidateReport 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.produce @@ -24,16 +26,21 @@ class NextPlayerActionTest { private val amadeus = Player(id = "Mozart", avatarType = null) private val shorty = Player(id = "Napoleon", avatarType = null) + interface NextPlayerActionTestDispatcher : + NextPlayerAction.Dispatcher, + CreatePairCandidateReportListAction.Dispatcher, + CreatePairCandidateReportAction.Dispatcher + @Test fun willUseHistoryToProduceSequenceInOrderOfLongestTimeSinceLastPairedToShortest() = asyncSetup(object : - NextPlayerAction.Dispatcher, ScopeMint() { + NextPlayerActionTestDispatcher, ScopeMint() { val players = notEmptyListOf(bill, ted, amadeus, shorty) val billsPairCandidates = PairCandidateReport(bill, emptyList(), TimeResultValue(3)) val tedsPairCandidates = PairCandidateReport(ted, emptyList(), TimeResultValue(7)) val amadeusPairCandidates = PairCandidateReport(amadeus, emptyList(), TimeResultValue(4)) val shortyPairCandidates = PairCandidateReport(shorty, emptyList(), TimeResultValue(5)) - override val cannon = StubCannon( + override val cannon = StubCannon( receivedActions = mutableListOf(), resultChannel = exerciseScope.produce { send( @@ -46,6 +53,8 @@ class NextPlayerActionTest { ) }, ) + override val execute: ExecutableActionExecutor + get() = TODO("Not yet implemented") }) exercise { perform(NextPlayerAction(longestTimeSpin(players))) } verify { result -> @@ -54,11 +63,11 @@ class NextPlayerActionTest { @Test fun aPersonWhoJustPairedHasLowerPriorityThanSomeoneWhoHasNotPairedInALongTime() = asyncSetup(object : - NextPlayerAction.Dispatcher, ScopeMint() { + NextPlayerAction.Dispatcher, ScopeMint() { val players = notEmptyListOf(bill, ted, amadeus, shorty) val amadeusPairCandidates = PairCandidateReport(amadeus, emptyList(), TimeResultValue(5)) val shortyPairCandidates = PairCandidateReport(shorty, emptyList(), TimeResultValue(0)) - override val cannon = StubCannon( + override val cannon = StubCannon( receivedActions = mutableListOf(), resultChannel = exerciseScope.produce { send(notEmptyListOf(amadeusPairCandidates, shortyPairCandidates)) @@ -70,7 +79,7 @@ class NextPlayerActionTest { @Test fun sequenceWillBeFromLongestToShortest() = asyncSetup(object : - NextPlayerAction.Dispatcher, ScopeMint() { + NextPlayerAction.Dispatcher, ScopeMint() { val players = notEmptyListOf(bill, amadeus, shorty) val billsPairCandidates = PairCandidateReport(bill, emptyList(), TimeResultValue(3)) @@ -78,7 +87,7 @@ class NextPlayerActionTest { val shortyPairCandidates = PairCandidateReport(shorty, emptyList(), TimeResultValue(5)) val pairCandidates = notEmptyListOf(billsPairCandidates, amadeusPairCandidates, shortyPairCandidates) - override val cannon = StubCannon( + override val cannon = StubCannon( receivedActions = mutableListOf(), resultChannel = exerciseScope.produce { send(pairCandidates) }, ) @@ -88,13 +97,13 @@ class NextPlayerActionTest { @Test fun sequenceWillPreferPlayerWhoHasNeverPaired() = asyncSetup(object : - NextPlayerAction.Dispatcher, ScopeMint() { + NextPlayerAction.Dispatcher, ScopeMint() { val players = notEmptyListOf(bill, amadeus, shorty) val billsPairCandidates = PairCandidateReport(bill, emptyList(), TimeResultValue(3)) val amadeusPairCandidates = PairCandidateReport(amadeus, emptyList(), TimeResultValue(4)) val shortyPairCandidates = PairCandidateReport(shorty, emptyList(), NeverPaired) - override val cannon = StubCannon( + override val cannon = StubCannon( receivedActions = mutableListOf(), resultChannel = exerciseScope.produce { send(notEmptyListOf(billsPairCandidates, amadeusPairCandidates, shortyPairCandidates)) @@ -106,7 +115,7 @@ class NextPlayerActionTest { @Test fun willPrioritizeTheReportWithFewestPlayersGivenEqualAmountsOfTime() = asyncSetup(object : - NextPlayerAction.Dispatcher, ScopeMint() { + NextPlayerAction.Dispatcher, ScopeMint() { val players = notEmptyListOf(bill, amadeus, shorty) val billsPairCandidates = PairCandidateReport( @@ -124,7 +133,7 @@ class NextPlayerActionTest { listOf(Player(avatarType = null), Player(avatarType = null)), NeverPaired, ) - override val cannon = StubCannon( + override val cannon = StubCannon( receivedActions = mutableListOf(), resultChannel = exerciseScope.produce { send(notEmptyListOf(billsPairCandidates, amadeusPairCandidates, shortyPairCandidates)) diff --git a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt index 4c423784f5..7d556d9296 100644 --- a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt +++ b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt @@ -24,6 +24,7 @@ import com.zegreatrob.coupling.server.action.connection.ConnectPartyUserCommand 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.CreatePairCandidateReportListAction import com.zegreatrob.coupling.server.action.pairassignmentdocument.CurrentPairAssignmentDocumentQuery import com.zegreatrob.coupling.server.action.pairassignmentdocument.NextPlayerAction import com.zegreatrob.coupling.server.action.pairassignmentdocument.PairAssignmentDocumentListQuery @@ -121,6 +122,7 @@ class CurrentPartyDispatcher( ) : ICommandDispatcher by commandDispatcher, DispatchingActionExecutor, + CreatePairCandidateReportListAction.Dispatcher, ShufflePairsAction.Dispatcher, AssignPinsAction.Dispatcher, NextPlayerAction.Dispatcher, diff --git a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/PairAssignmentDispatcher.kt b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/PairAssignmentDispatcher.kt index 5bb6ba6f16..a5315c6bf2 100644 --- a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/PairAssignmentDispatcher.kt +++ b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/PairAssignmentDispatcher.kt @@ -13,9 +13,10 @@ interface PairAssignmentDispatcher : ShufflePairsAction.Dispatcher, FindNewPairsAction.Dispatcher, NextPlayerAction.Dispatcher, - CreatePairCandidateReportListAction.Dispatcher, + CreatePairCandidateReportListAction.Dispatcher, CreatePairCandidateReportAction.Dispatcher, - Wheel where D : CreatePairCandidateReportListAction.Dispatcher, + Wheel where D : CreatePairCandidateReportAction.Dispatcher, + D : CreatePairCandidateReportListAction.Dispatcher, D : NextPlayerAction.Dispatcher, D : AssignPinsAction.Dispatcher, D : FindNewPairsAction.Dispatcher {