Skip to content

Commit 4a0af62

Browse files
committed
bitop tests [TO SQUASH]
1 parent c8e0df9 commit 4a0af62

13 files changed

+56
-36
lines changed

tests/lapi/bitop_arshift_test.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local luzer = require("luzer")
99
local test_lib = require("lib")
1010

1111
if test_lib.lua_version() ~= "LuaJIT" then
12+
print("Unsupported version.")
1213
os.exit(0)
1314
end
1415

tests/lapi/bitop_band_test.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ local function TestOneInput(buf)
3131

3232
assert(band(x, band(y, z)) == band(band(x, y), z))
3333
assert(band(x, 0) == 0)
34-
35-
-- FIXME: assert(band(x, test_lib.MAX_INT) == x)
3634
assert(band(x, y) == band(y, x))
3735
assert(band(x, x) == x)
36+
assert(band(x, -1) == x)
3837
end
3938

4039
local args = {

tests/lapi/bitop_bnot_test.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ local function TestOneInput(buf)
2424
assert(type(res) == "number")
2525

2626
-- For any integer x, the following identity holds [1]:
27+
--
2728
-- 1. https://www.lua.org/manual/5.2/manual.html
28-
-- FIXME: assert(bnot(x) == (-1 - x) % 2^32)
29-
assert(bnot(bnot(x)) == x)
29+
if test_lib.lua_version() == "LuaJIT" then
30+
assert(bnot(x) == (-1 - x) % 2^32)
31+
else
32+
assert(bnot(x) == (-1 - x))
33+
end
3034
end
3135

3236
local args = {

tests/lapi/bitop_bor_test.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@ local function TestOneInput(buf)
3434

3535
assert(bor(x, y) == bor(y, x))
3636
assert(bor(x, bor(y, z)) == bor(bor(x, y), z))
37-
3837
assert(bor(x, 0) == x)
39-
-- FIXME: assert(bor(x, test_lib.MAX_INT) == test_lib.MAX_INT)
4038
assert(bor(x, x) == x)
39+
if test_lib.lua_version() == "LuaJIT" then
40+
local MAX_UINT = bor(test_lib.MAX_INT, test_lib.MIN_INT)
41+
assert(bor(x, MAX_UINT) == MAX_UINT)
42+
else
43+
local MAX_UINT64 = bor(test_lib.MAX_INT64, test_lib.MIN_INT64)
44+
assert(bor(x, MAX_UINT64) == MAX_UINT64)
45+
end
4146
end
4247

4348
local args = {

tests/lapi/bitop_bswap_test.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local luzer = require("luzer")
99
local test_lib = require("lib")
1010

1111
if test_lib.lua_version() ~= "LuaJIT" then
12+
print("Unsupported version.")
1213
os.exit(0)
1314
end
1415

tests/lapi/bitop_bxor_test.lua

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,21 @@ local function TestOneInput(buf)
3535
assert(bxor(x, y) == bxor(y, x))
3636
assert(bxor(x, bxor(y, z)) == bxor(bxor(x, y), z))
3737
assert(bxor(x, x) == 0)
38+
-- a ^ b = (a | b) & (~a | ~b)
39+
assert(bxor(x, y) == band(bor(x, y), bor(bnot(x), bnot(y))))
40+
-- a ^ b = (a & ~b) | (~a & b)
3841
assert(bxor(x, y) == bor(band(x, bnot(y)), band(bnot(x), y)))
39-
40-
-- FIXME: assert(bxor(x, 0xffff) == bnot(x))
41-
-- FIXME: assert(bxor(x, 0) == 0)
42+
assert(bxor(x, y, y) == x)
4243
assert(bxor(bxor(x, y), y) == x)
43-
assert(bxor(x, y) == band(bor(x, y), bor(bnot(x), bnot(y))))
44+
45+
if test_lib.lua_version() == "LuaJIT" then
46+
local MAX_UINT = bor(test_lib.MAX_INT, test_lib.MIN_INT)
47+
assert(bxor(x, MAX_UINT) == bnot(x))
48+
else
49+
local MAX_UINT64 = bor(test_lib.MAX_INT64, test_lib.MIN_INT64)
50+
assert(bxor(x, MAX_UINT64) == bnot(x))
51+
end
52+
assert(bxor(x, 0) == x)
4453
end
4554

4655
local args = {

tests/lapi/bitop_lshift_test.lua

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,10 @@ end
2121
local function TestOneInput(buf)
2222
local fdp = luzer.FuzzedDataProvider(buf)
2323
local MAX_INT = test_lib.MAX_INT
24-
local MIN_INT = test_lib.MIN_INT
25-
local x = fdp:consume_integer(MIN_INT, MAX_INT)
26-
local n = fdp:consume_integer(MIN_INT, MAX_INT)
24+
local x = fdp:consume_integer(0, MAX_INT)
25+
local n = fdp:consume_integer(1, 32)
2726
local res = lshift(x, n)
2827
assert(type(res) == "number")
29-
30-
-- For positive displacements, the following equality holds [1]:
31-
--
32-
-- 1. https://www.lua.org/manual/5.2/manual.html
33-
-- FIXME: assert(lshift(x, n) == (x * 2^n) % 2^32)
3428
end
3529

3630
local args = {

tests/lapi/bitop_rol_test.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ local luzer = require("luzer")
1212
local test_lib = require("lib")
1313

1414
if test_lib.lua_version() ~= "LuaJIT" then
15+
print("Unsupported version.")
1516
os.exit(0)
1617
end
1718

tests/lapi/bitop_ror_test.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local luzer = require("luzer")
99
local test_lib = require("lib")
1010

1111
if test_lib.lua_version() ~= "LuaJIT" then
12+
print("Unsupported version.")
1213
os.exit(0)
1314
end
1415

tests/lapi/bitop_rshift_test.lua

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,10 @@ end
2424
local function TestOneInput(buf)
2525
local fdp = luzer.FuzzedDataProvider(buf)
2626
local MAX_INT = test_lib.MAX_INT
27-
local MIN_INT = test_lib.MIN_INT
28-
local x = fdp:consume_integer(MIN_INT, MAX_INT)
29-
local n = fdp:consume_integer(MIN_INT, MAX_INT)
27+
local x = fdp:consume_integer(0, MAX_INT)
28+
local n = fdp:consume_integer(1, 32)
3029
local res = rshift(x, n)
3130
assert(type(res) == "number")
32-
33-
-- For positive displacements, the following equality holds
34-
-- [1]:
35-
--
36-
-- 1. https://www.lua.org/manual/5.2/manual.html
37-
-- FIXME: assert(rshift(x, n) == math.floor(x % 2^32 / 2^n))
3831
end
3932

4033
local args = {

0 commit comments

Comments
 (0)