Llama 3.3 70B × test-writing
6.3Edge-case thinking + pytest parametrize discipline
correctness 7.0quality 6.0documentation 6.01103ms
$ cat test-writing.prompt — what the model was asked
Write a comprehensive pytest test suite for the following Python function:
```python
def parse_duration(s: str) -> int:
"""Parse a human duration string into total seconds.
Accepted formats: '1h', '30m', '45s', '1h30m', '2h15m30s'.
Raises ValueError on unrecognized input.
"""
import re
pattern = r'^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$'
m = re.fullmatch(pattern, s.strip())
if not m or not s.strip():
raise ValueError(f'Invalid duration: {s!r}')
h, mi, sec = (int(x) if x else 0 for x in m.groups())
return h * 3600 + mi * 60 + sec
```
Requirements:
- Use pytest (plain functions, no unittest classes)
- Use `@pytest.mark.parametrize` for the happy-path cases
- Cover at least 3 edge/error cases with `pytest.raises`
- Name tests descriptively so failures are self-explaining
- No mocking needed — the function is pure
- Do not reimplement the function; test it as a black box
run 1 of 1
6.3correctness 7.0quality 6.0documentation 6.01103ms
# judge: Covers h, m, s, hm, hms and a zero-case, but omits the standalone 'ms' format explicitly required by the rubric; error cases are adequate (empty, invalid char, garbage string) though lack tests for malformed ordering; whitespace test is a nice touch but generic test names and lack of parametrize ids weaken documentation quality.
$ cat llama-3.3-70b.test-writing.r1.response
```python
import pytest
from your_module import parse_duration # Replace 'your_module' with the actual module name
@pytest.mark.parametrize(
"input_str, expected_seconds",
[
("1h", 3600),
("30m", 1800),
("45s", 45),
("1h30m", 5400),
("2h15m30s", 9030),
("0h0m0s", 0),
],
)
def test_parse_duration_happy_path(input_str, expected_seconds):
"""Test parsing of valid duration strings."""
assert parse_duration(input_str) == expected_seconds
def test_parse_duration_empty_string():
"""Test parsing of an empty string."""
with pytest.raises(ValueError):
parse_duration("")
def test_parse_duration_invalid_string():
"""Test parsing of a string with invalid format."""
with pytest.raises(ValueError):
parse_duration("1x")
def test_parse_duration_unexpected_input():
"""Test parsing of a string with unexpected input."""
with pytest.raises(ValueError):
parse_duration("abc")
def test_parse_duration_leading_trailing_whitespace():
"""Test parsing of a string with leading and trailing whitespace."""
assert parse_duration(" 1h ") == parse_duration("1h")
```