Files
mcm-26-b/referee/tests/test_scenes.py
2026-09-11 11:36:08 +08:00

37 lines
1.2 KiB
Python

"""场景生成:源数量、频道、位置与接收半径满足题面范围。"""
import math
from referee import DEFAULT_SPEC, mixed_scene, random_omni_scene
def test_random_omni_scene_within_spec():
for seed in range(5):
sources = random_omni_scene(seed=seed)
assert 10 <= len(sources) <= 16 # 源总数范围 [题面]
channels = [s.channel for s in sources]
assert len(set(channels)) == len(channels) # 每频道至多一个源
assert all(1 <= c <= 20 for c in channels)
for s in sources:
assert math.hypot(s.x, s.y) <= DEFAULT_SPEC.field.omega_radius_m
assert 1000 <= s.r_eff_m <= 1500
assert not s.directional
def test_scene_is_reproducible_by_seed():
a = random_omni_scene(seed=123, count=12)
b = random_omni_scene(seed=123, count=12)
assert a == b
def test_mixed_scene_directional_count():
sources = mixed_scene(seed=7, count=12, directional=4)
assert sum(1 for s in sources if s.directional) == 4
assert all(0 <= s.heading_deg < 360 for s in sources if s.directional)
def test_count_is_validated():
import pytest
with pytest.raises(ValueError):
random_omni_scene(seed=1, count=0)