Dota 2 Вики
Advertisement

Для документации этого модуля может быть создана страница Модуль:Calculate/testcases/doc

local calc = require('Модуль:Calculate')._main -- the module to be tested
local ScribuntoUnit = require('Модуль:ScribuntoUnit')
local suite = ScribuntoUnit:new()


--------------------------------------------------------------------------------
-- Value substitution tests
--------------------------------------------------------------------------------

function suite:test_substitution_1v()
	self:assertEquals( '1', calc({'v1', ['v1']='1'}) )
end

function suite:test_substitution_2v()
	self:assertEquals( '1/2', calc({'v1', ['v1']='1/2'}) )
end

function suite:test_substitution_3v()	
	self:assertEquals( '1/2/3', calc({'v1', ['v1']='1/2/3'}) )
end


--------------------------------------------------------------------------------
-- Test simple expressions without v values
--------------------------------------------------------------------------------

function suite:test_non_substituted_expression()
	self:assertEquals( '0', calc({'1-1'}) )
end

function suite:test_non_substituted_expression_with_percentage()
	self:assertEquals( '1', calc({'100*1%'}) )
end

function suite:test_non_substituted_expression_with_round_at_end()
	self:assertEquals( '0,1', calc({'0,05 round1'}) )
end

function suite:test_non_substituted_expression_with_round()
	self:assertEquals( '0,01', calc({'(0,05 round1) * 10%'}) )
end


--------------------------------------------------------------------------
-- Number conversion tests
--------------------------------------------------------------------------------

function suite:test_substituted_expression_1v()
	self:assertEquals( '6/7/8', calc({'v1+5', ['v1']='1/2/3'}) )
end

function suite:test_substituted_expression_2v()
	self:assertEquals( '9/9/9', calc({'v1+v2+5', ['v1']='1/2/3', ['v2']='3/2/1'}) )
end

function suite:test_substituted_expression_3v()
	self:assertEquals( '54/104/154', calc({'v1+v2+5*v3', ['v1']='1/2/3', ['v2']='3/2/1', ['v3']='10/20/30'}) )
end


--------------------------------------------------------------------------------
-- Percentage handling tests
--------------------------------------------------------------------------------

function suite:test_percentage_in_main_expression()
	self:assertEquals( '1', calc({'100%'}) )
	self:assertEquals( '0,01', calc({'1%'}) )
end

function suite:test_percentage_in_v_value()
	self:assertEquals( '1', calc({'v1', ['v1']='100%'}) )
	self:assertEquals( '0,01', calc({'v1', ['v1']='1%'}) )
end


--------------------------------------------------------------------------------
-- Percentage output tests
--------------------------------------------------------------------------------

function suite:test_percentage_output_percentage_in_expression()
	self:assertEquals( '100%', calc({'100%', '%'}) )
end

function suite:test_percentage_output_percentage_in_v()
	self:assertEquals( '1%', calc({'v1', '%', ['v1']='1%'}) )
end

function suite:test_percentage_output_percentage_in_both()
	self:assertEquals( '5%', calc({'v1*50%', '%', ['v1']='10%'}) )
end

return suite
Advertisement