"""pytest 公共夹具。""" from __future__ import annotations import numpy as np import pytest @pytest.fixture def rng(): """固定种子的随机数生成器——所有含随机的测试都必须用它,保证可复现。""" return np.random.default_rng(20260101) @pytest.fixture def linear_data(rng): """带噪声的线性数据,用于回归类测试(真值 y = 2x + 1)。""" x = rng.uniform(-5, 5, size=200) y = 2.0 * x + 1.0 + rng.normal(0, 0.1, size=200) return x, y @pytest.fixture def decision_matrix(): """3 个方案 × 4 个指标的决策矩阵,用于评价类测试。""" return np.array( [ [9.0, 0.3, 120.0, 8.5], [7.5, 0.5, 90.0, 9.0], [8.8, 0.2, 150.0, 7.0], ] )