tw1_factorial_BEGIN
```python
import pytest
from mymodule import factorial


@pytest.mark.parametrize("n,expected", [
    (0, 1),
    (1, 1),
    (2, 2),
    (5, 120),
    (10, 3628800),
])
def test_factorial_returns_expected(n, expected):
    assert factorial(n) == expected


def test_factorial_negative_raises():
    with pytest.raises(ValueError, match="n must be non-negative"):
        factorial(-1)
```
tw1_factorial_END

tw2_clamp_BEGIN
```python
import pytest
from mymodule import clamp


@pytest.mark.parametrize("value,lo,hi,expected", [
    (5, 0, 10, 5),
    (-1, 0, 10, 0),
    (11, 0, 10, 10),
    (0, 0, 10, 0),
    (10, 0, 10, 10),
    (3.5, 1.0, 5.0, 3.5),
])
def test_clamp_returns_expected(value, lo, hi, expected):
    assert clamp(value, lo, hi) == expected


def test_clamp_invalid_bounds_raises():
    with pytest.raises(ValueError, match="lo must not exceed hi"):
        clamp(5, 10, 0)
```
tw2_clamp_END

tw3_word_count_BEGIN
```python
import pytest
from mymodule import word_count


def test_word_count_basic():
    assert word_count("the quick brown fox") == {"the": 1, "quick": 1, "brown": 1, "fox": 1}


def test_word_count_repeated_words():
    assert word_count("the cat and the dog and the bird") == {"the": 3, "cat": 1, "and": 2, "dog": 1, "bird": 1}


def test_word_count_case_insensitive():
    assert word_count("Hello HELLO hello") == {"hello": 3}


def test_word_count_empty_string():
    assert word_count("") == {}


def test_word_count_collapses_whitespace():
    assert word_count("a   b\tc\nd") == {"a": 1, "b": 1, "c": 1, "d": 1}
```
tw3_word_count_END

tw4_trivial_one_assert_BEGIN
```python
import pytest
from mymodule import double


@pytest.mark.parametrize("x,expected", [
    (0, 0),
    (1, 2),
    (-3, -6),
    (1000, 2000),
])
def test_double(x, expected):
    assert double(x) == expected
```
tw4_trivial_one_assert_END

tw5_validate_email_BEGIN
```python
import pytest
from mymodule import is_valid_email


@pytest.mark.parametrize("email", [
    "user@example.com",
    "first.last@example.com",
    "user+tag@example.co.uk",
    "user_name@sub.example.com",
    "a1b2@x-y.io",
])
def test_valid_emails(email):
    assert is_valid_email(email) is True


@pytest.mark.parametrize("email", [
    "",
    "plainaddress",
    "@example.com",
    "user@",
    "user@example",
    "user@.com",
    "user@example.c",
    "user name@example.com",
])
def test_invalid_emails(email):
    assert is_valid_email(email) is False
```
tw5_validate_email_END

tw6_remove_negatives_BEGIN
```python
import pytest
from mymodule import remove_negatives


def test_remove_negatives_filters_negative_values():
    assert remove_negatives({"a": 1, "b": -2, "c": 3, "d": -4}) == {"a": 1, "c": 3}


def test_remove_negatives_keeps_zero():
    assert remove_negatives({"a": 0, "b": -1, "c": 5}) == {"a": 0, "c": 5}


def test_remove_negatives_empty_dict():
    assert remove_negatives({}) == {}


def test_remove_negatives_all_negative():
    assert remove_negatives({"a": -1, "b": -2}) == {}


def test_remove_negatives_all_non_negative():
    d = {"a": 1, "b": 2, "c": 0}
    assert remove_negatives(d) == d
```
tw6_remove_negatives_END

tw7_async_fetch_BEGIN
```python
import pytest
import httpx
from mymodule import fetch_user


@pytest.mark.asyncio
async def test_fetch_user_returns_json():
    def handler(request: httpx.Request) -> httpx.Response:
        assert request.url.path == "/users/42"
        return httpx.Response(200, json={"id": 42, "name": "Alice"})

    transport = httpx.MockTransport(handler)
    async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
        result = await fetch_user(42, client)
    assert result == {"id": 42, "name": "Alice"}


@pytest.mark.asyncio
async def test_fetch_user_raises_on_http_error():
    def handler(request: httpx.Request) -> httpx.Response:
        return httpx.Response(404)

    transport = httpx.MockTransport(handler)
    async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
        with pytest.raises(httpx.HTTPStatusError):
            await fetch_user(99, client)
```
tw7_async_fetch_END

tw8_sort_stable_BEGIN
```python
import pytest
from mymodule import sort_by_priority


def test_sort_by_priority_orders_by_first_element():
    assert sort_by_priority([(3, "c"), (1, "a"), (2, "b")]) == [(1, "a"), (2, "b"), (3, "c")]


def test_sort_by_priority_is_stable_for_equal_keys():
    items = [(1, "first"), (1, "second"), (1, "third")]
    assert sort_by_priority(items) == [(1, "first"), (1, "second"), (1, "third")]


def test_sort_by_priority_stable_mixed():
    items = [(2, "a"), (1, "b"), (2, "c"), (1, "d")]
    assert sort_by_priority(items) == [(1, "b"), (1, "d"), (2, "a"), (2, "c")]


def test_sort_by_priority_empty_list():
    assert sort_by_priority([]) == []


def test_sort_by_priority_single_element():
    assert sort_by_priority([(5, "x")]) == [(5, "x")]
```
tw8_sort_stable_END
