Module:math/testcases
Appearance
- The following documentation is located at Module:math/testcases/documentation. [edit] Categories were auto-generated by Module:documentation. [edit]
- Useful links: root page • root page’s subpages • links • transclusions • tested module • sandbox
All tests passed. (refresh)
Text | Expected | Actual | |
---|---|---|---|
![]() | 1 | 1 | 1 |
![]() | -1 | 1 | 1 |
![]() | 0 | 0 | 0 |
![]() | 0, 0 | 0 | 0 |
![]() | 1, 0 | 1 | 1 |
![]() | 0, 1 | 1 | 1 |
![]() | 1, 1 | 1 | 1 |
![]() | 6, 4 | 2 | 2 |
![]() | 6, -4 | 2 | 2 |
![]() | -6, -4 | 2 | 2 |
![]() | 2, 8 | 2 | 2 |
![]() | 15, 20 | 5 | 5 |
![]() | 20, 15 | 5 | 5 |
![]() | 35, -21 | 7 | 7 |
![]() | 48, 18 | 6 | 6 |
![]() | 8, 12, 16 | 4 | 4 |
![]() | 25, -35, 95 | 5 | 5 |
![]() | 95, -35, 25 | 5 | 5 |
![]() | 1500, 750, 150000, 625 | 125 | 125 |
![]() | 186028, 193052, 144624 | 4 | 4 |
![]() | 2^100, 2^53 | 9.007199254741e+15 | 9.007199254741e+15 |
Text | Expected | Actual | |
---|---|---|---|
![]() | 1 | 1 | 1 |
![]() | -1 | 1 | 1 |
![]() | 0 | 0 | 0 |
![]() | 0, 0 | 0 | 0 |
![]() | 1, 0 | 0 | 0 |
![]() | 0, 1 | 0 | 0 |
![]() | 1, 1 | 1 | 1 |
![]() | 6, 4 | 12 | 12 |
![]() | 6, -4 | 12 | 12 |
![]() | -6, -4 | 12 | 12 |
![]() | 2, 8 | 8 | 8 |
![]() | 15, 20 | 60 | 60 |
![]() | 20, 15 | 60 | 60 |
![]() | 35, -21 | 105 | 105 |
![]() | 48, 18 | 144 | 144 |
![]() | 8, 12, 16 | 48 | 48 |
![]() | 25, -35, 95 | 3325 | 3325 |
![]() | 95, -35, 25 | 3325 | 3325 |
![]() | 1500, 750, 150000, 625 | 150000 | 150000 |
![]() | 186028, 193052, 144624 | 3.2461830712478e+14 | 3.2461830712478e+14 |
![]() | 2^100, 2^53 | 1.2676506002282e+30 | 1.2676506002282e+30 |
local tests = require("Module:UnitTests")
local m_math = require("Module:math")
local concat = table.concat
local gcd = m_math.gcd
local lcm = m_math.lcm
local unpack = unpack
local function do_test(func, args, expected, name)
if name == nil then
name = concat(args, ", ")
end
tests:equals(name, func(unpack(args)), expected)
end
function tests:check_gcd(args, expected, name)
return do_test(gcd, args, expected, name)
end
function tests:check_lcm(args, expected, name)
return do_test(lcm, args, expected, name)
end
function tests:test_gcd()
self:iterate({
{{1}, 1},
{{-1}, 1},
{{0}, 0},
{{0, 0}, 0},
{{1, 0}, 1},
{{0, 1}, 1},
{{1, 1}, 1},
{{6, 4}, 2},
{{6, -4}, 2},
{{-6, -4}, 2},
{{2, 8}, 2},
{{15, 20}, 5},
{{20, 15}, 5},
{{35, -21}, 7},
{{48, 18}, 6},
{{8, 12, 16}, 4},
{{25, -35, 95}, 5},
{{95, -35, 25}, 5},
{{1500, 750, 150000, 625}, 125},
{{186028, 193052, 144624}, 4},
{{2^100, 2^53}, 2^53, "2^100, 2^53"},
}, "check_gcd")
end
function tests:test_lcm()
self:iterate({
{{1}, 1},
{{-1}, 1},
{{0}, 0},
{{0, 0}, 0},
{{1, 0}, 0},
{{0, 1}, 0},
{{1, 1}, 1},
{{6, 4}, 12},
{{6, -4}, 12},
{{-6, -4}, 12},
{{2, 8}, 8},
{{15, 20}, 60},
{{20, 15}, 60},
{{35, -21}, 105},
{{48, 18}, 144},
{{8, 12, 16}, 48},
{{25, -35, 95}, 3325},
{{95, -35, 25}, 3325},
{{1500, 750, 150000, 625}, 150000},
{{186028, 193052, 144624}, 324618307124784},
{{2^100, 2^53}, 2^100, "2^100, 2^53"},
}, "check_lcm")
end
return tests