fix: use equal weight sharing for remaining 15% and quantize min_rate floor comparison to 2 decimal places
This commit is contained in:
@@ -406,8 +406,17 @@ def test_calculate_target_rate_priority_weighted():
|
||||
assert calculate_target_rate(["0.18", "0.25"], 50, "priority_weighted_plus_percent") == Decimal("0.29")
|
||||
# 单来源时等同于该来源倍率 + 百分比
|
||||
assert calculate_target_rate(["0.18"], 50, "priority_weighted_plus_percent") == Decimal("0.27")
|
||||
# 多来源时权重按低倍率优先,最高倍率不会主导价格
|
||||
assert calculate_target_rate(["0.18", "0.25", "0.38"], 50, "priority_weighted_plus_percent") == Decimal("0.29")
|
||||
# 多来源时最低倍率占 85%,其余平分 15%:
|
||||
# 0.18 * 0.85 + (0.25 + 0.38) * 0.075 = 0.20025 -> 0.20025 * 1.5 = 0.300375 -> 0.30
|
||||
assert calculate_target_rate(["0.18", "0.25", "0.38"], 50, "priority_weighted_plus_percent") == Decimal("0.30")
|
||||
|
||||
# 4 个来源以锁定均分 15% 的权重语义:
|
||||
# 0.18 * 0.85 + (0.24 + 0.30 + 0.36) * 0.05 = 0.198 -> 0.198 * 1.5 = 0.297 -> 0.30
|
||||
assert calculate_target_rate(["0.18", "0.24", "0.30", "0.36"], 50, "priority_weighted_plus_percent") == Decimal("0.30")
|
||||
assert calculate_target_rate(["0.18", "0.24", "0.30", "0.36"], 0, "priority_weighted_plus_percent") == Decimal("0.20")
|
||||
|
||||
# 验证保护线与精度保护:最低来源 0.124,应当四舍五入并返回两位小数
|
||||
assert calculate_target_rate(["0.124"], 0, "priority_weighted_plus_percent") == Decimal("0.12")
|
||||
|
||||
# 无可用正数倍率时报错
|
||||
with pytest.raises(WebsiteError, match="没有可用的正数上游倍率"):
|
||||
|
||||
Reference in New Issue
Block a user