Files
EscapistsReintroduced/tests/test_time_policy.py
T
jakub cab998fb64 Combine Workshop addon and fix prison startup
Merge owned systems into one addon while preserving resource identities. Gate player admission on the replicated prison scene, restore the original framed door, and hold enemy AI until escape. Correct scenario branding and author metadata, include publishing assets, and retain regression and native verification evidence.
2026-09-20 16:42:52 +02:00

51 lines
2.6 KiB
Python

"""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/00_Core/ERR_AdminService.c'
service = ROOT/'addons/core/Scripts/Game/ERR/00_Core/ERR_TimeService.c'
settings = ROOT/'addons/core/Scripts/Game/ERR/00_Core/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')