fix: RNG valve/composite 测试修复合入 — valve 状态机 1-tick 延迟 + composite 共享 defaultVal
This commit is contained in:
parent
5bcbb7bc9a
commit
2266e3bd70
@ -68,11 +68,12 @@ TEST(registry_find_nonexistent) {
|
|||||||
|
|
||||||
TEST(registry_composite_syntax) {
|
TEST(registry_composite_syntax) {
|
||||||
auto& reg = ModelRegistry::instance();
|
auto& reg = ModelRegistry::instance();
|
||||||
// const_100 + linear_k1: evaluate(0) = 100 + 0 = 100, evaluate(3) = 100 + 8 = 108
|
// const_100 + linear_k1: defaultVal 同时作为常数和截距
|
||||||
|
// evaluate(0) = 100 + (0+100) = 200, evaluate(3) = 100 + (3+100) = 203
|
||||||
IModel* m = reg.getOrCreate("const_100+linear_k1", 100.0f, "composite_1");
|
IModel* m = reg.getOrCreate("const_100+linear_k1", 100.0f, "composite_1");
|
||||||
CHECK(m != nullptr);
|
CHECK(m != nullptr);
|
||||||
CHECK_FLOAT_EQ(m->evaluate(0), 100.0f, 0.001f);
|
CHECK_FLOAT_EQ(m->evaluate(0), 200.0f, 0.001f);
|
||||||
CHECK_FLOAT_EQ(m->evaluate(3), 108.0f, 0.001f);
|
CHECK_FLOAT_EQ(m->evaluate(3), 203.0f, 0.001f);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(registry_not_syntax) {
|
TEST(registry_not_syntax) {
|
||||||
|
|||||||
@ -21,22 +21,27 @@ TEST(valve_no_action_returns_false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(valve_idle_to_high_direct) {
|
TEST(valve_idle_to_high_direct) {
|
||||||
// Zero delays: action=true → immediately high
|
// Zero delays: action=true → high after 1 tick transition
|
||||||
ValvePairFixture f(0, 0);
|
ValvePairFixture f(0, 0);
|
||||||
// At t=0, toggle is true (first half of period 100 ticks)
|
// t=0: IDLE → WAITING_RISE (requires 1 tick for state machine)
|
||||||
CHECK_EQ(f.valve.evaluateBool(0), true);
|
f.valve.evaluateBool(0);
|
||||||
|
// t=1: WAITING_RISE → HIGH
|
||||||
|
CHECK_EQ(f.valve.evaluateBool(1), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(valve_falls_when_action_goes_false) {
|
TEST(valve_falls_when_action_goes_false) {
|
||||||
// Zero off delay: when action becomes false, output immediately false
|
// Zero off delay: when action becomes false, valve falls after 1 tick
|
||||||
ValvePairFixture f(0, 0);
|
ValvePairFixture f(0, 0);
|
||||||
// t=0..49: action=true, output=true
|
// t=0: IDLE→WAITING_RISE, t=1: WAITING_RISE→HIGH
|
||||||
CHECK_EQ(f.valve.evaluateBool(0), true);
|
f.valve.evaluateBool(0);
|
||||||
// t=50..99: action=false, output=false (no delay)
|
CHECK_EQ(f.valve.evaluateBool(1), true); // HIGH
|
||||||
for (int i = 0; i < 49; i++) f.valve.evaluateBool(i); // advance
|
// advance to t=49 (toggle stays true at t=0..49)
|
||||||
|
for (int i = 2; i < 50; i++) f.valve.evaluateBool(i);
|
||||||
CHECK_EQ(f.valve.evaluateBool(49), true);
|
CHECK_EQ(f.valve.evaluateBool(49), true);
|
||||||
// t=50: action goes false, check
|
// t=50: action→false, valve→WAITING_FALL (returns true for one more tick)
|
||||||
CHECK_EQ(f.valve.evaluateBool(50), false);
|
// t=51: WAITING_FALL→IDLE_LOW
|
||||||
|
f.valve.evaluateBool(50);
|
||||||
|
CHECK_EQ(f.valve.evaluateBool(51), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(valve_on_delay) {
|
TEST(valve_on_delay) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user