Add independent extraction results and configurable mission clock
This commit is contained in:
@@ -4,11 +4,11 @@ from policy_harness import ROOT,body,run
|
||||
spec=importlib.util.spec_from_file_location('import_settings',ROOT/'tools/import_settings.py')
|
||||
m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m)
|
||||
result,deferred=m.merge({'configVersion':1,'reportIntervalSeconds':20.0,'supportSquadLimit':2,'responseRadiusMetres':1500,'convoyCount':3},{'aiIntelChancePercent':0,'intelRevealChancePercent':100})
|
||||
assert result==dict(reportIntervalSeconds=20,supportSquadLimit=2,responseRadiusMetres=1500,aiIntelChancePercent=0,intelRevealChancePercent=100,radioDefenceSeconds=180)
|
||||
assert result==dict(reportIntervalSeconds=20,supportSquadLimit=2,responseRadiusMetres=1500,aiIntelChancePercent=0,intelRevealChancePercent=100,radioDefenceSeconds=180,startTimeMinutes=840,timeMultiplier=1)
|
||||
assert deferred==['ai:convoyCount']
|
||||
assert m.merge()[0]=={k:v[0] for k,v in m.SCHEMA.items()}
|
||||
for key,(_,lo,hi) in m.SCHEMA.items():
|
||||
if key=='radioDefenceSeconds':continue
|
||||
if key not in m.AI_KEYS and key not in m.INTEL_KEYS:continue
|
||||
for invalid in (lo-1,hi+1,True,False,None,'10',lo+0.5,float('nan'),float('inf')):
|
||||
try:m.merge(**({'ai':{key:invalid}} if key in m.AI_KEYS else {'intel':{key:invalid}}))
|
||||
except ValueError:pass
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
"""Run actual clock parsing/formatting and progression policy bodies as C++.
|
||||
Native world authority, JSON serialization and progression need native probes.
|
||||
"""
|
||||
from policy_harness import ROOT, body, run
|
||||
admin = ROOT/'addons/core/Scripts/Game/ERR/ERR_AdminService.c'
|
||||
service = ROOT/'addons/core/Scripts/Game/ERR/ERR_TimeService.c'
|
||||
settings = ROOT/'addons/core/Scripts/Game/ERR/ERR_Settings.c'
|
||||
|
||||
def translate(source):
|
||||
return (source.replace('string ', 'std::string ').replace('out int ', 'int& ')
|
||||
.replace('text.Length()', 'int(text.size())').replace('.IsEmpty()', '.empty()')
|
||||
.replace('.Substring(', '.substr(')
|
||||
.replace('"0123456789".IndexOf(', 'std::string("0123456789").find(')
|
||||
.replace(' < 0) return false;', ' == std::string::npos) return false;')
|
||||
.replace('text.ToInt()', 'std::stoi(text)')
|
||||
.replace('hours.ToString()', 'std::to_string(hours)')
|
||||
.replace('remainder.ToString()', 'std::to_string(remainder)')
|
||||
.replace('ERR_CommandArguments.Integer', 'Integer')
|
||||
.replace('ERR_Settings.Valid', 'Valid'))
|
||||
|
||||
functions = '\n'.join(translate(body(path, signature)) for path, signature in (
|
||||
(settings, 'static bool Valid('),
|
||||
(settings, 'static int AddedDefault('),
|
||||
(admin, 'static bool Integer('),
|
||||
(service, 'static bool ParseClock('),
|
||||
(service, 'static string Clock('),
|
||||
(service, 'static float DayDuration('),
|
||||
))
|
||||
run('#include <cassert>\n#include <cmath>\n#include <string>\n' + functions + r'''
|
||||
int main() {
|
||||
for (int minute=0; minute<1440; ++minute) {
|
||||
int parsed=-1;
|
||||
assert(ParseClock(Clock(minute),parsed));
|
||||
assert(parsed==minute);
|
||||
}
|
||||
assert(Clock(0)=="00:00" && Clock(1439)=="23:59" && Clock(375)=="06:15");
|
||||
assert(Clock(-1)=="unavailable" && Clock(1440)=="unavailable");
|
||||
for (std::string input : {"", "0:00", "00:0", "24:00", "12:60", "-1:00", "1a:00", "00:0b", "06:15junk", " 06:15", "06:15 ", "06.15"}) {
|
||||
int parsed=-1; assert(!ParseClock(input,parsed));
|
||||
}
|
||||
assert(AddedDefault("startTimeMinutes")==840);
|
||||
assert(AddedDefault("timeMultiplier")==1);
|
||||
assert(AddedDefault("radioDefenceSeconds")==-1);
|
||||
assert(AddedDefault("unknown")==-1);
|
||||
for (int multiplier=1; multiplier<=24; ++multiplier)
|
||||
assert(std::abs(DayDuration(multiplier)*multiplier-86400.0)<0.01);
|
||||
assert(DayDuration(0)==-1 && DayDuration(25)==-1 && DayDuration(-1)==-1);
|
||||
}
|
||||
''')
|
||||
print('PASS: every minute round-trips, malformed clocks rejected, defaults limited to added keys, progression bounds and day duration aligned')
|
||||
Reference in New Issue
Block a user