Ugrás a tartalomhoz

Modul:NumberSpell/tests

Ellenőrzött
A Wikipédiából, a szabad enciklopédiából

NumberSpell modul tesztek[mi ez?]

Név Várt Tényleges
Igen test0To100
Igen testBadInputInvoke
Igen testGoodInvokeInput
Igen testBadInputLua
-- Unit tests for [[Module:NumberSpell]]. Click talk page to run tests.

local ns = require('Modul:NumberSpell')
local ScribuntoUnit = require('Modul:ScribuntoUnit')
local suite = ScribuntoUnit:new()

local write = ns.main
local _write = ns._main

local max = 100 -- Maximum number that can be parsed.

function suite:test0To100()
	self:assertEquals('nulla'           , _write(0))
 	self:assertEquals('egy'             , _write(1))
 	self:assertEquals('kettő'           , _write(2))
 	self:assertEquals('három'           , _write(3))
 	self:assertEquals('négy'            , _write(4))
 	self:assertEquals('öt'              , _write(5))
 	self:assertEquals('hat'             , _write(6))
 	self:assertEquals('hét'             , _write(7))
 	self:assertEquals('nyolc'           , _write(8))
 	self:assertEquals('kilenc'          , _write(9))
 	self:assertEquals('tíz'             , _write(10))
 	self:assertEquals('tizenegy'        , _write(11))
 	self:assertEquals('tizenkettő'      , _write(12))
 	self:assertEquals('tizenhárom'      , _write(13))
 	self:assertEquals('tizennégy'       , _write(14))
 	self:assertEquals('tizenöt'         , _write(15))
 	self:assertEquals('tizenhat'        , _write(16))
 	self:assertEquals('tizenhét'        , _write(17))
 	self:assertEquals('tizennyolc'      , _write(18))
 	self:assertEquals('tizenkilenc'     , _write(19))
 	self:assertEquals('húsz'            , _write(20))
 	self:assertEquals('huszonegy'       , _write(21))
 	self:assertEquals('huszonkettő'     , _write(22))
 	self:assertEquals('huszonhárom'     , _write(23))
 	self:assertEquals('huszonnégy'      , _write(24))
 	self:assertEquals('huszonöt'        , _write(25))
 	self:assertEquals('huszonhat'       , _write(26))
 	self:assertEquals('huszonhét'       , _write(27))
 	self:assertEquals('huszonnyolc'     , _write(28))
 	self:assertEquals('huszonkilenc'    , _write(29))
 	self:assertEquals('harminc'         , _write(30))
 	self:assertEquals('harmincegy'      , _write(31))
 	self:assertEquals('harminckettő'    , _write(32))
 	self:assertEquals('harminchárom'    , _write(33))
 	self:assertEquals('harmincnégy'     , _write(34))
 	self:assertEquals('harmincöt'       , _write(35))
 	self:assertEquals('harminchat'      , _write(36))
 	self:assertEquals('harminchét'      , _write(37))
 	self:assertEquals('harmincnyolc'    , _write(38))
 	self:assertEquals('harminckilenc'   , _write(39))
 	self:assertEquals('negyven'         , _write(40))
 	self:assertEquals('negyvenegy'      , _write(41))
 	self:assertEquals('negyvenkettő'    , _write(42))
 	self:assertEquals('negyvenhárom'    , _write(43))
 	self:assertEquals('negyvennégy'     , _write(44))
 	self:assertEquals('negyvenöt'       , _write(45))
 	self:assertEquals('negyvenhat'      , _write(46))
 	self:assertEquals('negyvenhét'      , _write(47))
 	self:assertEquals('negyvennyolc'    , _write(48))
 	self:assertEquals('negyvenkilenc'   , _write(49))
 	self:assertEquals('ötven'           , _write(50))
 	self:assertEquals('ötvenegy'        , _write(51))
 	self:assertEquals('ötvenkettő'      , _write(52))
 	self:assertEquals('ötvenhárom'      , _write(53))
 	self:assertEquals('ötvennégy'       , _write(54))
 	self:assertEquals('ötvenöt'         , _write(55))
 	self:assertEquals('ötvenhat'        , _write(56))
 	self:assertEquals('ötvenhét'        , _write(57))
 	self:assertEquals('ötvennyolc'      , _write(58))
 	self:assertEquals('ötvenkilenc'     , _write(59))
 	self:assertEquals('hatvan'          , _write(60))
 	self:assertEquals('hatvanegy'       , _write(61))
 	self:assertEquals('hatvankettő'     , _write(62))
 	self:assertEquals('hatvanhárom'     , _write(63))
 	self:assertEquals('hatvannégy'      , _write(64))
 	self:assertEquals('hatvanöt'        , _write(65))
 	self:assertEquals('hatvanhat'       , _write(66))
 	self:assertEquals('hatvanhét'       , _write(67))
 	self:assertEquals('hatvannyolc'     , _write(68))
 	self:assertEquals('hatvankilenc'    , _write(69))
 	self:assertEquals('hetven'          , _write(70))
 	self:assertEquals('hetvenegy'       , _write(71))
 	self:assertEquals('hetvenkettő'     , _write(72))
 	self:assertEquals('hetvenhárom'     , _write(73))
 	self:assertEquals('hetvennégy'      , _write(74))
 	self:assertEquals('hetvenöt'        , _write(75))
 	self:assertEquals('hetvenhat'       , _write(76))
 	self:assertEquals('hetvenhét'       , _write(77))
 	self:assertEquals('hetvennyolc'     , _write(78))
 	self:assertEquals('hetvenkilenc'    , _write(79))
 	self:assertEquals('nyolcvan'        , _write(80))
 	self:assertEquals('nyolcvanegy'     , _write(81))
 	self:assertEquals('nyolcvankettő'   , _write(82))
 	self:assertEquals('nyolcvanhárom'   , _write(83))
 	self:assertEquals('nyolcvannégy'    , _write(84))
 	self:assertEquals('nyolcvanöt'      , _write(85))
 	self:assertEquals('nyolcvanhat'     , _write(86))
 	self:assertEquals('nyolcvanhét'     , _write(87))
 	self:assertEquals('nyolcvannyolc'   , _write(88))
 	self:assertEquals('nyolcvankilenc'  , _write(89))
 	self:assertEquals('kilencven'       , _write(90))
 	self:assertEquals('kilencvenegy'    , _write(91))
 	self:assertEquals('kilencvenkettő'  , _write(92))
 	self:assertEquals('kilencvenhárom'  , _write(93))
 	self:assertEquals('kilencvennégy'   , _write(94))
 	self:assertEquals('kilencvenöt'     , _write(95))
 	self:assertEquals('kilencvenhat'    , _write(96))
 	self:assertEquals('kilencvenhét'    , _write(97))
 	self:assertEquals('kilencvennyolc'  , _write(98))
 	self:assertEquals('kilencvenkilenc' , _write(99))
 	self:assertEquals('száz'            , _write(100))
end

function suite:testGoodInvokeInput()
 	self:assertEquals('négy'       , write{'4'})
 	self:assertEquals('tizenhárom' , write{'13'})
 	self:assertEquals('hetvenhét'  , write{'77'})
end

function suite:testBadInputInvoke()
	local msg = '<strong class="error">Error: input must be an integer between 0 and ' .. tostring(max) .. '</strong>'
	self:assertEquals(msg, write{'foo'})
	self:assertEquals(msg, write{'-1'})
	self:assertEquals(msg, write{'101'})
	self:assertEquals(msg, write{'3.5'})
end

function suite:testBadInputLua()
	self:assertFalse(pcall(_write, 'foo'))
	self:assertFalse(pcall(_write, -1))
	self:assertFalse(pcall(_write, 101))
	self:assertFalse(pcall(_write, 3.5))
	self:assertFalse(pcall(_write, 0/0))
	self:assertFalse(pcall(_write, math.huge))
end

return suite