local export =
local Array = require "Module:array"
local function collect(iter) local vals = Array for val in iter do vals:insert(val) end return valsend
local total_tests, successes = 0, 0local function assert(val) total_tests = total_tests + 1 if val then successes = successes + 1 endend
function export.run_tests local ok, ret = pcall(function assert(Array(1, 2, 3):map(function (x) return x * x end):concat ", "
0 end):concat ", "
"array") assert(Array(1, nil, 2, nil, 3):compress:concat ", "
"1, 3, 5") assert(Array("a", "b", "c"):toSet["a"]
true) assert(Array(2, 4, 8):all(function (x) return x % 2
true) assert(Array(1, 2, 3):some(function (x) return x % 2
true) assert(Array(1, 2, 3, nil, 4):length
true) assert(Array(1, 2, 3, nil, 4):contains(4)
"a, b, c") assert(Array(1, nil, 2, nil, 3):maxIndex
5) assert(Array(1, nil, 2, nil, 3):num_keys:concat ", "
"3, 2, 1") assert(Array("a", "b", "c"):reverse:concat ", "
"a, b, and c") assert(Array(1, 1, 2, 3, 1, 2, 3):removeDuplicates:concat ", "
"1, 2, 3") assert(Array(1, 2, 3, 4, 5):slice(1, -3):concat ", "
3) assert((Array(1, 2, 3) + Array(4, 5, 6)):concat ", "
return export