Jump to content

Module:Number table sorting/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by TheDJ (talk | contribs) at 21:00, 6 July 2018. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local mNts = require('Module:Nts') -- the module to be tested
local Nts = mNts._exportClasses().Nts -- the Nts class
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()

-------------------------------------------------------------------------------
-- Helper functions and values
-------------------------------------------------------------------------------

suite.offValues = {'off', 'no', 'NO', 'n', 'false', false}
suite.onValues = {'on', 'yes', 'YES', 'y', 'true', true}
local function makeOnOffAsserts(fragment)
	suite['assert' .. fragment .. 'WhenOn'] = function (self, first, func, ...)
		for i, on in ipairs(suite.onValues) do
			self['assert' .. fragment](self, first, func(on), ...)
		end
	end
	suite['assert' .. fragment .. 'WhenOff'] = function (self, first, func, ...)
		for i, off in ipairs(suite.offValues) do
			self['assert' .. fragment](self, first, func(off), ...)
		end
	end
end
makeOnOffAsserts('Equals')
makeOnOffAsserts('StringContains')
makeOnOffAsserts('NotStringContains')

function suite:assertSortKeyEquals(expected, args)
	local ntsObj = Nts.new(args)
	self:assertEquals(expected, ntsObj:makeSortKey())
end

function suite:assertDisplayEquals(expected, args)
	local ntsObj = Nts.new(args)
	self:assertEquals(expected, ntsObj:makeDisplay())
end

-------------------------------------------------------------------------------
-- Sort key tests
-------------------------------------------------------------------------------

function suite:testSortKeyLimits()
	suite:assertSortKeyEquals('5000000000000000000♠', '0')
	suite:assertSortKeyEquals('', '5.4321e300')
	suite:assertSortKeyEquals('', '-5.4321e300')
	suite:assertSortKeyEquals('', '5.4321e-308')
	suite:assertSortKeyEquals('', '-5.4321e-308')
end

return suite