Moduuli:Värit/testit
Ulkoasu
✓ Kaikki testit läpäisty.
Testi | Odotettu | Tulos | |
---|---|---|---|
✓ | testi RGB → HSL → RGB palautuu alkuperäiseen | ||
✓ | testi Värin voi antaa muodossa gray(x.y) | ||
✓ | testi Värin voi antaa muodossa rgb(x, y, z) | ||
✓ | testi Värin voi muuttaa muotoon rgb(a.b,c.d,e.f) |
-- Unit tests for [[Module:Värit]].
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
local libName = 'Värit'
-- Helper to run all tests using sandbox version of the library from the debug console. To run against main lib, use =p.run()
function suite.runSandbox()
local frame = mw.getCurrentFrame():newChild{title='testit', args={module=libName .. '/hiekkalaatikko', displayMode='log'}}
return suite.run(frame)
end
-- Allow test runner to use the sandbox and the primary versions of the library with the same testcases
function suite:module()
return require('Moduuli:' .. (self.frame and self.frame.args.module or libName))
end
--[[
Library-specific tests
]]
local EPSILON = 1E-12
suite["testi Värin voi antaa muodossa rgb(x, y, z)"] = function (self)
local m = self:module()
self:assertEquals("#000000", m.alter_color{ color = "rgb(0, 0, 0)", output = "hex6" })
self:assertEquals("#7f7f7f", m.alter_color{ color = "rgb(127, 127, 127)", output = "hex6" })
self:assertEquals("#ffffff", m.alter_color{ color = "rgb(255, 255, 255)", output = "hex6" })
self:assertEquals("#ff0000", m.alter_color{ color = "rgb(255, 0, 0)", output = "hex6" })
self:assertEquals("#00ff00", m.alter_color{ color = "rgb(0, 255, 0)", output = "hex6" })
self:assertEquals("#0000ff", m.alter_color{ color = "rgb(0, 0, 255)", output = "hex6" })
self:assertEquals("#ffff00", m.alter_color{ color = "rgb(255, 255, 0)", output = "hex6" })
self:assertEquals("#ff00ff", m.alter_color{ color = "rgb(255, 0, 255)", output = "hex6" })
self:assertEquals("#00ff00", m.alter_color{ color = "rgb(0, 255, 0)", output = "hex6" })
self:assertEquals("#00ffff", m.alter_color{ color = "rgb(0, 255, 255)", output = "hex6" })
end
suite["testi Värin voi muuttaa muotoon rgb(a.b,c.d,e.f)"] = function (self)
local m = self:module()
self:assertEquals("rgb(1.0,1.0,1.0)", m.alter_color{ color = "#ffffff", output = "rgb0.1" })
--self:assertEquals("rgb(0.5,0.5,0.5)", m.alter_color{ color = "#808080", output = "rgb0.1" })
self:assertEquals("rgb(0.0,0.0,0.0)", m.alter_color{ color = "#000000", output = "rgb0.1" })
end
suite["testi Värin voi antaa muodossa gray(x.y)"] = function (self)
local m = self:module()
self:assertEquals("#000000", m.alter_color{ color = "gray(0.0)", output = "hex6" })
self:assertEquals("#7f7f7f", m.alter_color{ color = "gray(0.5)", output = "hex6" })
self:assertEquals("#ffffff", m.alter_color{ color = "gray(1.0)", output = "hex6" })
end
suite["testi RGB → HSL → RGB palautuu alkuperäiseen"] = function (self)
local m = self:module()
local function helper(R, G, B)
local H2, S2, L2 = m.rgb_to_hsl(R, G, B)
local R3, G3, B3 = m.hsl_to_rgb_(H2, S2, L2)
self:assertWithinDelta(R, R3, EPSILON, R3 .. " != " .. R .. "; syöte: " .. R .. ", " .. G .. ", " .. B)
self:assertWithinDelta(G, G3, EPSILON, G3 .. " != " .. G .. "; syöte: " .. R .. ", " .. G .. ", " .. B)
self:assertWithinDelta(B, B3, EPSILON, B3 .. " != " .. B .. "; syöte: " .. R .. ", " .. G .. ", " .. B)
end
helper(0, 0, 0)
helper(0, 0, 255)
helper(0, 255, 0)
helper(0, 255, 255)
helper(255, 0, 0)
helper(255, 0, 255)
helper(255, 255, 0)
helper(255, 255, 255)
helper(127, 127, 255)
helper(127, 255, 127)
helper(127, 255, 255)
helper(255, 127, 127)
helper(255, 127, 255)
helper(255, 255, 127)
helper(5, 62, 35)
helper(206, 40, 103)
helper(34, 28, 255)
helper(56, 131, 214)
helper(157, 76, 163)
helper(134, 126, 249)
helper(75, 197, 135)
helper(197, 103, 228)
helper(73, 90, 206)
helper(235, 18, 243)
helper(135, 22, 50)
helper(170, 228, 89)
helper(17, 6, 117)
helper(17, 61, 248)
helper(231, 217, 68)
helper(138, 96, 194)
helper(131, 171, 136)
helper(11, 112, 238)
helper(238, 184, 73)
helper(189, 164, 91)
helper(176, 43, 113)
helper(225, 212, 85)
helper(59, 228, 90)
helper(176, 244, 151)
helper(168, 219, 113)
helper(236, 102, 208)
helper(175, 233, 124)
helper(56, 243, 235)
helper(38, 225, 164)
helper(111, 158, 72)
helper(201, 79, 114)
helper(58, 48, 71)
helper(142, 107, 44)
helper(232, 27, 33)
helper(127, 194, 252)
helper(239, 175, 98)
helper(192, 95, 76)
helper(60, 150, 63)
helper(39, 187, 32)
helper(203, 42, 190)
helper(20, 243, 14)
helper(133, 45, 62)
helper(204, 187, 168)
helper(247, 164, 194)
helper(24, 35, 133)
helper(20, 18, 53)
helper(118, 210, 147)
helper(193, 14, 41)
helper(255, 53, 227)
helper(32, 255, 14)
helper(222, 19, 2)
helper(236, 152, 46)
helper(42, 100, 233)
helper(210, 92, 141)
helper(148, 116, 176)
helper(26, 136, 194)
helper(78, 254, 148)
helper(224, 191, 161)
helper(10, 191, 213)
helper(236, 223, 212)
helper(250, 190, 231)
helper(251, 171, 127)
helper(42, 212, 227)
helper(20, 166, 64)
helper(161, 59, 179)
helper(81, 84, 60)
helper(19, 162, 58)
helper(167, 131, 248)
helper(72, 140, 184)
helper(29, 121, 152)
helper(241, 115, 86)
helper(217, 111, 1)
helper(88, 153, 213)
helper(60, 173, 124)
helper(123, 78, 182)
helper(47, 159, 11)
helper(106, 178, 172)
helper(163, 89, 48)
helper(156, 160, 187)
helper(84, 189, 52)
helper(235, 175, 167)
helper(66, 136, 23)
helper(67, 224, 175)
helper(24, 29, 93)
helper(148, 152, 170)
helper(74, 198, 74)
helper(85, 49, 252)
helper(1, 211, 85)
helper(48, 112, 245)
helper(235, 196, 179)
helper(31, 175, 98)
helper(198, 241, 234)
helper(220, 52, 203)
helper(140, 76, 231)
helper(232, 223, 128)
helper(147, 42, 70)
helper(221, 126, 119)
helper(217, 127, 75)
helper(47, 175, 186)
helper(36, 154, 126)
helper(173, 152, 15)
helper(143, 143, 61)
helper(4, 87, 2)
helper(236, 153, 196)
helper(227, 237, 44)
helper(114, 124, 202)
helper(163, 246, 39)
helper(74, 224, 93)
helper(230, 190, 121)
helper(69, 241, 31)
helper(221, 158, 183)
helper(236, 46, 71)
helper(42, 51, 159)
helper(45, 32, 58)
helper(242, 3, 41)
helper(30, 117, 165)
helper(234, 25, 156)
helper(18, 100, 126)
helper(111, 74, 62)
helper(233, 144, 48)
helper(8, 110, 207)
helper(192, 90, 254)
helper(9, 133, 51)
helper(169, 178, 83)
helper(227, 164, 87)
helper(12, 195, 204)
helper(178, 173, 230)
helper(80, 191, 75)
helper(207, 48, 150)
helper(13, 25, 40)
helper(62, 34, 150)
helper(14, 226, 241)
helper(14, 235, 119)
helper(65, 149, 43)
helper(149, 121, 207)
helper(237, 134, 148)
helper(186, 57, 67)
helper(162, 137, 4)
helper(238, 88, 52)
helper(133, 102, 78)
helper(174, 164, 113)
helper(68, 179, 84)
helper(54, 193, 65)
helper(174, 4, 215)
helper(218, 153, 81)
helper(170, 134, 216)
helper(64, 65, 18)
helper(131, 226, 155)
helper(135, 209, 244)
helper(188, 87, 91)
helper(11, 6, 1)
helper(124, 74, 180)
helper(209, 129, 119)
helper(20, 48, 123)
helper(236, 11, 21)
helper(62, 181, 155)
helper(23, 245, 221)
helper(42, 121, 193)
helper(199, 1, 147)
helper(188, 189, 235)
helper(24, 200, 241)
helper(25, 70, 61)
helper(207, 24, 190)
helper(70, 44, 239)
helper(194, 24, 250)
helper(216, 87, 176)
helper(116, 110, 166)
helper(82, 153, 33)
helper(20, 96, 34)
helper(168, 29, 224)
helper(149, 53, 170)
helper(135, 79, 240)
helper(196, 31, 9)
helper(131, 101, 53)
helper(115, 40, 78)
helper(111, 1, 165)
helper(32, 117, 21)
helper(199, 200, 174)
helper(233, 221, 15)
helper(12, 134, 45)
helper(237, 27, 98)
helper(152, 162, 178)
helper(138, 103, 209)
helper(147, 234, 56)
helper(202, 95, 97)
helper(24, 206, 98)
helper(191, 238, 216)
helper(212, 182, 161)
helper(132, 159, 128)
helper(148, 171, 7)
helper(193, 152, 35)
helper(36, 49, 198)
helper(216, 187, 46)
helper(170, 79, 26)
helper(227, 26, 122)
helper(69, 50, 73)
helper(168, 241, 56)
helper(129, 198, 238)
helper(36, 75, 143)
helper(164, 222, 59)
helper(172, 160, 212)
helper(208, 197, 7)
helper(151, 157, 194)
helper(198, 72, 19)
helper(225, 44, 45)
helper(92, 112, 96)
helper(165, 25, 83)
helper(222, 154, 26)
helper(206, 191, 101)
helper(93, 100, 69)
helper(153, 17, 229)
helper(110, 224, 172)
helper(117, 120, 74)
helper(57, 62, 147)
helper(77, 32, 191)
helper(122, 123, 49)
helper(219, 34, 74)
helper(47, 0, 229)
helper(73, 206, 165)
helper(176, 44, 11)
helper(245, 197, 28)
helper(220, 52, 253)
helper(137, 170, 118)
helper(212, 227, 181)
helper(103, 49, 213)
helper(39, 171, 82)
helper(88, 135, 116)
helper(163, 182, 117)
helper(138, 1, 68)
helper(49, 176, 113)
helper(60, 166, 55)
helper(89, 131, 108)
helper(87, 12, 24)
helper(207, 224, 251)
helper(133, 72, 45)
helper(91, 111, 217)
helper(174, 200, 98)
helper(35, 108, 26)
helper(153, 246, 27)
helper(222, 40, 204)
helper(80, 100, 116)
helper(136, 189, 247)
helper(245, 22, 5)
helper(13, 228, 229)
helper(10, 106, 46)
helper(56, 198, 158)
helper(18, 117, 104)
helper(117, 153, 213)
helper(144, 51, 204)
helper(172, 18, 245)
helper(121, 98, 91)
helper(238, 233, 26)
helper(230, 223, 48)
helper(235, 236, 22)
helper(210, 246, 129)
helper(1, 48, 73)
helper(160, 66, 190)
helper(9, 184, 89)
helper(223, 72, 140)
helper(172, 244, 159)
helper(163, 110, 2)
helper(254, 92, 235)
helper(25, 67, 204)
helper(74, 47, 186)
helper(97, 1, 178)
helper(227, 2, 226)
helper(45, 162, 37)
helper(236, 172, 221)
helper(70, 139, 39)
helper(212, 56, 28)
helper(115, 219, 139)
helper(118, 218, 231)
helper(98, 243, 44)
helper(48, 63, 91)
helper(234, 160, 93)
helper(157, 131, 96)
helper(128, 176, 4)
helper(166, 157, 176)
helper(133, 228, 61)
helper(172, 184, 118)
helper(201, 45, 82)
helper(85, 162, 46)
helper(62, 6, 35)
helper(106, 54, 98)
helper(199, 33, 3)
helper(37, 190, 135)
helper(134, 62, 57)
helper(138, 228, 215)
helper(60, 106, 188)
helper(122, 23, 118)
helper(240, 224, 163)
helper(68, 54, 70)
helper(114, 116, 77)
helper(150, 223, 131)
helper(248, 166, 164)
helper(252, 203, 99)
helper(131, 82, 162)
helper(189, 220, 136)
helper(149, 25, 242)
helper(82, 147, 11)
end
return suite