refactor: 优化代码格式,提升可读性和一致性
This commit is contained in:
1 parent
5738d29bd6
commit
47e1a0cb2c
6 files changed
+172
-89
No files matched your search
@@ -26,7 +26,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
from douyin.reservation.douyin_reservation_logic import (
|
||||
process_reservation_attend_window,
|
||||
_sort_reservations_inplace,
|
||||
ReservationItem
|
||||
ReservationItem,
|
||||
)
|
||||
from douyin.reservation.douyin_reservation_verify import validate_back_to_reservation
|
||||
|
||||
@@ -92,7 +92,9 @@ class MockAnalyser:
|
||||
print(f"成功回退到位置 {target_pos}")
|
||||
return True
|
||||
else:
|
||||
print(f"回退距离过大,限制在 {self.high_value_fudai_max_swipe_back} 次滑动内")
|
||||
print(
|
||||
f"回退距离过大,限制在 {self.high_value_fudai_max_swipe_back} 次滑动内"
|
||||
)
|
||||
return False
|
||||
|
||||
|
||||
@@ -136,17 +138,23 @@ def test_reservation_backtrack():
|
||||
|
||||
print("排序前:")
|
||||
for i, r in enumerate(reservations):
|
||||
print(f" {i+1}. {r['room_title']} (位置{r['pos_seen']}) - {int((r['future_ts'] - time.time())/60)}分钟后, 价值: {r['prize_value_yuan']}元")
|
||||
print(
|
||||
f" {i+1}. {r['room_title']} (位置{r['pos_seen']}) - {int((r['future_ts'] - time.time())/60)}分钟后, 价值: {r['prize_value_yuan']}元"
|
||||
)
|
||||
|
||||
_sort_reservations_inplace(reservations)
|
||||
|
||||
print("排序后:")
|
||||
for i, r in enumerate(reservations):
|
||||
print(f" {i+1}. {r['room_title']} (位置{r['pos_seen']}) - {int((r['future_ts'] - time.time())/60)}分钟后, 价值: {r['prize_value_yuan']}元")
|
||||
print(
|
||||
f" {i+1}. {r['room_title']} (位置{r['pos_seen']}) - {int((r['future_ts'] - time.time())/60)}分钟后, 价值: {r['prize_value_yuan']}元"
|
||||
)
|
||||
|
||||
# 验证排序:时间优先,其次价值
|
||||
if (reservations[0]["future_ts"] <= reservations[1]["future_ts"] and
|
||||
reservations[1]["future_ts"] <= reservations[2]["future_ts"]):
|
||||
if (
|
||||
reservations[0]["future_ts"] <= reservations[1]["future_ts"]
|
||||
and reservations[1]["future_ts"] <= reservations[2]["future_ts"]
|
||||
):
|
||||
print("✓ 测试1通过:预约队列排序正确")
|
||||
else:
|
||||
print("✗ 测试1失败:预约队列排序不正确")
|
||||
@@ -156,10 +164,26 @@ def test_reservation_backtrack():
|
||||
print("-" * 40)
|
||||
|
||||
test_cases = [
|
||||
{"pos_seen": 3, "expected_direction": "up", "expected_steps": 2}, # 从5到3,向上2步
|
||||
{"pos_seen": 7, "expected_direction": "down", "expected_steps": 2}, # 从5到7,向下2步
|
||||
{"pos_seen": 5, "expected_direction": "none", "expected_steps": 0}, # 已在目标位置
|
||||
{"pos_seen": 1, "expected_direction": "up", "expected_steps": 4}, # 从5到1,向上4步
|
||||
{
|
||||
"pos_seen": 3,
|
||||
"expected_direction": "up",
|
||||
"expected_steps": 2,
|
||||
}, # 从5到3,向上2步
|
||||
{
|
||||
"pos_seen": 7,
|
||||
"expected_direction": "down",
|
||||
"expected_steps": 2,
|
||||
}, # 从5到7,向下2步
|
||||
{
|
||||
"pos_seen": 5,
|
||||
"expected_direction": "none",
|
||||
"expected_steps": 0,
|
||||
}, # 已在目标位置
|
||||
{
|
||||
"pos_seen": 1,
|
||||
"expected_direction": "up",
|
||||
"expected_steps": 4,
|
||||
}, # 从5到1,向上4步
|
||||
]
|
||||
|
||||
for i, case in enumerate(test_cases):
|
||||
@@ -185,7 +209,9 @@ def test_reservation_backtrack():
|
||||
if direction == case["expected_direction"] and steps == case["expected_steps"]:
|
||||
print(f" ✓ 方向: {direction}, 步数: {steps}")
|
||||
else:
|
||||
print(f" ✗ 期望: {case['expected_direction']}/{case['expected_steps']}, 实际: {direction}/{steps}")
|
||||
print(
|
||||
f" ✗ 期望: {case['expected_direction']}/{case['expected_steps']}, 实际: {direction}/{steps}"
|
||||
)
|
||||
|
||||
print("✓ 测试2通过:位置计算和回退方向正确")
|
||||
|
||||
@@ -240,10 +266,14 @@ def test_reservation_backtrack():
|
||||
|
||||
if result and analyser.room_pos == 3:
|
||||
print("✓ 测试3通过:成功回退到目标直播间")
|
||||
print(f" 滑动统计: 向上{analyser.swipe_up_count}次, 向下{analyser.swipe_down_count}次")
|
||||
print(
|
||||
f" 滑动统计: 向上{analyser.swipe_up_count}次, 向下{analyser.swipe_down_count}次"
|
||||
)
|
||||
else:
|
||||
print("✗ 测试3失败:回退失败")
|
||||
print(f" 当前位置: {analyser.room_pos}, 目标位置: {test_reservations[0]['pos_seen']}")
|
||||
print(
|
||||
f" 当前位置: {analyser.room_pos}, 目标位置: {test_reservations[0]['pos_seen']}"
|
||||
)
|
||||
|
||||
# 测试4:回退校验
|
||||
print("\n测试4:回退校验")
|
||||
@@ -260,8 +290,11 @@ def test_reservation_backtrack():
|
||||
|
||||
# 替换实际函数
|
||||
import douyin.fudai.douyin_fudai_detail
|
||||
|
||||
original_func = douyin.fudai.douyin_fudai_detail.read_live_room_title_core
|
||||
douyin.fudai.douyin_fudai_detail.read_live_room_title_core = mock_read_live_room_title_core
|
||||
douyin.fudai.douyin_fudai_detail.read_live_room_title_core = (
|
||||
mock_read_live_room_title_core
|
||||
)
|
||||
|
||||
try:
|
||||
# 测试校验通过的情况
|
||||
@@ -317,4 +350,4 @@ def test_reservation_backtrack():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_reservation_backtrack()
|
||||
test_reservation_backtrack()
|
||||
Reference in new issue
Block a user