Jump to content

Module:Wd/sandbox/testcases/common

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Janhrach (talk | contribs) at 16:38, 20 August 2023 (Added new functionality). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}

-- generates unit test object to be returned by a specific testcase module
-- first argument: name of the module to test
-- second argument: a table with the structure described in testcaseTable; used for reference values
function p.generate_unit_tests_module_vs_table(module_to_test, inputs_and_outputs)
	local unit_tests_module = require("Module:UnitTests")
    
    function unit_tests_module:test()
	    unit_tests_module:preprocess_equals_many(
	    	"{{#invoke:" .. module_to_test .. "|",
	    	"}}",
		    inputs_and_outputs
	    )
    end
    
    return unit_tests_module
end

-- for testing a module against a module
-- first argument: module to test
-- second argument: module to be used for correct outputs
-- third argument: inputs for the modules
function p.generate_unit_tests_module_vs_module(module_to_test, reference_module, inputs)
    local unit_tests_module = require("Module:UnitTests")
    
    function unit_tests_module:test()
	    unit_tests_module:preprocess_equals_preprocess_many(
	    	"{{#invoke:" .. module_to_test .. "|",
	    	"}}",
	    	"{{#invoke:" .. reference_module .. "|",
	    	"}}",
		    inputs
	    )
    end
    
    return unit_tests_module
end

return p