Home
Random
Log in
Settings
About example
Disclaimers
example
Search
Editing
Module:AffectionTest
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} -- 测试好感度系统的各种功能 function p.runTests() local results = {} local passCount = 0 local failCount = 0 -- 辅助函数:添加测试结果 local function addResult(name, passed, message) table.insert(results, { name = name, passed = passed, message = message or "" }) if passed then passCount = passCount + 1 else failCount = failCount + 1 end end -- 测试1:等级判断 local affection = require('Module:Affection') -- 创建模拟frame local function makeFrame(value) return { args = {[1] = tostring(value)} } end -- 测试等级名称 local level10 = affection.getLevelName(makeFrame(10)) addResult("等级测试:10分", level10 == "陌生", "期望'陌生',得到'" .. level10 .. "'") local level30 = affection.getLevelName(makeFrame(30)) addResult("等级测试:30分", level30 == "认识", "期望'认识',得到'" .. level30 .. "'") local level50 = affection.getLevelName(makeFrame(50)) addResult("等级测试:50分", level50 == "友好", "期望'友好',得到'" .. level50 .. "'") local level70 = affection.getLevelName(makeFrame(70)) addResult("等级测试:70分", level70 == "亲密", "期望'亲密',得到'" .. level70 .. "'") local level90 = affection.getLevelName(makeFrame(90)) addResult("等级测试:90分", level90 == "喜欢", "期望'喜欢',得到'" .. level90 .. "'") local level100 = affection.getLevelName(makeFrame(100)) addResult("等级测试:100分", level100 == "热恋", "期望'热恋',得到'" .. level100 .. "'") -- 测试等级图标 local icon10 = affection.getLevelIcon(makeFrame(10)) addResult("图标测试:10分", icon10 == "💔", "期望'💔',得到'" .. icon10 .. "'") local icon100 = affection.getLevelIcon(makeFrame(100)) addResult("图标测试:100分", icon100 == "❤️", "期望'❤️',得到'" .. icon100 .. "'") -- 测试计算功能 local calcFrame = { args = { current = "50", change = "15" } } local newValue = affection.calculate(calcFrame) addResult("计算测试:50+15", newValue == "65", "期望'65',得到'" .. newValue .. "'") -- 测试超出上限 local maxFrame = { args = { current = "95", change = "20", max = "100" } } local maxValue = affection.calculate(maxFrame) addResult("上限测试:95+20", maxValue == "100", "期望'100'(已达上限),得到'" .. maxValue .. "'") -- 测试低于下限 local minFrame = { args = { current = "10", change = "-20" } } local minValue = affection.calculate(minFrame) addResult("下限测试:10-20", minValue == "0", "期望'0'(已达下限),得到'" .. minValue .. "'") -- 生成测试报告 local html = mw.html.create('div') :css('max-width', '800px') :css('margin', '20px auto') :css('padding', '20px') :css('background', 'linear-gradient(135deg, #f0f8ff 0%, #e6f3ff 100%)') :css('border-radius', '15px') -- 标题 html:tag('div') :css('font-size', '24px') :css('font-weight', 'bold') :css('color', '#0088cc') :css('margin-bottom', '20px') :css('text-align', 'center') :wikitext('🧪 好感度系统测试报告') -- 统计信息 local stats = html:tag('div') :css('margin', '20px 0') :css('padding', '15px') :css('background', 'white') :css('border-radius', '10px') :css('text-align', 'center') stats:tag('span') :css('color', '#00aa00') :css('font-weight', 'bold') :css('font-size', '18px') :css('margin-right', '20px') :wikitext('✓ 通过: ' .. passCount) stats:tag('span') :css('color', '#aa0000') :css('font-weight', 'bold') :css('font-size', '18px') :wikitext('✗ 失败: ' .. failCount) -- 测试结果列表 for _, result in ipairs(results) do local resultDiv = html:tag('div') :css('margin', '10px 0') :css('padding', '12px') :css('background', 'white') :css('border-radius', '8px') :css('border-left', '4px solid ' .. (result.passed and '#00aa00' or '#aa0000')) resultDiv:tag('span') :css('font-weight', 'bold') :css('color', result.passed and '#00aa00' or '#aa0000') :wikitext((result.passed and '✓' or '✗') .. ' ') resultDiv:tag('span') :css('font-weight', 'bold') :wikitext(result.name) if result.message ~= "" then resultDiv:tag('div') :css('color', '#666') :css('font-size', '14px') :css('margin-top', '5px') :wikitext(result.message) end end return tostring(html) end return p
Summary:
Please note that all contributions to example are considered to be released under the 知识共享署名-相同方式共享 (see
example:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:AffectionTest/doc
(
edit
)