Files
EscapistsReintroduced/tests/test_recovery_forecast.py
T
2026-10-31 14:32:30 +01:00

39 lines
2.1 KiB
Python

from policy_harness import ROOT, body, run
p=ROOT/'addons/core/Scripts/Game/ERR/00_Core/ERR_RecoveryForecast.c'
s='\n'.join(body(p,x) for x in ('static bool KeepsRound(', 'static bool Awake(', 'static float Overlap(', 'static float Predict('))
s=s.replace('array<ref ERR_RecoveryFlow> flows','std::vector<ERR_RecoveryFlow*> flows').replace('foreach (ERR_RecoveryFlow flow : flows)', 'for (auto flow : flows)').replace('foreach (ERR_RecoveryFlow rate : flows)','for (auto rate : flows)')
s=s.replace('flow.','flow->').replace('rate.','rate->').replace('Math.Max','maxf').replace('Math.Min','minf').replace('Math.Clamp','clampf').replace('float db, dr;','float db=0, dr=0;')
run('''#include <cassert>
#include <vector>
#include <algorithm>
float maxf(float a,float b){return std::max(a,b);} float minf(float a,float b){return std::min(a,b);} float clampf(float v,float a,float b){return std::clamp(v,a,b);}
struct ERR_RecoveryFlow{float BloodRate=0,ResilienceRate=0,Delay=0,End=301;};
'''+s+'''
int main(){
assert(KeepsRound(-1,true,false));
assert(!KeepsRound(-1,false,true));
assert(KeepsRound(-2,false,true));
assert(!KeepsRound(-2,false,false));
assert(KeepsRound(300,false,false));
assert(Predict(1,1,.3,.5,{})==0);
assert(Predict(.2,0,.3,.5,{})==-1);
ERR_RecoveryFlow r;r.ResilienceRate=.002;
assert(Predict(1,0,.3,.5,{&r})>249 && Predict(1,0,.3,.5,{&r})<252);
r.End=100;assert(Predict(1,0,.3,.5,{&r})==-1);
r.End=301;r.Delay=60;assert(Predict(1,0,.3,.5,{&r})==-1);
r.Delay=0;r.ResilienceRate=.001;assert(Predict(1,0,.3,.5,{&r})==-1);
r.ResilienceRate=.002;
ERR_RecoveryFlow b;b.BloodRate=.001;
assert(Predict(0,0,.4,.5,{&b,&r})==-1);
b.BloodRate=.004;assert(Predict(0,0,.4,.5,{&b,&r})>=250);
ERR_RecoveryFlow bleed;bleed.BloodRate=-.005;
assert(Predict(.2,0,.4,.5,{&b,&r,&bleed})==-1);
assert(Overlap(0,1,.5,.75)==.25);
// Use exactly representable fractions for the inclusive 300-second horizon.
r.ResilienceRate=1.0/512;r.Delay=44;
assert(Predict(1,0,.3,255.0/512,{&r})==300);
r.Delay=45;assert(Predict(1,0,.3,255.0/512,{&r})==-1);
}
''')
print('PASS: real forecast code: joint thresholds, five-minute boundary, delays, medicine expiry and bleeding')