Jump to content

Module:ProbabilityFormat/testcases

From RiskiPedia

Test Cases for Module:ProbabilityFormat

Input Expected Actual Status
0 no chance no chance ✅ Pass
1 100% chance 100% chance ✅ Pass
1.5 100% chance 100% chance ✅ Pass
Error: No probability provided Error: No probability provided ✅ Pass
invalid Error: Invalid probability Error: Invalid probability ✅ Pass
2.51345e-07 almost zero chance (less than 1 in 1,000,000) almost zero chance (less than 1 in 1,000,000) ✅ Pass
1.002e-06 about 1 in 1,000,000 about 1 in 1,000,000 ✅ Pass
8.51395e-06 about 1 in 100,000 about 1 in 100,000 ✅ Pass
7.251335e-05 about 1 in 10,000 about 1 in 10,000 ✅ Pass
0.000251335 about 1 in 4,000 about 1 in 4,000 ✅ Pass
0.00252315 about 1 in 400 about 1 in 400 ✅ Pass
0.0125 about 1 in 80 about 1 in 80 ✅ Pass
0.01 about 1 in 100 about 1 in 100 ✅ Pass
0.333333 about 1 in 3 about 1 in 3 ✅ Pass
0.3899 about 1 in 3 about 1 in 3 ✅ Pass
0.49872 about 1 in 2 about 1 in 2 ✅ Pass
0.55113 about 6 in 10 about 6 in 10 ✅ Pass
0.74144213 about 7 in 10 about 7 in 10 ✅ Pass
0.79000113 about 8 in 10 about 8 in 10 ✅ Pass
0.8113 about 8 in 10 about 8 in 10 ✅ Pass
0.85113 about 9 in 10 about 9 in 10 ✅ Pass
0.9001234 about 9 in 10 about 9 in 10 ✅ Pass
0.9501234 almost certain (more than 9 in 10) almost certain (more than 9 in 10) ✅ Pass
0.9901234 almost certain (more than 9 in 10) almost certain (more than 9 in 10) ✅ Pass
0.00211354 about 1 in 500 about 1 in 500 ✅ Pass
25/25 tests passed

local p = {}

-- Load the main module
local probabilityFormat = require('Module:ProbabilityFormat')

-- Table of test cases: { input, expected_output }
local testCases = {
    { input = 0, expected = 'no chance' },
    { input = 1, expected = '100% chance' },
    { input = 1.5, expected = '100% chance' },
    { input = '', expected = 'Error: No probability provided' },
    { input = 'invalid', expected = 'Error: Invalid probability' },
    { input = 0.000000251345, expected = 'almost zero chance (less than 1 in 1,000,000)' },    
    { input = 1.002e-6, expected = 'about 1 in 1,000,000' },
    { input = 0.00000851395, expected = 'about 1 in 100,000' },
    { input = 0.00007251335, expected = 'about 1 in 10,000' },
    { input = 0.000251335, expected = 'about 1 in 4,000' },
    { input = 0.00252315, expected = 'about 1 in 400' },
    { input = 0.0125, expected = 'about 1 in 80' },
    { input = 0.01, expected = 'about 1 in 100' },
    { input = 0.333333, expected = 'about 1 in 3' },
    { input = 0.3899, expected = 'about 1 in 3' },
    { input = 0.49872, expected = 'about 1 in 2' },
    { input = 0.55113, expected = 'about 6 in 10' },
    { input = 0.74144213, expected = 'about 7 in 10' },
    { input = 0.79000113, expected = 'about 8 in 10' },
    { input = 0.8113, expected = 'about 8 in 10' },
    { input = 0.85113, expected = 'about 9 in 10' },
    { input = 0.9001234, expected = 'about 9 in 10' },
    { input = 0.9501234, expected = 'almost certain (more than 9 in 10)' },
    { input = 0.9901234, expected = 'almost certain (more than 9 in 10)' },
    { input = 0.00211354, expected = 'about 1 in 500' }
}

-- Function to run tests and return a formatted table
function p.runTests(frame)
    local output = { '{| class="wikitable"\n! Input !! Expected !! Actual !! Status' }
    local passCount = 0
    local totalCount = #testCases

    for i, test in ipairs(testCases) do
        -- Simulate frame.args[1] for the input
        local frameMock = { args = { [1] = test.input } }
        local actual = probabilityFormat.convert(frameMock)
        local status = actual == test.expected and '✅ Pass' or '❌ Fail'
        if actual == test.expected then
            passCount = passCount + 1
        end
        table.insert(output, '|-\n| ' .. test.input .. ' || ' .. test.expected .. ' || ' .. actual .. ' || ' .. status)
    end

    table.insert(output, '|-\n| colspan="4" | ' .. passCount .. '/' .. totalCount .. ' tests passed')
    table.insert(output, '|}')
    return table.concat(output, '\n')
end

return p