与公式 base_value * exp(-beta * dt) 精确对齐。
| 75 | # --------------------------------------------------------------------------- # |
| 76 | |
| 77 | class TestGetDynamicValueNumerics: |
| 78 | """与公式 base_value * exp(-beta * dt) 精确对齐。""" |
| 79 | |
| 80 | def test_exact_decay_sar(self): |
| 81 | """SAR 类型:beta=0.15,base_value=100.0;dt=5 时精确验证。""" |
| 82 | task = _make_task("SAR", creation_time=0.0) |
| 83 | dt = 5.0 |
| 84 | expected = task.base_value * math.exp(-task.beta * dt) |
| 85 | v = task.get_dynamic_value(dt) |
| 86 | assert v == pytest.approx(expected, rel=1e-9) |
| 87 | |
| 88 | def test_exact_decay_optical(self): |
| 89 | """OPTICAL 类型:beta=0.05,base_value=80.0;dt=20 时精确验证。""" |
| 90 | task = _make_task("OPTICAL", creation_time=0.0) |
| 91 | dt = 20.0 |
| 92 | expected = task.base_value * math.exp(-task.beta * dt) |
| 93 | v = task.get_dynamic_value(dt) |
| 94 | assert v == pytest.approx(expected, rel=1e-9) |
| 95 | |
| 96 | def test_exact_decay_control(self): |
| 97 | """CONTROL 类型:beta=0.5,base_value=150.0;dt=2 时精确验证。""" |
| 98 | task = _make_task("CONTROL", creation_time=0.0) |
| 99 | dt = 2.0 |
| 100 | expected = task.base_value * math.exp(-task.beta * dt) |
| 101 | v = task.get_dynamic_value(dt) |
| 102 | assert v == pytest.approx(expected, rel=1e-9) |
| 103 | |
| 104 | def test_exact_decay_iot(self): |
| 105 | """IOT 类型:beta=0.001,base_value=40.0;dt=1000 时精确验证。""" |
| 106 | task = _make_task("IOT", creation_time=0.0) |
| 107 | dt = 1000.0 |
| 108 | expected = task.base_value * math.exp(-task.beta * dt) |
| 109 | v = task.get_dynamic_value(dt) |
| 110 | assert v == pytest.approx(expected, rel=1e-9) |
| 111 | |
| 112 | def test_half_life_sar(self): |
| 113 | """SAR 半衰期 t_half = ln(2)/beta:此时价值应为 base_value/2。""" |
| 114 | task = _make_task("SAR", creation_time=0.0) |
| 115 | t_half = math.log(2) / task.beta |
| 116 | v = task.get_dynamic_value(t_half) |
| 117 | assert v == pytest.approx(task.base_value / 2.0, rel=1e-6) |
| 118 | |
| 119 | def test_half_life_optical(self): |
| 120 | """OPTICAL 半衰期验证。""" |
| 121 | task = _make_task("OPTICAL", creation_time=0.0) |
| 122 | t_half = math.log(2) / task.beta |
| 123 | v = task.get_dynamic_value(t_half) |
| 124 | assert v == pytest.approx(task.base_value / 2.0, rel=1e-6) |
| 125 | |
| 126 | def test_double_time_squared_decay(self): |
| 127 | """两倍时间时,价值为初始值的 exp(-2*beta*T_1) = v1^2 / base_value。""" |
| 128 | task = _make_task("SAR", creation_time=0.0) |
| 129 | dt1, dt2 = 5.0, 10.0 |
| 130 | v1 = task.get_dynamic_value(dt1) |
| 131 | v2 = task.get_dynamic_value(dt2) |
| 132 | # exp(-beta*2*T) = (exp(-beta*T))^2 |
| 133 | assert v2 == pytest.approx(v1 ** 2 / task.base_value, rel=1e-9) |
| 134 |
nothing calls this directly
no outgoing calls
no test coverage detected