diff --git a/test/lang/constant/index b/test/lang/constant/index index 05bc1edb01..61db9ef549 100644 --- a/test/lang/constant/index +++ b/test/lang/constant/index @@ -1 +1,2 @@ number.lua +table.lua diff --git a/test/misc/tnew_tdup.lua b/test/lang/constant/table.lua similarity index 86% rename from test/misc/tnew_tdup.lua rename to test/lang/constant/table.lua index 140d05dee3..1e8e3de22c 100644 --- a/test/misc/tnew_tdup.lua +++ b/test/lang/constant/table.lua @@ -1,16 +1,15 @@ - -do - local a = nil - local b = {} - local t = {[true] = a, [false] = b or 1} - assert(t[true] == nil) - assert(t[false] == b) -end - -do - local b = {} - local t = {[true] = nil, [false] = b or 1} - assert(t[true] == nil) - assert(t[false] == b) -end - + +do --- tnew + local a = nil + local b = {} + local t = {[true] = a, [false] = b or 1} + assert(t[true] == nil) + assert(t[false] == b) +end + +do --- tdup + local b = {} + local t = {[true] = nil, [false] = b or 1} + assert(t[true] == nil) + assert(t[false] == b) +end diff --git a/test/lang/index b/test/lang/index index 457490ef30..3901d82ff8 100644 --- a/test/lang/index +++ b/test/lang/index @@ -3,6 +3,7 @@ assignment.lua compare.lua constant for.lua +length.lua modulo.lua concat.lua self.lua diff --git a/test/misc/tlen_loop.lua b/test/lang/length.lua similarity index 62% rename from test/misc/tlen_loop.lua rename to test/lang/length.lua index 050f23c389..1974b8257c 100644 --- a/test/misc/tlen_loop.lua +++ b/test/lang/length.lua @@ -1,23 +1,23 @@ - -do - local t = {} - for i=1,100 do t[#t+1] = i end - assert(#t == 100) - for i=1,100 do t[#t] = nil end -end - -do - local t = {} - t[90] = 999 - for i=1,100 do t[#t+1] = i end - assert(#t > 100 and t[#t] == 100) -end - -do - local t = {} - for i=1,100 do t[i] = i end - t[10] = nil - for i=1,99 do t[#t] = nil end - assert(#t == 0) -end - + +do --- length increasing and decreasing in loop + local t = {} + for i=1,100 do t[#t+1] = i end + assert(#t == 100) + for i=1,100 do t[#t] = nil end + assert(#t == 0) +end + +do --- length increasing in loop with existing element + local t = {} + t[90] = 999 + for i=1,100 do t[#t+1] = i end + assert(#t > 100 and t[#t] == 100) +end + +do --- length decreasing in loop with erased element + local t = {} + for i=1,100 do t[i] = i end + t[10] = nil + for i=1,99 do t[#t] = nil end + assert(#t == 0) +end diff --git a/test/lib/base/index b/test/lib/base/index index c9ddd19535..1c9f2be9dd 100644 --- a/test/lib/base/index +++ b/test/lib/base/index @@ -2,6 +2,9 @@ assert.lua error.lua getfenv.lua +lua<5.2 getsetmetatable.lua +ipairs.lua +next.lua pairs.lua select.lua +tonumber_tostring.lua xpcall_jit.lua +compat5.2 diff --git a/test/lib/base/ipairs.lua b/test/lib/base/ipairs.lua new file mode 100644 index 0000000000..66ac9f0ae3 --- /dev/null +++ b/test/lib/base/ipairs.lua @@ -0,0 +1,41 @@ +do --- small integer values + local t = { 4,5,6,7,8,9,10 } + local n = 0 + for i,v in ipairs(t) do + assert(v == i+3) + n = n + 1 + end + assert(n == 7) +end + +do --- jit key=value + local t = {} + for i=1,100 do t[i]=i end + local n = 0 + for i,v in ipairs(t) do + assert(i == v) + n = n + 1 + end + assert(n == 100) +end + +do --- untitled + local t = {} + local o = {{}, {}} + for i=1,100 do + local c = i.."" + t[i] = c + o[1][c] = i + o[2][c] = i + end + o[1]["90"] = nil + + local n = 0 + for _, c in ipairs(t) do + for i = 1, 2 do + o[i][c] = o[i][c] or 1 + n = n + 1 + end + end + assert(n == 200) +end diff --git a/test/lib/base/next.lua b/test/lib/base/next.lua new file mode 100644 index 0000000000..af0ee6642c --- /dev/null +++ b/test/lib/base/next.lua @@ -0,0 +1,17 @@ +do --- _G 1 + local ok, err = pcall(next, _G, 1) + assert(not ok) + local ok, err = pcall(function() next(_G, 1) end) + assert(not ok) +end + +do --- as iterator + local t = { foo = 9, bar = 10, 4, 5, 6 } + local r = {} + local function dummy() end + local function f(next) + for k,v in next,t,nil do r[#r+1] = k; if v == 5 then f(dummy) end end + end + f(next) + assert(#r == 5) +end diff --git a/test/lib/base/pairs.lua b/test/lib/base/pairs.lua index ac0b9de367..4d89d42d39 100644 --- a/test/lib/base/pairs.lua +++ b/test/lib/base/pairs.lua @@ -45,3 +45,29 @@ do --- metamethods +compat5.2 assert(b == 107500) end +do --- _G + local n = 0 + for k,v in pairs(_G) do + assert(_G[k] == v) + n = n + 1 + end + assert(n >= 35) +end + +do --- count + local function count(t) + local n = 0 + for i,v in pairs(t) do + n = n + 1 + end + return n; + end + assert(count({ 4,5,6,nil,8,nil,10}) == 5) + assert(count({ [0] = 3, 4,5,6,nil,8,nil,10}) == 6) + assert(count({ foo=1, bar=2, baz=3 }) == 3) + assert(count({ foo=1, bar=2, baz=3, boo=4 }) == 4) + assert(count({ 4,5,6,nil,8,nil,10, foo=1, bar=2, baz=3 }) == 8) + local t = { foo=1, bar=2, baz=3, boo=4 } + t.bar = nil; t.boo = nil + assert(count(t) == 2) +end diff --git a/test/misc/tonumber_tostring.lua b/test/lib/base/tonumber_tostring.lua similarity index 83% rename from test/misc/tonumber_tostring.lua rename to test/lib/base/tonumber_tostring.lua index d611b2c3c4..e7f576cea3 100644 --- a/test/misc/tonumber_tostring.lua +++ b/test/lib/base/tonumber_tostring.lua @@ -1,17 +1,17 @@ -do +do --- tonumber int local x = 0 for i=1,100 do x = x + tonumber(i) end assert(x == 5050) end -do +do --- tonumber float local x = 0 for i=1.5,100.5 do x = x + tonumber(i) end assert(x == 5100) end -do +do --- tostring int / tonumber local t = {} for i=1,100 do t[i] = tostring(i) end local x = 0 @@ -19,7 +19,7 @@ do assert(x == 5050) end -do +do --- tostring float / tonumber local t = {} for i=1,100 do t[i] = tostring(i+0.5) end local x = 0 @@ -27,11 +27,11 @@ do assert(x == 5100) end -do +do --- tonumber table for i=1,100 do assert(tonumber({}) == nil) end end -do +do --- tostring int / tostring local t = {} for i=1,100 do t[i] = tostring(i) end for i=1,100 do t[i] = tostring(t[i]) end @@ -40,7 +40,7 @@ do assert(x == 5050) end -do +do --- tostring table __tostring local mt = { __tostring = function(t) return tostring(t[1]) end } local t = {} for i=1,100 do t[i] = setmetatable({i}, mt) end @@ -50,7 +50,7 @@ do assert(x == 5050) end -do +do --- tostring table __tostring __call local r = setmetatable({}, { __call = function(x, t) return tostring(t[1]) end }) local mt = { __tostring = r } @@ -62,7 +62,7 @@ do assert(x == 5050) end -do +do --- print calls overridden tostring +lua<5.2 local x = false local co = coroutine.create(function() print(1) end) debug.setfenv(co, setmetatable({}, { __index = { @@ -71,12 +71,11 @@ do assert(x == true) end -do +do --- tonumber base 2 assert(tonumber(111, 2) == 7) end -do +do --- __tostring must be callable local t = setmetatable({}, { __tostring = "" }) assert(pcall(function() tostring(t) end) == false) end - diff --git a/test/misc/iter.lua b/test/misc/iter.lua deleted file mode 100644 index 4811812eef..0000000000 --- a/test/misc/iter.lua +++ /dev/null @@ -1,85 +0,0 @@ - -do - local n = 0 - for k,v in pairs(_G) do - assert(_G[k] == v) - n = n + 1 - end - assert(n >= 40) -end - -do - local t = { 4,5,6,7,8,9,10 } - local n = 0 - for i,v in ipairs(t) do - assert(v == i+3) - n = n + 1 - end - assert(n == 7) -end - -do - local function count(t) - local n = 0 - for i,v in pairs(t) do - n = n + 1 - end - return n; - end - assert(count({ 4,5,6,nil,8,nil,10}) == 5) - assert(count({ [0] = 3, 4,5,6,nil,8,nil,10}) == 6) - assert(count({ foo=1, bar=2, baz=3 }) == 3) - assert(count({ foo=1, bar=2, baz=3, boo=4 }) == 4) - assert(count({ 4,5,6,nil,8,nil,10, foo=1, bar=2, baz=3 }) == 8) - local t = { foo=1, bar=2, baz=3, boo=4 } - t.bar = nil; t.boo = nil - assert(count(t) == 2) -end - -do - local t = {} - for i=1,100 do t[i]=i end - local n = 0 - for i,v in ipairs(t) do - assert(i == v) - n = n + 1 - end - assert(n == 100) -end - -do - local ok, err = pcall(next, _G, 1) - assert(not ok) - local ok, err = pcall(function() next(_G, 1) end) - assert(not ok) -end - -do - local t = {} - local o = {{}, {}} - for i=1,100 do - local c = i.."" - t[i] = c - o[1][c] = i - o[2][c] = i - end - o[1]["90"] = nil - - for _, c in ipairs(t) do - for i = 1, 2 do - o[i][c] = o[i][c] or 1 - end - end -end - -do - local t = { foo = 9, bar = 10, 4, 5, 6 } - local r = {} - local function dummy() end - local function f(next) - for k,v in next,t,nil do r[#r+1] = k; if v == 5 then f(dummy) end end - end - f(next) - assert(#r == 5) -end - diff --git a/test/misc/phi_rot18.lua b/test/misc/phi_rot18.lua deleted file mode 100644 index b57b040539..0000000000 --- a/test/misc/phi_rot18.lua +++ /dev/null @@ -1,39 +0,0 @@ -local function rot18r(N) - local a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 - for x=1,N do - a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r=r,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q - end - return table.concat{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r} -end - -local function rot18l(N) - local a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 - for x=1,N do - a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r=b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,a - end - return table.concat{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r} -end - -assert(rot18r(0) == "123456789101112131415161718") -assert(rot18r(10) == "910111213141516171812345678") -assert(rot18r(105) == "456789101112131415161718123") -assert(rot18r(0) == "123456789101112131415161718") -assert(rot18r(1) == "181234567891011121314151617") -assert(rot18r(2) == "171812345678910111213141516") -assert(rot18r(0) == "123456789101112131415161718") -assert(rot18r(1) == "181234567891011121314151617") -assert(rot18r(2) == "171812345678910111213141516") -assert(rot18r(105) == "456789101112131415161718123") - -assert(rot18l(0) == "123456789101112131415161718") -assert(rot18l(10) == "111213141516171812345678910") -assert(rot18l(105) == "161718123456789101112131415") -assert(rot18l(0) == "123456789101112131415161718") -assert(rot18l(1) == "234567891011121314151617181") -assert(rot18l(2) == "345678910111213141516171812") -assert(rot18l(0) == "123456789101112131415161718") -assert(rot18l(1) == "234567891011121314151617181") -assert(rot18l(2) == "345678910111213141516171812") - -assert(rot18r(100) == "910111213141516171812345678") -assert(rot18l(100) == "111213141516171812345678910") diff --git a/test/misc/phi_rot8.lua b/test/misc/phi_rot8.lua deleted file mode 100644 index 2c249b76da..0000000000 --- a/test/misc/phi_rot8.lua +++ /dev/null @@ -1,39 +0,0 @@ -local function rot8r(n) - local a,b,c,d,e,f,g,h=1,2,3,4,5,6,7,8 - for x=1,n do - a,b,c,d,e,f,g,h=h,a,b,c,d,e,f,g - end - return table.concat{a,b,c,d,e,f,g,h} -end - -local function rot8l(n) - local a,b,c,d,e,f,g,h=1,2,3,4,5,6,7,8 - for x=1,n do - a,b,c,d,e,f,g,h=b,c,d,e,f,g,h,a - end - return table.concat{a,b,c,d,e,f,g,h} -end - -assert(rot8r(0) == "12345678") -assert(rot8r(10) == "78123456") -assert(rot8r(105) == "81234567") -assert(rot8r(0) == "12345678") -assert(rot8r(1) == "81234567") -assert(rot8r(2) == "78123456") -assert(rot8r(0) == "12345678") -assert(rot8r(1) == "81234567") -assert(rot8r(2) == "78123456") -assert(rot8r(105) == "81234567") - -assert(rot8l(0) == "12345678") -assert(rot8l(10) == "34567812") -assert(rot8l(105) == "23456781") -assert(rot8l(0) == "12345678") -assert(rot8l(1) == "23456781") -assert(rot8l(2) == "34567812") -assert(rot8l(0) == "12345678") -assert(rot8l(1) == "23456781") -assert(rot8l(2) == "34567812") - -assert(rot8r(100) == "56781234") -assert(rot8l(100) == "56781234") diff --git a/test/misc/phi_rot9.lua b/test/misc/phi_rot9.lua deleted file mode 100644 index e7b2821fb7..0000000000 --- a/test/misc/phi_rot9.lua +++ /dev/null @@ -1,39 +0,0 @@ -local function rot9r(n) - local a,b,c,d,e,f,g,h,i=1,2,3,4,5,6,7,8,9 - for x=1,n do - a,b,c,d,e,f,g,h,i=i,a,b,c,d,e,f,g,h - end - return table.concat{a,b,c,d,e,f,g,h,i} -end - -local function rot9l(n) - local a,b,c,d,e,f,g,h,i=1,2,3,4,5,6,7,8,9 - for x=1,n do - a,b,c,d,e,f,g,h,i=b,c,d,e,f,g,h,i,a - end - return table.concat{a,b,c,d,e,f,g,h,i} -end - -assert(rot9r(0) == "123456789") -assert(rot9r(10) == "912345678") -assert(rot9r(105) == "456789123") -assert(rot9r(0) == "123456789") -assert(rot9r(1) == "912345678") -assert(rot9r(2) == "891234567") -assert(rot9r(0) == "123456789") -assert(rot9r(1) == "912345678") -assert(rot9r(2) == "891234567") -assert(rot9r(105) == "456789123") - -assert(rot9l(0) == "123456789") -assert(rot9l(10) == "234567891") -assert(rot9l(105) == "789123456") -assert(rot9l(0) == "123456789") -assert(rot9l(1) == "234567891") -assert(rot9l(2) == "345678912") -assert(rot9l(0) == "123456789") -assert(rot9l(1) == "234567891") -assert(rot9l(2) == "345678912") - -assert(rot9r(100) == "912345678") -assert(rot9l(100) == "234567891") diff --git a/test/misc/phi_rotx.lua b/test/misc/phi_rotx.lua deleted file mode 100644 index c8c8b1eb35..0000000000 --- a/test/misc/phi_rotx.lua +++ /dev/null @@ -1,21 +0,0 @@ -local function rot9r(n, m) - local a,b,c,d,e,f,g,h,i=1,2,3,4,5,6,7,8,9 - local s = "" - for x=1,n do - a,b,c,d,e,f,g,h,i=i,a,b,c,d,e,f,g,h - if x == m then s = table.concat{a,b,c,d,e,f,g,h,i} end - c,d = d,c - end - return table.concat{a,b,c,d,e,f,g,h,i, s} -end - -assert(rot9r(0,0) == "123456789") -assert(rot9r(10,0) == "893124567") -assert(rot9r(105,0) == "913245678") -assert(rot9r(105,90) == "913245678891324567") -assert(rot9r(0,0) == "123456789") -assert(rot9r(1,0) == "913245678") -assert(rot9r(2,0) == "893124567") -assert(rot9r(1,1) == "913245678912345678") -assert(rot9r(2,1) == "893124567912345678") -assert(rot9r(2,2) == "893124567891324567") diff --git a/test/trace/index b/test/trace/index index 00e4d3badc..2703d2f3b7 100644 --- a/test/trace/index +++ b/test/trace/index @@ -1,5 +1,6 @@ exit_frame.lua exit_growstack.lua exit_jfuncf.lua +phi snap.lua stitch.lua diff --git a/test/misc/phi_copyspill.lua b/test/trace/phi/copyspill.lua similarity index 98% rename from test/misc/phi_copyspill.lua rename to test/trace/phi/copyspill.lua index c62d66fbb4..17a8698f56 100644 --- a/test/misc/phi_copyspill.lua +++ b/test/trace/phi/copyspill.lua @@ -1,3 +1,4 @@ +do --- mat4mul !private_G function mat4mul(a11, a21, a31, a41, a12, a22, a32, a42, a13, a23, a33, a43, @@ -49,3 +50,4 @@ for i = 1, 1000 do end assert(a11 == 1) assert(a31 == 0) +end diff --git a/test/trace/phi/index b/test/trace/phi/index new file mode 100644 index 0000000000..76799b894f --- /dev/null +++ b/test/trace/phi/index @@ -0,0 +1,3 @@ +copyspill.lua +ref.lua +rotate.lua diff --git a/test/misc/phi_ref.lua b/test/trace/phi/ref.lua similarity index 74% rename from test/misc/phi_ref.lua rename to test/trace/phi/ref.lua index 7493ef466f..3662912d27 100644 --- a/test/misc/phi_ref.lua +++ b/test/trace/phi/ref.lua @@ -1,35 +1,34 @@ --- rref points into invariant part -do +do --- rref points into invariant part 1 local x,y=1,2; for i=1,100 do x=x+y; y=i end assert(y == 100) end -do +do --- rref points into invariant part 2 local x,y=1,2; for i=1,100.5 do x=x+y; y=i end assert(y == 100) end -do +do --- rref points into invariant part 3 local x,y=1,2; for i=1,100 do x,y=y,x end assert(x == 1) assert(y == 2) end -do +do --- rref points into invariant part 4 local x,y,z=1,2,3; for i=1,100 do x,y,z=y,z,x end assert(x == 2) assert(y == 3) assert(z == 1) end -do +do --- rref points into invariant part 5 local x,y,z=1,2,3; for i=1,100 do x,y,z=z,x,y end assert(x == 3) assert(y == 1) assert(z == 2) end -do +do --- rref points into invariant part 6 local a,x,y,z=0,1,2,3; for i=1,100 do a=a+x; x=y; y=z; z=i end assert(a == 4759) assert(x == 98) @@ -37,41 +36,37 @@ do assert(z == 100) end --- variant slot, but no corresponding SLOAD -do +do --- variant slot, but no corresponding SLOAD i-1 local x,y=1,2; for i=1,100 do x=i; y=i-1 end assert(x == 100) assert(y == 99) end -do +do --- variant slot, but no corresponding SLOAD i+1 local x,y=1,2; for i=1,100 do x=i; y=i+1 end assert(x == 100) assert(y == 101) end -do +do --- variant slot, but no corresponding SLOAD side exit local x=0; for i=1,100 do if i==90 then break end x=i end assert(x == 89) end --- dup lref from variant slot (suppressed) -do +do --- dup lref from variant slot (suppressed) local x,y=1,2; for i=1,100 do x=i; y=i end assert(x == 100) assert(y == 100) end --- const rref -do +do --- const rref local x,y=1,2 local bxor,tobit=bit.bxor,bit.tobit; for i=1,100 do x=bxor(i,y); y=tobit(i+1) end assert(x == 0) assert(y == 101) end --- dup rref (ok) -do +do --- dup rref (ok) local x,y,z1,z2=1,2,3,4 local bxor,tobit=bit.bxor,bit.tobit; for i=1,100 do x=bxor(i,y); z2=tobit(i+5); z1=bxor(x,i+5); y=tobit(i+1) end assert(x == 0) @@ -80,8 +75,7 @@ do assert(z2 == 105) end --- variant slot, no corresponding SLOAD, -do +do --- variant slot, no corresponding SLOAD for i=1,5 do local a, b = 1, 2 local bits = 0 @@ -94,8 +88,7 @@ do end end --- don't eliminate PHI if referenced from snapshot -do +do --- don't eliminate PHI if referenced from snapshot local t = { 0 } local a = 0 for i=1,100 do @@ -107,8 +100,7 @@ do assert(t[1] == 2550) end --- don't eliminate PHI if referenced from snapshot -do +do --- don't eliminate PHI if referenced from snapshot local x = 1 local function f() local t = {} @@ -122,8 +114,7 @@ do assert(f() == 100) end --- don't eliminate PHI if referenced from another non-redundant PHI -do +do --- don't eliminate PHI if referenced from another non-redundant PHI local t = {} for i=1,256 do local a, b, k = i, math.floor(i/2), -i @@ -138,4 +129,3 @@ do for i=1,256 do x = x + bit.bxor(i, t[i]) end assert(x == -41704) end - diff --git a/test/trace/phi/rotate.lua b/test/trace/phi/rotate.lua new file mode 100644 index 0000000000..b80f07e184 --- /dev/null +++ b/test/trace/phi/rotate.lua @@ -0,0 +1,149 @@ +do --- rot8 + local function rot8r(n) + local a,b,c,d,e,f,g,h=1,2,3,4,5,6,7,8 + for x=1,n do + a,b,c,d,e,f,g,h=h,a,b,c,d,e,f,g + end + return table.concat{a,b,c,d,e,f,g,h} + end + + local function rot8l(n) + local a,b,c,d,e,f,g,h=1,2,3,4,5,6,7,8 + for x=1,n do + a,b,c,d,e,f,g,h=b,c,d,e,f,g,h,a + end + return table.concat{a,b,c,d,e,f,g,h} + end + + assert(rot8r(0) == "12345678") + assert(rot8r(10) == "78123456") + assert(rot8r(105) == "81234567") + assert(rot8r(0) == "12345678") + assert(rot8r(1) == "81234567") + assert(rot8r(2) == "78123456") + assert(rot8r(0) == "12345678") + assert(rot8r(1) == "81234567") + assert(rot8r(2) == "78123456") + assert(rot8r(105) == "81234567") + + assert(rot8l(0) == "12345678") + assert(rot8l(10) == "34567812") + assert(rot8l(105) == "23456781") + assert(rot8l(0) == "12345678") + assert(rot8l(1) == "23456781") + assert(rot8l(2) == "34567812") + assert(rot8l(0) == "12345678") + assert(rot8l(1) == "23456781") + assert(rot8l(2) == "34567812") + + assert(rot8r(100) == "56781234") + assert(rot8l(100) == "56781234") +end + +do --- rot9 + local function rot9r(n) + local a,b,c,d,e,f,g,h,i=1,2,3,4,5,6,7,8,9 + for x=1,n do + a,b,c,d,e,f,g,h,i=i,a,b,c,d,e,f,g,h + end + return table.concat{a,b,c,d,e,f,g,h,i} + end + + local function rot9l(n) + local a,b,c,d,e,f,g,h,i=1,2,3,4,5,6,7,8,9 + for x=1,n do + a,b,c,d,e,f,g,h,i=b,c,d,e,f,g,h,i,a + end + return table.concat{a,b,c,d,e,f,g,h,i} + end + + assert(rot9r(0) == "123456789") + assert(rot9r(10) == "912345678") + assert(rot9r(105) == "456789123") + assert(rot9r(0) == "123456789") + assert(rot9r(1) == "912345678") + assert(rot9r(2) == "891234567") + assert(rot9r(0) == "123456789") + assert(rot9r(1) == "912345678") + assert(rot9r(2) == "891234567") + assert(rot9r(105) == "456789123") + + assert(rot9l(0) == "123456789") + assert(rot9l(10) == "234567891") + assert(rot9l(105) == "789123456") + assert(rot9l(0) == "123456789") + assert(rot9l(1) == "234567891") + assert(rot9l(2) == "345678912") + assert(rot9l(0) == "123456789") + assert(rot9l(1) == "234567891") + assert(rot9l(2) == "345678912") + + assert(rot9r(100) == "912345678") + assert(rot9l(100) == "234567891") +end + +do --- rot18 + local function rot18r(N) + local a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 + for x=1,N do + a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r=r,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q + end + return table.concat{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r} + end + + local function rot18l(N) + local a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 + for x=1,N do + a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r=b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,a + end + return table.concat{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r} + end + + assert(rot18r(0) == "123456789101112131415161718") + assert(rot18r(10) == "910111213141516171812345678") + assert(rot18r(105) == "456789101112131415161718123") + assert(rot18r(0) == "123456789101112131415161718") + assert(rot18r(1) == "181234567891011121314151617") + assert(rot18r(2) == "171812345678910111213141516") + assert(rot18r(0) == "123456789101112131415161718") + assert(rot18r(1) == "181234567891011121314151617") + assert(rot18r(2) == "171812345678910111213141516") + assert(rot18r(105) == "456789101112131415161718123") + + assert(rot18l(0) == "123456789101112131415161718") + assert(rot18l(10) == "111213141516171812345678910") + assert(rot18l(105) == "161718123456789101112131415") + assert(rot18l(0) == "123456789101112131415161718") + assert(rot18l(1) == "234567891011121314151617181") + assert(rot18l(2) == "345678910111213141516171812") + assert(rot18l(0) == "123456789101112131415161718") + assert(rot18l(1) == "234567891011121314151617181") + assert(rot18l(2) == "345678910111213141516171812") + + assert(rot18r(100) == "910111213141516171812345678") + assert(rot18l(100) == "111213141516171812345678910") +end + +do --- rotx + local function rot9r(n, m) + local a,b,c,d,e,f,g,h,i=1,2,3,4,5,6,7,8,9 + local s = "" + for x=1,n do + a,b,c,d,e,f,g,h,i=i,a,b,c,d,e,f,g,h + if x == m then s = table.concat{a,b,c,d,e,f,g,h,i} end + c,d = d,c + end + return table.concat{a,b,c,d,e,f,g,h,i, s} + end + + assert(rot9r(0,0) == "123456789") + assert(rot9r(10,0) == "893124567") + assert(rot9r(105,0) == "913245678") + assert(rot9r(105,90) == "913245678891324567") + assert(rot9r(0,0) == "123456789") + assert(rot9r(1,0) == "913245678") + assert(rot9r(2,0) == "893124567") + assert(rot9r(1,1) == "913245678912345678") + assert(rot9r(2,1) == "893124567912345678") + assert(rot9r(2,2) == "893124567891324567") +end