154 lines
3.6 KiB
Python
154 lines
3.6 KiB
Python
import pytest
|
|
from src.engine.calculate_fan import calculate_fan, is_seven_pairs, is_cleared, is_big_pairs
|
|
|
|
# 测试用例
|
|
|
|
def test_basic_win():
|
|
"""
|
|
测试平胡(基本胡)计分
|
|
"""
|
|
hand = [0] * 108
|
|
# 模拟平胡手牌: 四组顺子 + 一对将
|
|
hand[0] = 2 # 将: 两张1条
|
|
hand[3] = 1 # 2条
|
|
hand[4] = 1 # 3条
|
|
hand[5] = 1 # 4条
|
|
hand[10] = 1 # 5条
|
|
hand[11] = 1 # 6条
|
|
hand[12] = 1 # 7条
|
|
hand[20] = 1 # 8条
|
|
hand[21] = 1 # 9条
|
|
hand[22] = 1 # 1筒
|
|
hand[30] = 1 # 2筒
|
|
hand[31] = 1 # 3筒
|
|
|
|
melds = []
|
|
conditions = {}
|
|
|
|
fan = calculate_fan(hand, melds, is_self_draw=False, is_cleared=False, conditions=conditions)
|
|
assert fan == 1, f"Expected 1 fan, got {fan}"
|
|
|
|
|
|
def test_clear_win():
|
|
"""
|
|
测试清一色计分(不加自摸番)
|
|
"""
|
|
hand = [0] * 108
|
|
# 模拟清一色手牌
|
|
hand[0] = 2
|
|
hand[4] = 1
|
|
hand[5] = 1
|
|
hand[6] = 1
|
|
hand[10] = 1
|
|
hand[11] = 1
|
|
hand[12] = 1
|
|
hand[20] = 1
|
|
hand[21] = 1
|
|
hand[22] = 1
|
|
hand[23] = 1
|
|
|
|
melds = []
|
|
conditions = {"is_seven_pairs": False, "add_self_draw": False}
|
|
|
|
fan = calculate_fan(hand, melds, is_self_draw=True, is_cleared=is_cleared(hand), conditions=conditions)
|
|
assert fan == 3, f"Expected 3 fans (1 basic + 2 cleared), got {fan}"
|
|
|
|
|
|
|
|
|
|
def test_seven_pairs():
|
|
"""
|
|
测试七对计分
|
|
"""
|
|
hand = [0] * 108
|
|
# 模拟七对手牌
|
|
hand[0] = 2 # 1条
|
|
hand[4] = 2 # 2条
|
|
hand[8] = 2 # 3条
|
|
hand[12] = 2 # 4条
|
|
hand[16] = 2 # 5条
|
|
hand[20] = 2 # 6条
|
|
hand[24] = 2 # 7条
|
|
|
|
melds = []
|
|
conditions = {"is_seven_pairs": is_seven_pairs(hand)}
|
|
|
|
fan = calculate_fan(hand, melds, is_self_draw=False, is_cleared=False, conditions=conditions)
|
|
assert fan == 2, f"Expected 2 fans (7 pairs), got {fan}"
|
|
|
|
|
|
def test_big_pairs():
|
|
"""
|
|
测试大对子计分
|
|
"""
|
|
hand = [0] * 108
|
|
# 模拟大对子手牌
|
|
hand[0] = 3 # 1条
|
|
hand[4] = 3 # 2条
|
|
hand[8] = 3 # 3条
|
|
hand[12] = 2 # 将: 4条
|
|
|
|
melds = []
|
|
conditions = {"is_big_pairs": is_big_pairs(hand)}
|
|
|
|
# Debug output
|
|
print(f"Conditions: {conditions}")
|
|
|
|
# 确保大对子检测正确
|
|
assert is_big_pairs(hand), "The hand is not identified as a big pairs hand."
|
|
|
|
fan = calculate_fan(hand, melds, is_self_draw=False, is_cleared=False, conditions=conditions)
|
|
assert fan == 2, f"Expected 2 fans (big pairs), got {fan}"
|
|
|
|
|
|
|
|
def test_gang_flower():
|
|
"""
|
|
测试杠上开花计分
|
|
"""
|
|
hand = [0] * 108
|
|
# 模拟杠上开花手牌
|
|
hand[0] = 2 # 将: 两张1条
|
|
hand[3] = 1 # 2条
|
|
hand[4] = 1 # 3条
|
|
hand[5] = 1 # 4条
|
|
hand[10] = 1 # 5条
|
|
hand[11] = 1 # 6条
|
|
hand[12] = 1 # 7条
|
|
hand[20] = 1 # 8条
|
|
hand[21] = 1 # 9条
|
|
hand[22] = 1 # 1筒
|
|
|
|
melds = []
|
|
conditions = {"is_gang_flower": True}
|
|
|
|
fan = calculate_fan(hand, melds, is_self_draw=True, is_cleared=False, conditions=conditions)
|
|
assert fan == 2, f"Expected 2 fans (1 basic + 1 gang flower), got {fan}"
|
|
|
|
|
|
def test_dragon_seven_pairs():
|
|
"""
|
|
测试龙七对计分
|
|
"""
|
|
hand = [0] * 108
|
|
# 模拟龙七对手牌
|
|
hand[0] = 2 # 1条
|
|
hand[4] = 2 # 2条
|
|
hand[8] = 2 # 3条
|
|
hand[12] = 2 # 4条
|
|
hand[16] = 2 # 5条
|
|
hand[20] = 2 # 6条
|
|
hand[24] = 4 # 龙: 7条
|
|
|
|
melds = []
|
|
conditions = {
|
|
"is_dragon_seven_pairs": True,
|
|
"is_seven_pairs": True,
|
|
}
|
|
|
|
fan = calculate_fan(hand, melds, is_self_draw=True, is_cleared=False, conditions=conditions)
|
|
assert fan == 13, f"Expected 13 fans (1 self-draw + 12 dragon seven pairs), got {fan}"
|
|
|
|
|
|
|