Wordclock/unit/testWordClock.lua

225 lines
4.8 KiB
Lua
Raw Permalink Normal View History

-- Example usage of the word clock
2016-04-12 21:11:50 +02:00
dofile("../wordclock.lua")
2017-02-28 18:50:43 +01:00
print "------- Manual test ----"
-- Manually set something
leds=display_timestat(15,30)
for k,v in pairs(leds) do
if (v == 1) then
print(k)
end
end
2017-02-28 18:50:43 +01:00
print "---------------------"
2016-04-19 20:56:45 +02:00
function checkWords(leds, expected, hour, min)
for k, v in pairs(leds) do
if (v == 1) then
local found=false
for kexp, vexp in pairs(expected) do
if (k == kexp) then found=true end
end
if not found then
print(k .. " was not found")
os.exit(1)
end
else
local found=false
for kexp, vexp in pairs(expected) do
if (k == kexp) then found=true end
end
if found then
print(k .. " should not be found")
os.exit(1)
end
end
end
print(hour .. ":" .. min)
end
function checkCharacter(words, expected)
if (words == nil or expected == nil) then
print("Not all parameter set to checkCharacter")
os.exit(1)
end
if (words ~= expected) then
print("Not all character found. Expected " .. expected .. ", but found " .. words)
os.exit(1)
end
end
2017-02-28 18:50:43 +01:00
print ""
print "----------- Unit tests -------------"
2016-04-19 20:56:45 +02:00
-- Unit tests
leds=display_timestat(1,0)
expected={}
expected.itis=1
expected.one=1
expected.clock=1
checkWords(leds, expected, 1, 0)
checkCharacter(display_countwords_de(leds), 11)
2016-04-19 20:56:45 +02:00
leds=display_timestat(2,5)
expected={}
expected.two=1
expected.fiveMin=1
expected.after=1
checkWords(leds, expected, 2 , 5)
checkCharacter(display_countwords_de(leds), 12)
2016-04-19 20:56:45 +02:00
leds=display_timestat(3,10)
expected={}
expected.three=1
expected.tenMin=1
expected.after=1
checkWords(leds, expected, 3 , 10)
2017-02-28 19:14:09 +01:00
checkCharacter(display_countwords_de(leds), 12)
2016-04-19 20:56:45 +02:00
leds=display_timestat(4,15)
expected={}
expected.four=1
expected.after=1
expected.quater=1
checkWords(leds, expected, 4 , 15)
2017-02-28 19:14:09 +01:00
checkCharacter(display_countwords_de(leds), 15)
2016-04-19 20:56:45 +02:00
leds=display_timestat(5,20)
expected={}
expected.five=1
expected.twenty=1
expected.after=1
2016-04-19 20:56:45 +02:00
checkWords(leds, expected, 5 , 20)
2017-02-28 19:14:09 +01:00
checkCharacter(display_countwords_de(leds), 15)
2016-04-19 20:56:45 +02:00
leds=display_timestat(6,25)
expected={}
expected.seven=1
expected.fiveMin=1
expected.before=1
expected.half=1
checkWords(leds, expected, 6 , 25)
2017-02-28 19:14:09 +01:00
checkCharacter(display_countwords_de(leds), 17)
2016-04-19 20:56:45 +02:00
leds=display_timestat(7,30)
expected={}
expected.itis=1
expected.eight=1
expected.half=1
checkWords(leds, expected, 7 , 30)
2017-02-28 19:14:09 +01:00
checkCharacter(display_countwords_de(leds), 13)
2016-04-19 20:56:45 +02:00
leds=display_timestat(8,35)
expected={}
expected.nine=1
expected.half=1
expected.fiveMin=1
expected.after=1
checkWords(leds, expected, 8 , 35)
2017-02-28 19:14:09 +01:00
checkCharacter(display_countwords_de(leds), 16)
2016-04-19 20:56:45 +02:00
leds=display_timestat(9,40)
expected={}
expected.ten=1
expected.twenty=1
expected.before=1
2016-04-19 20:56:45 +02:00
checkWords(leds, expected, 9 , 40)
2017-02-28 19:14:09 +01:00
checkCharacter(display_countwords_de(leds), 14)
2016-04-19 20:56:45 +02:00
leds=display_timestat(10,45)
expected={}
expected.eleven=1
expected.quater=1
expected.before=1
checkWords(leds, expected, 10 , 45)
2017-02-28 19:14:09 +01:00
checkCharacter(display_countwords_de(leds), 13)
2016-04-19 20:56:45 +02:00
leds=display_timestat(11,50)
expected={}
expected.twelve=1
expected.tenMin=1
expected.before=1
checkWords(leds, expected, 11 , 50)
2017-02-28 19:14:09 +01:00
checkCharacter(display_countwords_de(leds), 12)
2016-04-19 20:56:45 +02:00
leds=display_timestat(12,55)
expected={}
expected.oneLong=1
2016-04-19 20:56:45 +02:00
expected.fiveMin=1
expected.before=1
checkWords(leds, expected, 12 , 55)
2017-02-28 19:14:09 +01:00
checkCharacter(display_countwords_de(leds), 11)
2016-04-19 20:56:45 +02:00
leds=display_timestat(13,00)
expected={}
expected.itis=1
expected.one=1
expected.clock=1
checkWords(leds, expected, 13 , 00)
2017-02-28 19:14:09 +01:00
checkCharacter(display_countwords_de(leds), 11)
2016-04-19 20:56:45 +02:00
-- test the minutes inbetween
leds=display_timestat(14,01)
expected={}
expected.itis=1
2016-04-19 20:56:45 +02:00
expected.two=1
expected.min1=1
expected.clock=1
checkWords(leds, expected, 14 , 01)
checkCharacter(display_countwords_de(leds), 12)
2016-04-19 20:56:45 +02:00
leds=display_timestat(15,02)
expected={}
expected.itis=1
expected.three=1
expected.min2=1
expected.clock=1
checkWords(leds, expected, 15 , 02)
checkCharacter(display_countwords_de(leds), 12)
leds=display_timestat(16,03)
expected={}
expected.itis=1
expected.four=1
expected.min3=1
expected.clock=1
checkWords(leds, expected, 16 , 03)
checkCharacter(display_countwords_de(leds), 12)
leds=display_timestat(17,04)
expected={}
expected.itis=1
expected.five=1
expected.min4=1
expected.clock=1
checkWords(leds, expected, 17 , 04)
checkCharacter(display_countwords_de(leds), 12)
leds=display_timestat(18,06)
expected={}
expected.fiveMin=1
expected.after=1
expected.min1=1
expected.six=1
checkWords(leds, expected, 18 , 06)
checkCharacter(display_countwords_de(leds), 13)
leds=display_timestat(19,09)
expected={}
expected.fiveMin=1
expected.after=1
expected.min4=1
expected.seven=1
checkWords(leds, expected, 19 , 09)
checkCharacter(display_countwords_de(leds), 14)
leds=display_timestat(20,17)
expected={}
expected.quater=1
expected.after=1
expected.min2=1
expected.eight=1
checkWords(leds, expected, 20 , 17)
checkCharacter(display_countwords_de(leds), 15)