测试评估
| 指标 | 结果 |
|---|---|
| Base 测试 | PASS |
| Plus 测试 | PASS |
| 代码长度 | 783 字符 |
模型生成的代码 (783 字符)
def sum_in_range(l: int, r: int) -> int:
"""
Returns the sum of all odd natural numbers in the inclusive range [l, r].
Natural numbers are assumed to be positive integers (>=1), but the function
works for any integer range.
"""
# If the range is invalid (l > r), return 0.
if l > r:
return 0
# Adjust l to the first odd number in the range.
if l % 2 == 0:
l += 1
# Adjust r to the last odd number in the range.
if r % 2 == 0:
r -= 1
# If after adjustment l > r, there are no odd numbers.
if l > r:
return 0
# Number of odd numbers in the adjusted range.
n = (r - l) // 2 + 1
# Sum of an arithmetic progression: n * (first + last) / 2.
return n * (l + r) // 2
Base 失败测试用例
- 无失败测试
Plus 失败测试用例
- 无失败测试