mbcp/tests/answer.py

59 lines
1.6 KiB
Python
Raw Normal View History

2024-08-27 21:39:36 +08:00
# -*- coding: utf-8 -*-
"""
Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
@Time : 2024/8/27 下午1:03
@Author : snowykami
@Email : snowykami@outlook.com
@File : .answer.py
@Software: PyCharm
"""
2024-08-28 01:26:59 +08:00
from typing import Optional
2024-08-27 21:39:36 +08:00
from liteyuki.log import logger # type: ignore
2024-08-28 01:26:59 +08:00
def output_ans(correct_ans, actual_ans, condition: Optional[bool] = None,question: Optional[str] = None):
2024-08-27 21:39:36 +08:00
"""
输出答案
Args:
correct_ans:
actual_ans:
2024-08-28 01:26:59 +08:00
condition: 判对条件
question: 问题
2024-08-27 21:39:36 +08:00
Returns:
"""
print("")
if question is not None:
logger.info(f"问题:{question}")
2024-08-28 01:26:59 +08:00
r = (correct_ans == actual_ans) if condition is None else condition
2024-08-27 21:39:36 +08:00
if r:
logger.success(f"测试正确 正确答案:{correct_ans} 实际答案:{actual_ans}")
else:
logger.error(f"测试错误 正确答案:{correct_ans} 实际答案:{actual_ans}")
2024-08-28 01:26:59 +08:00
assert r
def output_step_ans(correct_ans, actual_ans, condition: Optional[bool] = None, question: Optional[str] = None):
"""
输出步骤答案
Args:
correct_ans: 正确答案
actual_ans: 实际答案
condition: 判对条件
question: 问题
Returns:
"""
print("")
if question is not None:
logger.info(f" 步骤:{question}")
r = (correct_ans == actual_ans) if condition is None else condition
if r:
logger.success(f" 正确 正确:{correct_ans} 实际:{actual_ans}")
else:
logger.error(f" 错误 正确:{correct_ans} 实际:{actual_ans}")