Bruker:Jeblad/Module:JSONstat/testtilfeller
Utseende
![]() | Denne siden inneholder testtilfeller for modulen Bruker:Jeblad/Module:JSONstat. Vis resultater fra testene. |
-- Unit tests for [[Module:Wb]]. Click talk page to run tests.
-- Note that the test set at [[Bruker:Jeblad/SSB01222.json]] is not live and only for test purposes.
local p = require('Module:UnitTests')
local jsonstat = require('Module:JSONstat')
local categoryAsJson =
[[{
"index": { "A": 0, "B": 1 },
"label": { "A": "test a", "B": "test b" },
"unit": {
"X": { "base": "apples" },
"Y": { "base": "bananas" },
}
}]]
local categoryAsTable = mw.text.jsonDecode( categoryAsJson )
local axisAsJson =
[[{
"label": "horizontal",
"category": {}
}]]
local axisAsTable = mw.text.jsonDecode( axisAsJson )
local bundle =
[[{"bar":{"class":"dataset"},"foo":{"class":"dataset"}}]]
function p:test_category()
local instance = jsonstat.Category( categoryAsTable )
self:equals( 'Recall signature', instance.signature(), 'JSONstatCategory' )
self:equals_deep( 'Call toTable to get data as table', instance.toTable(), categoryAsTable )
self:equals_deep( 'Call toJSON to get data as JSON', mw.text.jsonDecode( instance.toJSON() ), categoryAsTable )
self:equals_deep( 'Call index to get the indicies on table form', instance.index(), categoryAsTable.index )
self:equals( 'Call index to get a single index', instance.index( 'A' ), categoryAsTable.index['A'] )
self:equals( 'Call index to get a single non-existing index', instance.index( 'C' ), categoryAsTable.index['C'] )
self:equals_deep( 'Call label to get the labels on table form', instance.label(), categoryAsTable.label )
self:equals( 'Call label to get a single index', instance.label( 'A' ), categoryAsTable.label['A'] )
self:equals( 'Call label to get a single non-existing index', instance.label( 'C' ), categoryAsTable.label['C'] )
self:equals_deep( 'Call unit to get the units on table form', instance.unit(), categoryAsTable.unit )
self:equals_deep( 'Call unit to get a single unit', instance.unit( 'X' ), categoryAsTable.unit['X'] )
self:equals_deep( 'Call unit to get a single non-existing unit', instance.unit( 'Z' ), categoryAsTable.label['Z'] )
end
function p:test_axis()
local instance = jsonstat.Axis( axisAsTable )
self:equals( 'Recall signature', instance.signature(), 'JSONstatAxis' )
self:equals_deep( 'Call toTable to get data as table', instance.toTable(), axisAsTable )
self:equals_deep( 'Call toJSON to get data as JSON', mw.text.jsonDecode( instance.toJSON() ), axisAsTable )
self:equals( 'Call label to get the single label', instance.label(), axisAsTable.label )
self:equals( 'Call category to get the single category and check its signature', instance.category().signature(), 'JSONstatCategory' )
end
return p