Skip to content
mager-bench1.3

GPT-5.6 Sol × test-writing

8.3

Edge-case thinking + pytest parametrize discipline

correctness 8.0quality 9.0documentation 8.010947ms
$ 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

8.3
correctness 8.0quality 9.0documentation 8.010947ms

# judge: The suite is accurate, concise, and covers many useful boundary and invalid inputs, but it misses a dedicated valid minutes-plus-seconds case and lacks explicit meaningful parametrization IDs.

$ cat codex-cli/gpt-5.6-sol.test-writing.r1.response
```python
import pytest

from your_module import parse_duration


@pytest.mark.parametrize(
    ("duration", "expected_seconds"),
    [
        ("1h", 3600),
        ("30m", 1800),
        ("45s", 45),
        ("1h30m", 5400),
        ("2h15m30s", 8130),
        ("0h", 0),
        ("0m", 0),
        ("0s", 0),
        ("24h60m60s", 90060),
        ("001h002m003s", 3723),
        ("  1h30m  ", 5400),
        ("\t45s\n", 45),
    ],
)
def test_parse_duration_returns_total_seconds(duration, expected_seconds):
    assert parse_duration(duration) == expected_seconds


@pytest.mark.parametrize(
    "invalid_duration",
    [
        "",
        "   ",
        "1",
        "1d",
        "1H",
        "30M",
        "45S",
        "1h 30m",
        "30m1h",
        "1h30m45s extra",
        "-1h",
        "+30m",
        "1.5h",
        "hm",
        "abc",
    ],
)
def test_parse_duration_rejects_unrecognized_input(invalid_duration):
    with pytest.raises(ValueError, match=r"^Invalid duration:"):
        parse_duration(invalid_duration)
```