Files
metin2-server/tests/features/test_point_drop.py
T
shenlei bb0963210e feat: support Linux/ARM cross-platform build and AVA2 feature updates
- Port server core and libraries to Linux and 32-bit ARM (armhf):
  * Replace FreeBSD kqueue with Linux epoll in libthecore fdwatch
  * Fix unaligned float and 64-bit int memory stores in utils.h str_to_number to avoid ARM VFP alignment fault (SIGBUS)
  * Fix getopt loop variable type in main.cpp (char -> int) to eliminate infinite loop caused by default unsigned char on ARM
  * Add -fsigned-char and multi-architecture flags to Makefiles (x86_64 -m32, i386, and ARM armhf)
  * Update libsql for modern MariaDB client library (removed reconnect field) and C++20 concept/syntax compatibility
  * Replace Win32 xdirent with standard POSIX dirent on Unix/Linux
  * Include xmd5 in libthecore on non-FreeBSD platforms
- AVA2 unlock features and tools:
  * Material stacking up to 2000 count, refine material resolution and test suites
  * AVA2 ticket shop and point drop configuration updates
2026-11-11 00:59:49 -08:00

53 lines
2.1 KiB
Python

"""Compile the shipping eligibility/cap arithmetic, including boundary and overflow cases."""
import json
from pathlib import Path
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[2]
class PointDrop(unittest.TestCase):
def test_approved_rules_and_cap(self):
flags = json.loads((ROOT/'tools/ava2-itemshop/points-wide.json').read_text())
entries = ','.join('{"%s",%d}' % entry for entry in flags.items())
source = r'''
#include "src/server/common/point_drop.h"
#include <map>
#include <cassert>
int main() {
std::map<std::string,int> flags={ENTRIES};
auto lookup=[&](const std::string& key){return flags[key];};
auto mob=PortPointRule(lookup,false),stone=PortPointRule(lookup,true);
assert(mob.chance==5000 && mob.minimum==3 && mob.maximum==5);
assert(stone.chance==10000 && stone.minimum==15 && stone.maximum==30);
assert(mob.dailyCap==0 && stone.dailyCap==0);
assert(mob.eligible(105,120));assert(!mob.eligible(104,120));
assert(stone.eligible(120,1));assert(!stone.eligible(0,1));
assert(!stone.eligible(120,0));
assert(PortPointDropAmount(8,498,500)==2);
assert(PortPointDropAmount(8,500,500)==0);
assert(PortPointDropAmount(8,UINT64_MAX,500)==0);
assert(PortPointDropAmount(8,UINT64_MAX,0)==8);
assert(PortPointDropAmount(30,500,stone.dailyCap)==30);
assert(PortPointDropAmount(30,1000000,stone.dailyCap)==30);
flags["points_mob_chance"]=0;assert(!PortPointRule(lookup,false).eligible(105,120));
flags["points_stone_chance"]=10001;assert(!PortPointRule(lookup,true).valid());
flags["points_stone_chance"]=10000;flags["points_stone_min"]=-1;
assert(!PortPointRule(lookup,true).valid());
flags["points_stone_min"]=9;flags["points_stone_max"]=3;
assert(!PortPointRule(lookup,true).valid());
}
'''.replace('ENTRIES', entries)
with tempfile.TemporaryDirectory() as tmp:
src = Path(tmp)/'test.cpp'
exe = Path(tmp)/'test'
src.write_text(source)
subprocess.run(['c++', '-std=c++17', '-I'+str(ROOT), str(src), '-o', str(exe)], check=True)
subprocess.run([str(exe)], check=True)
if __name__ == '__main__':
unittest.main()