🌟現在、鉄壁 鉄壁ヘッドショットには対応済みです。
鉄壁HSは通常HSと同じダメージになります。LMG及びDMR、チャージライフル、ハンマーポイント弾を除き、すべてのダメージ値が一致していることを確認しています。

モジュール:Utility/TestHelper

提供:Apex Data
ナビゲーションに移動 検索に移動

このモジュールについての説明文ページを モジュール:Utility/TestHelper/doc に作成できます

local TestHelper = {}

local StringBuilder = require('Module:Utility/StringBuilder')

local tostringTable = nil
local function tostringObject(val, builder, offset)
	if type(val) == 'table' then
		tostringTable(val, builder, offset + 1)
	elseif type(val) == 'string' then
		builder:appendFormat('"%s"', val)
	else
		builder:append(val)
	end
end

function tostringTable(tbl, builder, offset)
	builder:append('{\n')
	
	-- index
	if #tbl > 0 then
		builder:appendFormat(' %s', string.rep('  ', offset))
		for i = 1, #tbl do
			local val = tbl[i]
			tostringObject(val, builder, offset)
			builder:append(', ')
		end
		builder:append('\n')
	end
	
	-- key
	for key, val in pairs(tbl) do
		if type(key) ~= 'number' then
			builder:appendFormat(' %s["%s"] = ', string.rep('  ', offset), key)
			tostringObject(val, builder, offset)
			builder:append(',\n')
		end
	end
	
	builder:appendFormat(' %s}', string.rep('  ', offset - 1))
end

local function tostringInternal(val)
	if type(val) == 'table' then
		local builder = StringBuilder.new()
		builder:append('\n ')
		tostringTable(val, builder, 1)
		builder:append('\n')
		return tostring(builder)
	end
	
	return tostring(val)
end

-- Memo: no check metatable!!
local function tableEquals(obj1, obj2)
	if obj1 == obj2 then
		return true
	end
	
	local typename1 = type(obj1)
	local typename2 = type(obj2)
	if typename1 ~= typename2 or typename1 ~= 'table' then
		return false
	end
	
	local keyset = {}
	for key, val in pairs(obj1) do
		local val2 = obj2[key]
		if val2 == nil or tableEquals(val, val2) == false then
			return false
		end
		
		keyset[key] = true
	end
	
	for key2, _ in pairs(obj2) do
		if not keyset[key2] then
			return false
		end
	end
	return true
end

local function execute(testcases)
	local result = {}
	for name, testcase in pairs(testcases) do
		local status, retval = pcall(testcase.func)
		--local retval = testcase.func()
		if status then
			if tableEquals(testcase.expected, retval) then
				result[name] = {
					succeed  = true,
					actual   = retval,
					expected = testcase.expected,
					message  = 'Test result is passed.',
				}
			else
				result[name] = {
					succeed = false,
					actual   = retval,
					expected = testcase.expected,
					message = 'Test result isn\'t passed.',
				}
			end
		else
			result[name] = {
				succeed = testcase.hasError,
				actual  = '',
				expected = testcase.expected,
				message = retval,
			}
		end
	end
	return result
end

function TestHelper.executeAsNode(testcases)
	local result = execute(testcases)
	local tbl = mw.html.create('table')
		:addClass('wikitable')
		:tag('tr')
			:tag('th')
				:wikitext('Test name<br>テスト名')
				:done()
			:tag('th')
				:wikitext('Status<br>成否')
				:done()
			:tag('th')
				:wikitext('Expected value<br>期待値')
				:done()
			:tag('th')
				:wikitext('Result<br>結果')
				:done()
			:tag('th')
				:wikitext('Message<br>メッセージ')
				:done()
			:done()
	for name, value in pairs(result) do
		local expectedString = tostringInternal(value.expected)
		local actualString = tostringInternal(value.actual)
		
		tbl:tag('tr')
			:tag('td'):wikitext(name):done()
			:tag('td')
				:attr('align', 'center')
				:wikitext(value.succeed and '✔️' or '❌')
				:done()
			:tag('td'):wikitext(expectedString):done()
			:tag('td'):wikitext(actualString):done()
			:tag('td'):wikitext(value.message)
	end
	return tbl
end

return TestHelper