tw1_factorial_BEGIN
```python
import pytest
from mymodule import factorial


def test_factorial_zero():
    assert factorial(0) == 1


def test_factorial_one():
    assert factorial(1) == 1


def test_factorial_small_positive():
    assert factorial(5) == 120


def test_factorial_larger():
    assert factorial(10) == 3628800


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


@pytest.mark.parametrize("n,expected", [(0, 1), (1, 1), (2, 2), (3, 6), (6, 720), (7, 5040)])
def test_factorial_parametrized(n, expected):
    assert factorial(n) == expected
```
tw1_factorial_END

tw2_clamp_BEGIN
```python
import math
import pytest
from mymodule import clamp


def test_clamp_value_within_range():
    assert clamp(5.0, 0.0, 10.0) == 5.0


def test_clamp_value_below_lo():
    assert clamp(-5.0, 0.0, 10.0) == 0.0


def test_clamp_value_above_hi():
    assert clamp(15.0, 0.0, 10.0) == 10.0


def test_clamp_lo_equals_hi():
    assert clamp(5.0, 3.0, 3.0) == 3.0


def test_clamp_lo_greater_than_hi_raises():
    with pytest.raises(ValueError, match='lo must not exceed hi'):
        clamp(5.0, 10.0, 0.0)


def test_clamp_infinity():
    assert clamp(math.inf, 0.0, 100.0) == 100.0
    assert clamp(-math.inf, 0.0, 100.0) == 0.0


@pytest.mark.parametrize("value,lo,hi,expected", [
    (5.0, 0.0, 10.0, 5.0), (-1.0, 0.0, 10.0, 0.0), (11.0, 0.0, 10.0, 10.0),
])
def test_clamp_parametrized(value, lo, hi, expected):
    assert clamp(value, lo, hi) == expected
```
tw2_clamp_END

tw3_word_count_BEGIN
```python
import pytest
from mymodule import word_count


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


def test_word_count_single_word():
    assert word_count("hello") == {"hello": 1}


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


def test_word_count_repeated_words():
    assert word_count("hello hello world") == {"hello": 2, "world": 1}


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


def test_word_count_extra_whitespace():
    assert word_count("  hello   world  ") == {"hello": 1, "world": 1}


def test_word_count_tabs_and_newlines():
    assert word_count("hello\tworld\nfoo") == {"hello": 1, "world": 1, "foo": 1}
```
tw3_word_count_END

tw4_trivial_one_assert_BEGIN
```python
import pytest
from mymodule import double


def test_double_positive():
    assert double(3) == 6


def test_double_zero():
    assert double(0) == 0


def test_double_negative():
    assert double(-4) == -8


@pytest.mark.parametrize("x,expected", [(1, 2), (0, 0), (-1, -2), (100, 200)])
def test_double_parametrized(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@example.com",
])
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",
])
def test_invalid_emails(email):
    assert is_valid_email(email) is False


def test_returns_bool():
    assert isinstance(is_valid_email("a@b.co"), bool)
```
tw5_validate_email_END

tw6_remove_negatives_BEGIN
```python
import pytest
from mymodule import remove_negatives


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


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


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


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


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


def test_remove_negatives_does_not_mutate_input():
    d = {"a": 1, "b": -1}
    original = dict(d)
    remove_negatives(d)
    assert d == original
```
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_success():
    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_404_raises():
    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(999, client)


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

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

tw8_sort_stable_BEGIN
```python
import pytest
from mymodule import sort_by_priority


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


def test_sort_single_item():
    assert sort_by_priority([(1, "a")]) == [(1, "a")]


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


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


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


def test_sort_does_not_mutate_input():
    items = [(3, "c"), (1, "a"), (2, "b")]
    original = list(items)
    sort_by_priority(items)
    assert items == original
```
tw8_sort_stable_END
