Merge branch 'master' of https://github.com/0110/Wordclock
This commit is contained in:
130
unit/example.lua
130
unit/example.lua
@@ -8,3 +8,133 @@ for k,v in pairs(leds) do
|
||||
print(k)
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
-- Unit tests
|
||||
leds=display_timestat(1,0)
|
||||
expected={}
|
||||
expected.itis=1
|
||||
expected.one=1
|
||||
expected.clock=1
|
||||
checkWords(leds, expected, 1, 0)
|
||||
|
||||
leds=display_timestat(2,5)
|
||||
expected={}
|
||||
expected.two=1
|
||||
expected.fiveMin=1
|
||||
expected.after=1
|
||||
checkWords(leds, expected, 2 , 5)
|
||||
|
||||
leds=display_timestat(3,10)
|
||||
expected={}
|
||||
expected.three=1
|
||||
expected.tenMin=1
|
||||
expected.after=1
|
||||
checkWords(leds, expected, 3 , 10)
|
||||
|
||||
leds=display_timestat(4,15)
|
||||
expected={}
|
||||
expected.four=1
|
||||
expected.after=1
|
||||
expected.quater=1
|
||||
checkWords(leds, expected, 4 , 15)
|
||||
|
||||
leds=display_timestat(5,20)
|
||||
expected={}
|
||||
expected.six=1
|
||||
expected.tenMin=1
|
||||
expected.before=1
|
||||
expected.half=1
|
||||
checkWords(leds, expected, 5 , 20)
|
||||
|
||||
leds=display_timestat(6,25)
|
||||
expected={}
|
||||
expected.seven=1
|
||||
expected.fiveMin=1
|
||||
expected.before=1
|
||||
expected.half=1
|
||||
checkWords(leds, expected, 6 , 25)
|
||||
|
||||
leds=display_timestat(7,30)
|
||||
expected={}
|
||||
expected.itis=1
|
||||
expected.eight=1
|
||||
expected.half=1
|
||||
checkWords(leds, expected, 7 , 30)
|
||||
|
||||
leds=display_timestat(8,35)
|
||||
expected={}
|
||||
expected.nine=1
|
||||
expected.half=1
|
||||
expected.fiveMin=1
|
||||
expected.after=1
|
||||
checkWords(leds, expected, 8 , 35)
|
||||
|
||||
leds=display_timestat(9,40)
|
||||
expected={}
|
||||
expected.ten=1
|
||||
expected.half=1
|
||||
expected.tenMin=1
|
||||
expected.after=1
|
||||
checkWords(leds, expected, 9 , 40)
|
||||
|
||||
leds=display_timestat(10,45)
|
||||
expected={}
|
||||
expected.eleven=1
|
||||
expected.quater=1
|
||||
expected.before=1
|
||||
checkWords(leds, expected, 10 , 45)
|
||||
|
||||
leds=display_timestat(11,50)
|
||||
expected={}
|
||||
expected.twelve=1
|
||||
expected.tenMin=1
|
||||
expected.before=1
|
||||
checkWords(leds, expected, 11 , 50)
|
||||
|
||||
leds=display_timestat(12,55)
|
||||
expected={}
|
||||
expected.one=1
|
||||
expected.fiveMin=1
|
||||
expected.before=1
|
||||
checkWords(leds, expected, 12 , 55)
|
||||
|
||||
leds=display_timestat(13,00)
|
||||
expected={}
|
||||
expected.itis=1
|
||||
expected.one=1
|
||||
expected.clock=1
|
||||
checkWords(leds, expected, 13 , 00)
|
||||
|
||||
-- test the minutes inbetween
|
||||
leds=display_timestat(14,01)
|
||||
expected={}
|
||||
expected.two=1
|
||||
expected.min1=1
|
||||
expected.clock=1
|
||||
checkWords(leds, expected, 14 , 01)
|
||||
|
||||
|
Reference in New Issue
Block a user