73 lines
2.0 KiB
Python
73 lines
2.0 KiB
Python
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: 庄家点炮通过!")
|