@@ -45,6 +45,64 @@ class GbBotDecisionServiceTest {
4545 assertEquals(3 , suggestedIndex)
4646 }
4747
48+ @Test
49+ fun `discard suggestion compares ready score before discard preference` () {
50+ val service = GbBotDecisionService (8 )
51+ val hand = listOf (MahjongTile .EAST , MahjongTile .M2 , MahjongTile .M3 )
52+ val ready = GbTingResponse (true , listOf (GbTingCandidate (" W1" , 8 )), null )
53+ assertTrue(
54+ GbBotDecisionService .discardPreference(hand, MahjongTile .EAST ) >
55+ GbBotDecisionService .discardPreference(hand, MahjongTile .M2 ),
56+ )
57+
58+ val suggestedIndex =
59+ service.suggestedDiscardIndex(hand, emptyList()) { remaining, _ ->
60+ if (MahjongTile .M2 !in remaining) {
61+ ready
62+ } else {
63+ GbTingResponse (true , emptyList(), null )
64+ }
65+ }
66+
67+ assertEquals(1 , suggestedIndex)
68+ }
69+
70+ @Test
71+ fun `discard suggestion compares discard preference after equal ready scores` () {
72+ val service = GbBotDecisionService (8 )
73+ val hand = listOf (MahjongTile .M2 , MahjongTile .M3 , MahjongTile .EAST )
74+
75+ val suggestedIndex =
76+ service.suggestedDiscardIndex(hand, emptyList()) { _, _ ->
77+ GbTingResponse (true , emptyList(), null )
78+ }
79+
80+ assertEquals(2 , suggestedIndex)
81+ }
82+
83+ @Test
84+ fun `discard suggestion evaluates unique candidates in hand order` () {
85+ val service = GbBotDecisionService (8 )
86+ val hand = listOf (MahjongTile .M1 , MahjongTile .P1 , MahjongTile .S1 )
87+ val evaluatedHands = mutableListOf<List <MahjongTile >>()
88+
89+ val suggestedIndex =
90+ service.suggestedDiscardIndex(hand, emptyList()) { remaining, _ ->
91+ evaluatedHands + = remaining.toList()
92+ GbTingResponse (true , emptyList(), null )
93+ }
94+
95+ assertEquals(0 , suggestedIndex)
96+ assertEquals(
97+ listOf (
98+ listOf (MahjongTile .P1 , MahjongTile .S1 ),
99+ listOf (MahjongTile .M1 , MahjongTile .S1 ),
100+ listOf (MahjongTile .M1 , MahjongTile .P1 ),
101+ ),
102+ evaluatedHands,
103+ )
104+ }
105+
48106 @Test
49107 fun `discard suggestion evaluates the first remaining hand once per duplicated tile` () {
50108 val service = GbBotDecisionService (8 )
0 commit comments