mjAi/tests/test_scoring.py

73 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from src.engine.scoring import calculate_score
def test_dealer_self_draw():
"""
测试用例 1: 庄家自摸,总番数 3底分 10
"""
fan = 3
base_score = 10
is_self_draw = True
is_dealer = True
scores = calculate_score(fan, base_score, is_self_draw, is_dealer)
expected_scores = {"winner": 240, "loser": [-80, -80, -80]}
assert scores == expected_scores, f"庄家自摸测试失败: {scores} != {expected_scores}"
def test_non_dealer_point_win():
"""
测试用例 2: 闲家点炮,总番数 2底分 10
"""
fan = 2
base_score = 10
is_self_draw = False
is_dealer = False
scores = calculate_score(fan, base_score, is_self_draw, is_dealer)
expected_scores = {"winner": 40, "loser": [-40, 0, 0]}
assert scores == expected_scores, f"闲家点炮测试失败: {scores} != {expected_scores}"
def test_non_dealer_self_draw():
"""
测试用例 3: 闲家自摸,总番数 4底分 10
"""
fan = 4
base_score = 10
is_self_draw = True
is_dealer = False
scores = calculate_score(fan, base_score, is_self_draw, is_dealer)
expected_scores = {"winner": 160, "loser": [-80, -40, -40]}
assert scores == expected_scores, f"闲家自摸测试失败: {scores} != {expected_scores}"
def test_dealer_point_win():
"""
测试用例 4: 庄家点炮,总番数 1底分 5
"""
fan = 1
base_score = 5
is_self_draw = False
is_dealer = True
scores = calculate_score(fan, base_score, is_self_draw, is_dealer)
expected_scores = {"winner": 10, "loser": [-10, 0, 0]}
assert scores == expected_scores, f"庄家点炮测试失败: {scores} != {expected_scores}"
if __name__ == "__main__":
# 单独执行测试
test_dealer_self_draw()
print("测试 1: 庄家自摸通过!")
test_non_dealer_point_win()
print("测试 2: 闲家点炮通过!")
test_non_dealer_self_draw()
print("测试 3: 闲家自摸通过!")
test_dealer_point_win()
print("测试 4: 庄家点炮通过!")