Module:Numlinks 2-num: Difference between revisions
mNo edit summary |
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 | local row_offset = clamp(num_links_2, num_links_2 + 1, curr_num_2) | ||
local | local col_offset = clamp(num_links_1, num_links_1 + 1, curr_num_1) | ||
local | local num_rows = num_links_2 + row_offset | ||
local | 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 | ||