测试评估
| 指标 | 结果 |
|---|---|
| Base 测试 | PASS |
| Plus 测试 | FAIL |
| 代码长度 | 915 字符 |
模型生成的代码 (915 字符)
import ast
def tuple_str_int(s: str) -> tuple:
"""
Convert a string representation of a tuple of integers into an actual tuple of integers.
Args:
s (str): A string containing a tuple of integers, e.g., "(7, 8, 9)".
Returns:
tuple: A tuple of integers parsed from the string.
Example:
>>> tuple_str_int("(7, 8, 9)")
(7, 8, 9)
"""
# Use ast.literal_eval for safe evaluation of the string as a Python literal.
# This raises ValueError if the string does not represent a valid tuple literal.
result = ast.literal_eval(s)
if not isinstance(result, tuple):
raise ValueError("Input string does not represent a tuple")
# Ensure all elements are integers (optional strict check)
if not all(isinstance(item, int) for item in result):
raise ValueError("All elements in the tuple must be integers")
return result
Base 失败测试用例
- 无失败测试
Plus 失败测试用例
['((7, 8, 9)']