From 735936efc55c1749f673212379ddcd08d6f6419c Mon Sep 17 00:00:00 2001 From: bol-van Date: Thu, 1 Jan 2026 14:26:23 +0300 Subject: [PATCH] zapret-tests: test_swap --- lua/zapret-tests.lua | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/lua/zapret-tests.lua b/lua/zapret-tests.lua index e1028f9..ddf3a98 100644 --- a/lua/zapret-tests.lua +++ b/lua/zapret-tests.lua @@ -304,6 +304,39 @@ function test_bit() end end +function test_swap() + local v1, v2, v3 + + v1 = math.random(0,0xFFFF) + v2 = swap16(v1) + v3 = divint(v1,0x100) + v1%0x100*0x100 + print("swap16: "..(v2==v3 and "OK" or "FAIL")) + test_assert(v2==v3) + + v1 = math.random(0,0xFFFFFF) + v2 = swap24(v1) + v3 = divint(v1,0x10000) + divint(v1,0x100)%0x100*0x100 + v1%0x100*0x10000 + print("swap24: "..(v2==v3 and "OK" or "FAIL")) + test_assert(v2==v3) + + v1 = math.random(0,0xFFFFFFFF) + v2 = swap32(v1) + v3 = divint(v1,0x1000000) + divint(v1,0x10000)%0x100*0x100 + divint(v1,0x100)%0x100*0x10000 + v1%0x100*0x1000000 + print("swap32: "..(v2==v3 and "OK" or "FAIL")) + test_assert(v2==v3) + + v1 = math.random(0,0xFFFFFFFFFFFF) + v2 = swap48(v1) + v3 = divint(v1,0x10000000000) + + divint(v1,0x100000000)%0x100*0x100 + + divint(v1,0x1000000)%0x100*0x10000 + + divint(v1,0x10000)%0x100*0x1000000 + + divint(v1,0x100)%0x100*0x100000000 + + v1%0x100*0x10000000000 + print("swap48: "..(v2==v3 and "OK" or "FAIL")) + test_assert(v2==v3) +end + function test_ux() local v1, v2, v3, usum, sum for k,test in pairs({ @@ -330,7 +363,7 @@ function test_ux() end function test_bin(...) - test_run({test_ub, test_bit, test_ux},...) + test_run({test_ub, test_bit, test_swap, test_ux},...) end