You are working in a small Python project in the current directory. Implement a new function `moving_average(values, window)` in `stats.py`.

The exact expected behavior — including the normal case, edge cases, and required error handling — is fully specified by the tests in `test_stats.py`, which currently fail because `moving_average` does not exist yet.

Follow a test-driven approach: read `test_stats.py` first to understand the contract, then implement `moving_average` so that ALL tests in `test_stats.py` pass when run with `pytest`. Run `pytest` yourself to verify. Do NOT modify the test file.
