MCPcopy Create free account
hub / github.com/Tong89/smartNode / TestGetDynamicValueBasic

Class TestGetDynamicValueBasic

tests/test_content_value.py:37–70  ·  view source on GitHub ↗

get_dynamic_value 基础契约。

Source from the content-addressed store, hash-verified

35# --------------------------------------------------------------------------- #
36
37class TestGetDynamicValueBasic:
38 """get_dynamic_value 基础契约。"""
39
40 def test_at_creation_time_equals_base_value(self):
41 """t=creation_time 时,价值等于 base_value(dt=0,exp(0)=1)。"""
42 task = _make_task("SAR", creation_time=100.0)
43 v = task.get_dynamic_value(100.0)
44 assert v == pytest.approx(task.base_value, rel=1e-9)
45
46 def test_value_decreases_over_time(self):
47 """价值随时间推进单调下降。"""
48 task = _make_task("OPTICAL", creation_time=0.0)
49 v0 = task.get_dynamic_value(0.0)
50 v1 = task.get_dynamic_value(10.0)
51 v2 = task.get_dynamic_value(100.0)
52 assert v0 > v1 > v2
53
54 def test_value_never_negative(self):
55 """任意时刻价值不为负(指数函数恒正)。
56
57 注:使用低衰减率 IOT 类型(beta=0.001),避免浮点下溢导致 exp() 为 0.0。
58 """
59 task = _make_task("IOT", creation_time=0.0)
60 for dt in [0, 1, 10, 100, 1000, 5000]:
61 v = task.get_dynamic_value(dt)
62 assert v > 0, f"t={dt} 时价值应为正,实际 v={v}"
63
64 def test_value_always_le_base_value(self):
65 """任意时刻价值不超过初始价值(衰减不增长)。"""
66 task = _make_task("IOT", creation_time=50.0)
67 base = task.base_value
68 for t in [50.0, 60.0, 100.0, 500.0]:
69 v = task.get_dynamic_value(t)
70 assert v <= base + 1e-12, f"t={t} 时价值 {v} 超过 base_value {base}"
71
72
73# --------------------------------------------------------------------------- #

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected