Module:WikiProject assessment progression/testcases

-- Unit tests for [[Module:WikiProject assessment progression]]. Click talk page to run tests.
local moduleName = 'WikiProject assessment progression/sandbox'
local myModule = require('Module:' .. moduleName)
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()

function suite:calculateProjectTotal()
	local projectTotal = self.frame:preprocess(
		'{{#expr:{{PAGESINCATEGORY:FA-Class spaceflight articles|pages|R}} + {{PAGESINCATEGORY:FL-Class spaceflight articles|pages|R}} + {{PAGESINCATEGORY:FM-Class spaceflight articles|pages|R}} + {{PAGESINCATEGORY:A-Class spaceflight articles|pages|R}} + {{PAGESINCATEGORY:GA-Class spaceflight articles|pages|R}} + {{PAGESINCATEGORY:B-Class spaceflight articles|pages|R}} + {{PAGESINCATEGORY:C-Class spaceflight articles|pages|R}} + {{PAGESINCATEGORY:Start-Class spaceflight articles|pages|R}} + {{PAGESINCATEGORY:Stub-Class spaceflight articles|pages|R}} + {{PAGESINCATEGORY:List-Class spaceflight articles|pages|R}} + {{PAGESINCATEGORY:Book-Class spaceflight articles|pages|R}} + {{PAGESINCATEGORY:Category-Class spaceflight articles|pages|R}} + {{PAGESINCATEGORY:Disambig-Class spaceflight articles|pages|R}} + {{PAGESINCATEGORY:File-Class spaceflight articles|pages|R}} + {{PAGESINCATEGORY:Portal-Class spaceflight articles|pages|R}} + {{PAGESINCATEGORY:Project-Class spaceflight articles|pages|R}} + {{PAGESINCATEGORY:Redirect-Class spaceflight articles|pages|R}} + {{PAGESINCATEGORY:Template-Class spaceflight articles|pages|R}} + {{PAGESINCATEGORY:Unassessed spaceflight articles|pages|R}}}}'
		)
	return projectTotal
end

function suite:assertTypeEquals(expectedType, functionName, message)
	local outputType = type(functionName)
	self:assertEquals(expectedType, outputType, message)
end

-- Confirm test function itself is working
function suite:test_assertTypeEquals_returns_correctly()
	self:assertTypeEquals('number', 10, 'assertTypeEquals failed to compare value to its type')
end

-- Confirm output is a number formatted as a string
function suite:test_module_outputs_number_as_string()
	local asString = self.frame:preprocess('{{#invoke:'..moduleName..'|main|project=spaceflight}}')
	local asNumber = tonumber(asString)
	self:assertTypeEquals('string', asString, 'Module output is not formatted as a string')
	self:assertTypeEquals('number', asNumber, 'Module output cannot be converted to a number')
end

-- Confirm output returns expected value
function suite:test_module_outputs_expected_value()
	local projectTotal = self:calculateProjectTotal()
	local expectedOutput = self.frame:preprocess('{{#expr:100 * ((' .. projectTotal .. ' - {{PAGESINCATEGORY:Unassessed spaceflight articles|pages|R}} ) / ' .. projectTotal .. ' ) round 1}}')
	local moduleOutput = self.frame:preprocess('{{#invoke:'..moduleName..'|main|project=spaceflight}}')
	self:assertEquals(expectedOutput, moduleOutput, 'Module output does not match expected calculation')
end

-- Confirm output returns expected value for single class
function suite:test_module_outputs_expected_for_single_class()
	local projectTotal = self:calculateProjectTotal()
	local expectedOutput = self.frame:preprocess('{{#expr:100 * ({{PAGESINCATEGORY:Stub-Class spaceflight articles|pages|R}} / ' .. projectTotal .. ' ) round 1}}')
	local moduleOutput = self.frame:preprocess('{{#invoke:'..moduleName..'|main|project=spaceflight|class=Stub}}')
	self:assertEquals(expectedOutput, moduleOutput, 'Module output differs for total on single class')
end

--[[ Confirm that module returns an error if no results are found for project name given
function suite:test_module_returns_error_if_invalid_project_specified()
	local invalidProject = self.frame:preprocess('{{#invoke:WikiProject assessment progression|main|project=SPAceflight}}')
	self:assertEquals('Error: project not found for project name "SPAceflight"', invalidProject)
end
--]]
return suite

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.