Spaces:
Sleeping
Sleeping
| import pytest | |
| from server.generators.code_gen import generate | |
| def test_returns_valid_tuple(difficulty): | |
| question, answer = generate(difficulty, seed=42) | |
| assert isinstance(question, str) and question | |
| assert isinstance(answer, str) and answer | |
| assert "Given this Python function:" in question | |
| assert "what does f(" in question | |
| def test_seeded_is_reproducible(difficulty): | |
| first = generate(difficulty, seed=123) | |
| second = generate(difficulty, seed=123) | |
| assert first == second | |
| def test_different_seeds_vary(difficulty): | |
| outputs = {generate(difficulty, seed=s) for s in range(15)} | |
| assert len(outputs) > 1, "seeded generation across different seeds should vary" | |
| def test_unseeded_varies(): | |
| outputs = {generate(3) for _ in range(30)} | |
| assert len(outputs) > 1, "unseeded generation should vary across calls" | |
| def test_invalid_difficulty_raises(): | |
| with pytest.raises(ValueError): | |
| generate(0) | |
| with pytest.raises(ValueError): | |
| generate(6) | |