42 lines
2.6 KiB
Python
42 lines
2.6 KiB
Python
from policy_harness import ROOT, body, run
|
|
import re
|
|
path = ROOT/'addons/core/Scripts/Game/ERR/ERR_CasualtyLoadingService.c'
|
|
source = '\n'.join(body(path, signature) for signature in [
|
|
'static int RoundAction(', 'static bool ObserveTicket(', 'static bool Within(', 'static bool SettledFor(', 'static bool Ranges(', 'static bool AircraftMotion('])
|
|
# Enforce float literals are single precision; C++ otherwise promotes these to doubles.
|
|
source = re.sub(r'(?<![\w.])(\d+\.\d+)(?![\w.])', r'\1f', source)
|
|
source = source.replace('ERR_Phase.PREPARING', '0').replace('ERR_MissionRules.Terminal(phase)', '(phase == 5 || phase == 6)')
|
|
run('#include <cassert>\n' + source + '''
|
|
int main() {
|
|
assert(RoundAction(0)==0); // pre-start roster callbacks must not latch Stop
|
|
for (int phase=1;phase<=4;phase++) assert(RoundAction(phase)==1);
|
|
assert(RoundAction(5)==2); assert(RoundAction(6)==2);
|
|
for (int flags=0;flags<8;flags++) {
|
|
bool committed=flags&1, physical=flags&2, authorized=flags&4;
|
|
bool keep=physical && (committed || authorized);
|
|
assert(ObserveTicket(committed,physical,authorized)==keep);
|
|
}
|
|
assert(ObserveTicket(true,true,false)); // disconnect after irreversible commit retains seat
|
|
assert(!ObserveTicket(false,true,false)); // before commit it cancels
|
|
// A late/reordered/expired lease cannot authorize a native entry.
|
|
assert(Within(1000,1000,3000)); assert(Within(1000,3999,3000));
|
|
assert(!Within(1000,4000,3000)); assert(!Within(1000,999,3000));
|
|
assert(!Within(2147483000,-2147483000,3000));
|
|
// A continuous observation window needs both sufficient settling and fresh data.
|
|
assert(!SettledFor(-1,5000,5000)); assert(!SettledFor(1000,5999,5999));
|
|
assert(SettledFor(1000,6000,6000)); assert(SettledFor(1000,6000,7999));
|
|
assert(!SettledFor(1000,6000,8000)); assert(!SettledFor(1000,6000,5999));
|
|
assert(!SettledFor(6000,6000,6000)); // recovered/moving body starts a new window
|
|
// Every participant must independently be inside the physical rescue range.
|
|
assert(Ranges(3,12,12)); assert(!Ranges(3.01,12,12));
|
|
assert(!Ranges(3,12.01,12)); assert(!Ranges(3,12,12.01));
|
|
assert(!Ranges(-1,0,0)); assert(!Ranges(0,-1,0)); assert(!Ranges(0,0,-1));
|
|
// Contact alone cannot authorize an airborne, inverted, sliding or turning craft.
|
|
assert(AircraftMotion(true,1,0,0)); assert(AircraftMotion(true,0.85,0.5,0.1));
|
|
assert(!AircraftMotion(false,1,0,0)); assert(!AircraftMotion(true,-1,0,0));
|
|
assert(!AircraftMotion(true,0.849,0,0)); assert(!AircraftMotion(true,1,0.501,0));
|
|
assert(!AircraftMotion(true,1,0,0.101));
|
|
}
|
|
''')
|
|
print('PASS: rescue lease expiry/reordering, fresh five-second settling, independent rescue ranges and grounded upright aircraft motion boundaries')
|