测试评估
| 指标 | 结果 |
|---|---|
| Base 测试 | FAIL |
| Plus 测试 | FAIL |
| 代码长度 | 996 字符 |
模型生成的代码 (996 字符)
def max_Product(arr):
"""
Find a pair of integers in the array with the highest product.
Returns the pair as a tuple (smaller, larger).
"""
# Handle edge case: array must have at least two elements
if len(arr) < 2:
return None # or raise an exception
# Initialize extremes
max1 = float('-inf') # largest
max2 = float('-inf') # second largest
min1 = float('inf') # smallest
min2 = float('inf') # second smallest
for num in arr:
# Update largest and second largest
if num > max1:
max2 = max1
max1 = num
elif num > max2:
max2 = num
# Update smallest and second smallest
if num < min1:
min2 = min1
min1 = num
elif num < min2:
min2 = num
# Compare products
product1 = max1 * max2
product2 = min1 * min2
if product1 >= product2:
return (max2, max1)
else:
return (min1, min2)
Base 失败测试用例
[[0, -1, -2, -4, 5, 0, -6]]
Plus 失败测试用例
[[10, -20, 30, -40, 50, -60, 70, -80, 90, -100]]