Spring til indhold

Modul:Sandbox/Jhertel/Formattal/testcases

Fra Wikipedia, den frie encyklopædi
Dette er siden til testcases for modulet Modul:Sandbox/Jhertel/Formattal. Vis resultatet af testen.
-- Enhedstests for [[Modul:Jhertel/sandkasse]]. Klik på diskussionsside for at køre tests.

local p = require('Module:UnitTests')
 
function p:test_formattal()
	-- 0 decimaler, ingen tusindadskiller
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|1}}", "1")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|12}}", "12")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|123}}", "123")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|1234}}", "1.234")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|12345}}", "12.345")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|123456}}", "123.456")

	-- 0 decimaler, komma som tusindadskiller
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|1}}", "1")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|12}}", "12")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|123}}", "123")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|1,234}}", "1.234")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|12,345}}", "12.345")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|123,456}}", "123.456")

	-- 0 decimaler, punktum som tusindadskiller
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|1}}", "1")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|12}}", "12")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|123}}", "123")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|1.234}}", "1.234")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|12.345}}", "12.345")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|123.456}}", "123.456")

	-- 2 decimaler, decimaladskiller punktum, tusindadskiller punktum
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|1.00}}", "1,00")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|12.00}}", "12,00")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|123.00}}", "123,00")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|1.234.00}}", "1.234.00[[Kategori:Sider med tal hvis format ikke kendes af formattal]]")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|12.345.00}}", "12.345.00[[Kategori:Sider med tal hvis format ikke kendes af formattal]]")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|123.456.00}}", "123.456.00[[Kategori:Sider med tal hvis format ikke kendes af formattal]]")

	-- 2 decimaler, decimaladskiller punktum, tusindadskiller komma
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|1.00}}", "1,00")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|12.00}}", "12,00")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|123.00}}", "123,00")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|1,234.00}}", "1.234")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|12,345.00}}", "12.345")
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|123,456.00}}", "123.456")

	-- Negative tal er ugyldige
	self:preprocess_equals("{{#invoke:Jhertel/sandkasse|formattal|-123}}", "-123[[Kategori:Sider med tal hvis format ikke kendes af formattal]]")

end
 
return p