Module:Numlinks 2-num: Difference between revisions

Ganaram inukshuk (talk | contribs)
mNo edit summary
Ganaram inukshuk (talk | contribs)
add tester; add edge-case detection
Line 62: Line 62:
local display_text = string.format(current_fmt, num_1, num_2)
local display_text = string.format(current_fmt, num_1, num_2)
return string.format("%s", display_text)
return string.format("%s", display_text)
end
local function clamp(value, min_val, max_val)
    return math.min(math.max(value, min_val), max_val)
end
end
-- Create a grid of links
-- Create a grid of links
local num_rows = 1 + num_links_2 + math.max(num_links_2, math.min(curr_num_2 - num_links_2, num_links_2))
local row_offset = clamp(num_links_2, num_links_2 + 1, curr_num_2)
local num_cols = 1 + num_links_1 + math.max(num_links_1, math.min(curr_num_1 - num_links_1, num_links_1))
local col_offset = clamp(num_links_1, num_links_1 + 1, curr_num_1)
local row_offset = 1 + num_links_2 -- How far from upper edge to current-page's row
local num_rows = num_links_2 + row_offset
local col_offset = 1 + num_links_1 -- How far from left edge to current-page's column
local num_cols = num_links_1 + col_offset
 
local links = {}
local links = {}
for j = 1, num_rows do
for j = 1, num_rows do
Line 133: Line 138:


return result
return result
end
function p.tester()
local args = {
["Current Num 1"] = 5,
["Current Num 2"] = 2,
["Link Count 1"] = 7,
["Link Count 2"] = 4,
["Link Format"] = "%sL %ss"
}
return p._numlinks_2_num(args)
end
end


return p
return p