@@ -24,7 +24,7 @@ class GbBotDecisionServiceTest {
2424
2525 assertTrue(
2626 GbBotDecisionService .discardPreference(hand, MahjongTile .P9 ) >
27- GbBotDecisionService .discardPreference(hand, MahjongTile .M2 )
27+ GbBotDecisionService .discardPreference(hand, MahjongTile .M2 ),
2828 )
2929 }
3030
@@ -33,14 +33,49 @@ class GbBotDecisionServiceTest {
3333 val service = GbBotDecisionService (8 )
3434 val hand = listOf (MahjongTile .M1 , MahjongTile .M2 , MahjongTile .M3 , MahjongTile .EAST )
3535
36- val suggestedIndex = service.suggestedDiscardIndex(hand, emptyList()) { remaining, _ ->
37- if (MahjongTile .EAST !in remaining) {
38- GbTingResponse (true , listOf (GbTingCandidate (" W1" , 8 )), null )
39- } else {
40- GbTingResponse (true , emptyList(), null )
36+ val suggestedIndex =
37+ service.suggestedDiscardIndex(hand, emptyList()) { remaining, _ ->
38+ if (MahjongTile .EAST !in remaining) {
39+ GbTingResponse (true , listOf (GbTingCandidate (" W1" , 8 )), null )
40+ } else {
41+ GbTingResponse (true , emptyList(), null )
42+ }
4143 }
42- }
4344
4445 assertEquals(3 , suggestedIndex)
4546 }
47+
48+ @Test
49+ fun `discard suggestion evaluates the first remaining hand once per duplicated tile` () {
50+ val service = GbBotDecisionService (8 )
51+ val hand = listOf (MahjongTile .M1 , MahjongTile .M2 , MahjongTile .M1 )
52+ val evaluatedHands = mutableListOf<List <MahjongTile >>()
53+
54+ service.suggestedDiscardIndex(hand, emptyList()) { remaining, _ ->
55+ evaluatedHands + = remaining.toList()
56+ GbTingResponse (true , emptyList(), null )
57+ }
58+
59+ assertEquals(
60+ listOf (
61+ listOf (MahjongTile .M2 , MahjongTile .M1 ),
62+ listOf (MahjongTile .M1 , MahjongTile .M1 ),
63+ ),
64+ evaluatedHands,
65+ )
66+ }
67+
68+ @Test
69+ fun `discard suggestion preserves null evaluator recomputation` () {
70+ val service = GbBotDecisionService (8 )
71+ val hand = listOf (MahjongTile .M1 , MahjongTile .M1 , MahjongTile .M1 )
72+ var evaluations = 0
73+
74+ service.suggestedDiscardIndex(hand, emptyList()) { _, _ ->
75+ evaluations++
76+ null
77+ }
78+
79+ assertEquals(hand.size, evaluations)
80+ }
4681}
0 commit comments