Include the current addon, terrain integrations, tools, regression tests and recorded development evidence.
51 lines
2.5 KiB
Plaintext
51 lines
2.5 KiB
Plaintext
"""Execute native refuel fixture policy/callback bodies; no engine qualification."""
|
|
from pathlib import Path
|
|
import os
|
|
from policy_harness import ROOT, body, run
|
|
P=Path(os.environ.get('ERR_NATIVE_MAINTENANCE_SOURCE', ROOT/'addons/core/Scripts/Game/ERR/40_Chat/ERR_NativeMaintenanceProbe.c'))
|
|
within=body(P,'static bool WithinDeadline(')
|
|
fuel=body(P,'static bool FuelConserved(').replace('Math.AbsFloat','std::fabs')
|
|
finish=body(P,'protected void Finish(').replace('protected ','')
|
|
run(r'''
|
|
#include <cassert>
|
|
#include <cmath>
|
|
#include <limits>
|
|
'''+within+fuel+r'''
|
|
struct Callback {int Result=0;
|
|
'''+finish+r'''
|
|
};
|
|
int main(){
|
|
assert(WithinDeadline(100,100)&&WithinDeadline(100,120100));
|
|
assert(!WithinDeadline(100,99)&&!WithinDeadline(100,120101)&&!WithinDeadline(-1,0));
|
|
float nan=std::numeric_limits<float>::quiet_NaN();
|
|
assert(!WithinDeadline(nan,100)&&!WithinDeadline(0,nan));
|
|
assert(FuelConserved(5,5,20,20,40));
|
|
assert(FuelConserved(5,4.5,20,20.5,40));
|
|
assert(FuelConserved(5,0,20,25,40));
|
|
assert(!FuelConserved(5,4.5,20,21,40)); // free gain
|
|
assert(!FuelConserved(5,4,20,20.5,40)); // unaccounted loss
|
|
assert(!FuelConserved(5,6,20,19,40)); // refill/reverse transfer
|
|
assert(!FuelConserved(5,-1,20,26,40));
|
|
assert(!FuelConserved(5,0,20,25,24));
|
|
assert(!FuelConserved(0,0,20,20,40));
|
|
assert(!FuelConserved(6,0,20,26,40));
|
|
for(int field=0;field<5;field++){
|
|
float v[]={5,4,20,21,40};v[field]=nan;
|
|
assert(!FuelConserved(v[0],v[1],v[2],v[3],v[4]));
|
|
}
|
|
Callback a;a.Finish(1);a.Finish(-1);a.Finish(1);assert(a.Result==1);
|
|
Callback b;b.Finish(-1);b.Finish(1);assert(b.Result==-1);
|
|
}
|
|
''')
|
|
s=P.read_text();select=body(P,'protected bool Select(');tick=body(P,'int Tick(')
|
|
for mutation in ('SetFuel(', 'TryMove', 'Spawn(', 'SetGadgetMode(', 'PerformAction('):
|
|
assert mutation not in select,mutation
|
|
assert s.count('TryMoveItemToStorage(')==1 and s.count('m_Tank.SetFuel(')==1
|
|
assert 'm_CanFuel.Set' not in s and 'TrySpawn' not in s
|
|
assert 'm_State = 1;' in tick[:tick.index('TryMoveItemToStorage(')]
|
|
assert 'm_Move.Result == 1' in tick and 'GetParentSlot().GetStorage() == m_Destination' in tick
|
|
assert 'Check(m_Interrupted,' in tick and 'm_Calls <= 128' in tick
|
|
assert 'if (m_Mode && m_Mode == ERR_GameMode.Get()' in body(P,'protected void CancelAction(')
|
|
assert 'errMaintenanceRefuel' in body(P,'static bool Enabled(') and 'normal-escape-route' in body(P,'static bool Enabled(')
|
|
print('PASS: actual finite conservation/deadline/callback policies; read-only selection, bounded once-only inventory submission and no can refill; native transfer not executed')
|