Jump to content

Module:TableTools/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 10:55, 15 December 2013 (create test case for compressSparseArray). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
-- Unit tests for [[Module:TableTools]]. Click talk page to run tests.

local tt = require('Module:TableTools') -- the module to be tested
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()

local sparseArray = {1, nil, [1.5] = 1.5, 2, nil, 3, nil, [math.huge] = math.huge, foo = 'bar', ['4'] = 'four_string'}
local sparseArrayConcatenated = '123'

function suite.concatIpairs(t)
	local ret = ''
	for i, v in ipairs(t) do
		ret = ret .. tostring(v)
	end
	return ret
end

function suite:testCompressSparseArray()
	local compressedArray = tt.compressSparseArray(sparseArray)
    self:assertEquals(sparseArrayConcatenated, suite.concatIpairs(compressedArray))
end

return suite