Skip to content

Commit

Permalink
how are there still more layers
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfmurdock committed Jul 19, 2023
1 parent 262e9e5 commit 900168d
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<CreatePairCandidateReportListAction.Dispatcher, NotEmptyList<PairCandidateReport>> {
override val performFunc = link(Dispatcher::perform)
@ActionMint
data class CreatePairCandidateReportListAction(val game: GameSpin) {

interface Dispatcher : PlayerCandidatesFinder {
interface Dispatcher<out D> : PlayerCandidatesFinder where D : CreatePairCandidateReportAction.Dispatcher {

val execute: ExecutableActionExecutor<CreatePairCandidateReportAction.Dispatcher>

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<PairCandidateReport> =
game.createReports(game.rule)

private fun GameSpin.createReports(rule: PairingRule) =
remainingPlayers.map { player -> pairCandidateReport(rule, player) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import kotools.types.collection.toNotEmptyList
@ActionMint
data class FindNewPairsAction(val game: Game) {
interface Dispatcher<out D> : CannonProvider<D>
where D : CreatePairCandidateReportListAction.Dispatcher,
where D : CreatePairCandidateReportAction.Dispatcher,
D : CreatePairCandidateReportListAction.Dispatcher<D>,
D : NextPlayerAction.Dispatcher<D> {

val wheel: Wheel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import com.zegreatrob.testmints.action.annotation.ActionMint
@ActionMint
data class NextPlayerAction(val gameSpin: GameSpin) {

interface Dispatcher<out D> : CannonProvider<D> where D : CreatePairCandidateReportListAction.Dispatcher {
interface Dispatcher<out D> : CannonProvider<D>
where D : CreatePairCandidateReportAction.Dispatcher,
D : CreatePairCandidateReportListAction.Dispatcher<D> {

suspend fun perform(action: NextPlayerAction): PairCandidateReport = with(action.createPairCandidateReports()) {
toList().fold(head) { reportWithLongestTime, report ->
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 : CreatePairCandidateReportListAction.Dispatcher,
CannonProvider<D> where D : CreatePairCandidateReportAction.Dispatcher,
D : CreatePairCandidateReportListAction.Dispatcher<D>,
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 @@ -22,7 +22,8 @@ data class ShufflePairsAction(
val history: List<PairAssignmentDocument>,
) {
interface Dispatcher<out D> : Clock, CannonProvider<D>
where D : CreatePairCandidateReportListAction.Dispatcher,
where D : CreatePairCandidateReportAction.Dispatcher,
D : CreatePairCandidateReportListAction.Dispatcher<D>,
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 @@ -8,19 +8,19 @@ 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

class CreatePairCandidateReportsActionTest {

class WhenThePartyPrefersPairingWithDifferentBadges :
CreatePairCandidateReportListAction.Dispatcher {
CreatePairCandidateReportListAction.Dispatcher<CreatePairCandidateReportAction.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)
Expand All @@ -47,7 +47,7 @@ class CreatePairCandidateReportsActionTest {
}

@Test
fun willReturnFilterCandidatesByUnlikeBadge() = setup(object {
fun willReturnFilterCandidatesByUnlikeBadge() = asyncSetup(object {
val history = emptyList<PairAssignmentDocument>()
val bill = Player(id = "Bill", badge = 1, avatarType = null)
val ted = Player(id = "Ted", badge = 1, avatarType = null)
Expand Down Expand Up @@ -76,7 +76,7 @@ class CreatePairCandidateReportsActionTest {
}

@Test
fun willReturnReportForOnePlayer() = setup(object {
fun willReturnReportForOnePlayer() = asyncSetup(object {
val history = emptyList<PairAssignmentDocument>()
val bill = Player(id = "Bill", badge = 1, avatarType = null)
val players = notEmptyListOf(bill)
Expand All @@ -92,8 +92,8 @@ class CreatePairCandidateReportsActionTest {
}

@Test
fun whenThePartyPrefersPairingByLongestTime() = setup(object :
CreatePairCandidateReportListAction.Dispatcher {
fun whenThePartyPrefersPairingByLongestTime() = asyncSetup(object :
CreatePairCandidateReportListAction.Dispatcher<CreatePairCandidateReportAction.Dispatcher> {
override val execute = stubActionExecutor(CreatePairCandidateReportAction::class)
val history = listOf<PairAssignmentDocument>()
val bill = Player(id = "Bill", badge = 1, avatarType = null)
Expand Down Expand Up @@ -131,8 +131,7 @@ class CreatePairCandidateReportsActionTest {
players: List<Player>,
history: List<PairAssignmentDocument>,
) = whenever(
receive = CreatePairCandidateReportAction(pairCandidateReport.player, history, players)
.also { println("expecting $it") },
receive = CreatePairCandidateReportAction(pairCandidateReport.player, history, players),
returnValue = pairCandidateReport,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class FindNewPairsActionTest {

interface FindNewPairsActionTestDispatcher :
NextPlayerAction.Dispatcher<FindNewPairsActionTestDispatcher>,
CreatePairCandidateReportListAction.Dispatcher,
CreatePairCandidateReportListAction.Dispatcher<FindNewPairsActionTestDispatcher>,
CreatePairCandidateReportAction.Dispatcher {
override val execute: ExecutableActionExecutor<FindNewPairsActionTestDispatcher>
get() = TODO("Not yet implemented")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ import kotlin.test.Test
class GameExamplesTest {

companion object :
CreatePairCandidateReportListAction.Dispatcher<Companion>,
ShufflePairsAction.Dispatcher<Companion>,
FindNewPairsAction.Dispatcher<Companion>,
AssignPinsAction.Dispatcher,
DispatchingActionExecutor<Companion>,
NextPlayerAction.Dispatcher<Companion>,
AssignPinsAction.Dispatcher,
CreatePairCandidateReportAction.Dispatcher,
CreatePairCandidateReportListAction.Dispatcher,
DispatchingActionExecutor<Companion>,
Wheel {
override val wheel = this
override val actionDispatcher = this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ShufflePairsActionTest {
interface ShufflePairsActionInner :
FindNewPairsAction.Dispatcher<ShufflePairsActionInner>,
NextPlayerAction.Dispatcher<ShufflePairsActionInner>,
CreatePairCandidateReportListAction.Dispatcher,
CreatePairCandidateReportListAction.Dispatcher<ShufflePairsActionInner>,
CreatePairCandidateReportAction.Dispatcher,
AssignPinsAction.Dispatcher {
override val execute: ExecutableActionExecutor<ShufflePairsActionInner>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<NextPlayerActionTestDispatcher>,
CreatePairCandidateReportListAction.Dispatcher<NextPlayerActionTestDispatcher>,
CreatePairCandidateReportAction.Dispatcher

@Test
fun willUseHistoryToProduceSequenceInOrderOfLongestTimeSinceLastPairedToShortest() = asyncSetup(object :
NextPlayerAction.Dispatcher<CreatePairCandidateReportListAction.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<CreatePairCandidateReportListAction.Dispatcher>(
override val cannon = StubCannon<NextPlayerActionTestDispatcher>(
receivedActions = mutableListOf(),
resultChannel = exerciseScope.produce<Any> {
send(
Expand All @@ -46,6 +53,8 @@ class NextPlayerActionTest {
)
},
)
override val execute: ExecutableActionExecutor<CreatePairCandidateReportAction.Dispatcher>
get() = TODO("Not yet implemented")
}) exercise {
perform(NextPlayerAction(longestTimeSpin(players)))
} verify { result ->
Expand All @@ -54,11 +63,11 @@ class NextPlayerActionTest {

@Test
fun aPersonWhoJustPairedHasLowerPriorityThanSomeoneWhoHasNotPairedInALongTime() = asyncSetup(object :
NextPlayerAction.Dispatcher<CreatePairCandidateReportListAction.Dispatcher>, ScopeMint() {
NextPlayerAction.Dispatcher<NextPlayerActionTestDispatcher>, 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<CreatePairCandidateReportListAction.Dispatcher>(
override val cannon = StubCannon<NextPlayerActionTestDispatcher>(
receivedActions = mutableListOf(),
resultChannel = exerciseScope.produce<Any> {
send(notEmptyListOf(amadeusPairCandidates, shortyPairCandidates))
Expand All @@ -70,15 +79,15 @@ class NextPlayerActionTest {

@Test
fun sequenceWillBeFromLongestToShortest() = asyncSetup(object :
NextPlayerAction.Dispatcher<CreatePairCandidateReportListAction.Dispatcher>, ScopeMint() {
NextPlayerAction.Dispatcher<NextPlayerActionTestDispatcher>, 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(), TimeResultValue(5))

val pairCandidates = notEmptyListOf(billsPairCandidates, amadeusPairCandidates, shortyPairCandidates)
override val cannon = StubCannon<CreatePairCandidateReportListAction.Dispatcher>(
override val cannon = StubCannon<NextPlayerActionTestDispatcher>(
receivedActions = mutableListOf(),
resultChannel = exerciseScope.produce<Any> { send(pairCandidates) },
)
Expand All @@ -88,13 +97,13 @@ class NextPlayerActionTest {

@Test
fun sequenceWillPreferPlayerWhoHasNeverPaired() = asyncSetup(object :
NextPlayerAction.Dispatcher<CreatePairCandidateReportListAction.Dispatcher>, ScopeMint() {
NextPlayerAction.Dispatcher<NextPlayerActionTestDispatcher>, 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<CreatePairCandidateReportListAction.Dispatcher>(
override val cannon = StubCannon<NextPlayerActionTestDispatcher>(
receivedActions = mutableListOf(),
resultChannel = exerciseScope.produce<Any> {
send(notEmptyListOf(billsPairCandidates, amadeusPairCandidates, shortyPairCandidates))
Expand All @@ -106,7 +115,7 @@ class NextPlayerActionTest {

@Test
fun willPrioritizeTheReportWithFewestPlayersGivenEqualAmountsOfTime() = asyncSetup(object :
NextPlayerAction.Dispatcher<CreatePairCandidateReportListAction.Dispatcher>, ScopeMint() {
NextPlayerAction.Dispatcher<NextPlayerActionTestDispatcher>, ScopeMint() {
val players = notEmptyListOf(bill, amadeus, shorty)

val billsPairCandidates = PairCandidateReport(
Expand All @@ -124,7 +133,7 @@ class NextPlayerActionTest {
listOf(Player(avatarType = null), Player(avatarType = null)),
NeverPaired,
)
override val cannon = StubCannon<CreatePairCandidateReportListAction.Dispatcher>(
override val cannon = StubCannon<NextPlayerActionTestDispatcher>(
receivedActions = mutableListOf(),
resultChannel = exerciseScope.produce<Any> {
send(notEmptyListOf(billsPairCandidates, amadeusPairCandidates, shortyPairCandidates))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -121,6 +122,7 @@ class CurrentPartyDispatcher(
) :
ICommandDispatcher by commandDispatcher,
DispatchingActionExecutor<CurrentPartyDispatcher>,
CreatePairCandidateReportListAction.Dispatcher<CurrentPartyDispatcher>,
ShufflePairsAction.Dispatcher<CurrentPartyDispatcher>,
AssignPinsAction.Dispatcher,
NextPlayerAction.Dispatcher<CurrentPartyDispatcher>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ interface PairAssignmentDispatcher<D> :
ShufflePairsAction.Dispatcher<D>,
FindNewPairsAction.Dispatcher<D>,
NextPlayerAction.Dispatcher<D>,
CreatePairCandidateReportListAction.Dispatcher,
CreatePairCandidateReportListAction.Dispatcher<D>,
CreatePairCandidateReportAction.Dispatcher,
Wheel where D : CreatePairCandidateReportListAction.Dispatcher,
Wheel where D : CreatePairCandidateReportAction.Dispatcher,
D : CreatePairCandidateReportListAction.Dispatcher<D>,
D : NextPlayerAction.Dispatcher<D>,
D : AssignPinsAction.Dispatcher,
D : FindNewPairsAction.Dispatcher<D> {
Expand Down

0 comments on commit 900168d

Please sign in to comment.