You are simulating fresh Claude API calls. The SYSTEM PROMPT below is the ONLY instruction Claude would have for each call — no Claude Code wrapper, no other context. Respond EXACTLY as Claude would respond to each user message under that system prompt.

## Critical rules

- No meta-commentary, no preamble, no acknowledgement of the simulation
- Each ITEM is an INDEPENDENT API call — Claude has NO memory of previous items
- You must NOT let your response on item N be influenced by items 1..N-1
- Just produce what Claude would output if that ITEM were the only user message

## SYSTEM PROMPT (the ONLY instruction Claude has)

You are a senior engineer writing pytest tests.

If the function is so trivial that one assertion fully covers it (e.g., `def add(a, b): return a + b`), write a single parametrized test instead of multiple cases.

<output_format>
```python
<test code only — pytest imports + test functions, parametrize where it reduces duplication>
```
</output_format>

- One assert per logical concept.
- No setUp/tearDown boilerplate.
- Cover: happy path + edge cases + documented errors. No fabricated edge cases.
- Use `pytest.raises` for exceptions.
- Use `@pytest.mark.parametrize` when the same logic applies to multiple inputs.

## ITEMS — 8 independent calls


### ITEM: tw1_factorial
```
Write pytest tests for:
  def factorial(n: int) -> int:
      if n < 0:
          raise ValueError('n must be non-negative')
      result = 1
      for i in range(2, n + 1):
          result *= i
      return result
```

### ITEM: tw2_clamp
```
Write pytest tests for:
  def clamp(value: float, lo: float, hi: float) -> float:
      if lo > hi:
          raise ValueError('lo must not exceed hi')
      return max(lo, min(value, hi))
```

### ITEM: tw3_word_count
```
Write pytest tests for:
  def word_count(text: str) -> dict:
      from collections import Counter
      return dict(Counter(text.lower().split()))
```

### ITEM: tw4_trivial_one_assert
```
Write pytest tests for:
  def double(x: int) -> int:
      return x * 2
```

### ITEM: tw5_validate_email
```
Write pytest tests for:
  import re
  _RE = re.compile(r'^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$')
  def is_valid_email(s: str) -> bool:
      return bool(_RE.match(s))
```

### ITEM: tw6_remove_negatives
```
Write pytest tests for:
  def remove_negatives(d: dict) -> dict:
      return {k: v for k, v in d.items() if v >= 0}
```

### ITEM: tw7_async_fetch
```
Write pytest tests for:
  import httpx
  async def fetch_user(user_id: int, client: httpx.AsyncClient) -> dict:
      response = await client.get(f'/users/{user_id}')
      response.raise_for_status()
      return response.json()
```

### ITEM: tw8_sort_stable
```
Write pytest tests for:
  def sort_by_priority(items: list[tuple[int, str]]) -> list[tuple[int, str]]:
      return sorted(items, key=lambda x: x[0])
```


## OUTPUT FORMAT

For each item, output exactly:

{ITEM_ID}_BEGIN
<the response Claude would produce for this item under the system prompt>
{ITEM_ID}_END

Output all 8 items in order. NO content outside the BEGIN/END markers.
