Jump to content

Module:WikiProject assessment progression/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Sasuke Sarutobi (talk | contribs) at 20:29, 6 December 2020 (Adding test for assessment using single class). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- 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: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 (this will be updated to be the same as original template)
function suite:test_module_outputs_expected_value()
	local moduleOutput = self.frame:preprocess('{{#invoke:'..moduleName..'|main|project=spaceflight}}')
	self:assertEquals('99.7', 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 expectedOutput = self.frame:preprocess('{{#expr:{{PAGESINCATEGORY:B-Class spaceflight articles|pages|R}} / ({{PAGESINCATEGORY:FA-Class {{{project}}} articles|pages|R}} + {{PAGESINCATEGORY:FL-Class {{{project}}} articles|pages|R}} + {{PAGESINCATEGORY:FM-Class {{{project}}} articles|pages|R}} + {{PAGESINCATEGORY:A-Class {{{project}}} articles|pages|R}} + {{PAGESINCATEGORY:GA-Class {{{project}}} articles|pages|R}} + {{PAGESINCATEGORY:B-Class {{{project}}} articles|pages|R}} + {{PAGESINCATEGORY:C-Class {{{project}}} articles|pages|R}} + {{PAGESINCATEGORY:Start-Class {{{project}}} articles|pages|R}} + {{PAGESINCATEGORY:Stub-Class {{{project}}} articles|pages|R}} + {{PAGESINCATEGORY:List-Class {{{project}}} articles|pages|R}} + {{PAGESINCATEGORY:Book-Class {{{project}}} articles|pages|R}} + {{PAGESINCATEGORY:Category-Class {{{project}}} articles|pages|R}} + {{PAGESINCATEGORY:Disambig-Class {{{project}}} articles|pages|R}} + {{PAGESINCATEGORY:File-Class {{{project}}} articles|pages|R}} + {{PAGESINCATEGORY:Portal-Class {{{project}}} articles|pages|R}} + {{PAGESINCATEGORY:Project-Class {{{project}}} articles|pages|R}} + {{PAGESINCATEGORY:Redirect-Class {{{project}}} articles|pages|R}} + {{PAGESINCATEGORY:Template-Class {{{project}}} articles|pages|R}} + {{PAGESINCATEGORY:Unassessed {{{project}}} articles|pages|R}}) round 1}}')
	local moduleOutput = self.frame:preprocess('{{#invoke:'..moduleName..'|main|project=spaceflight|class=B}}')
	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