From 0b124d559a04caec9e34961d67232f22b492ea54 Mon Sep 17 00:00:00 2001 From: C3MA Date: Tue, 19 Apr 2016 18:25:41 +0200 Subject: [PATCH 1/2] Included the Wordclock logic --- test.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test.lua b/test.lua index 8250213..97047cc 100644 --- a/test.lua +++ b/test.lua @@ -1,5 +1,6 @@ dofile("wlancfg.lua") dofile("timecore.lua") +dofile("wordclock.lua") print("Initialize Wordclock") function startTimeupdate() @@ -61,6 +62,13 @@ function startTimeupdate() print(hour) print(minutes) print(seconds) + -- Manually set something + leds=display_timestat(hour,minutes) + for k,v in pairs(leds) do + if (v == 1) then + print(k) + end + end print("---------------") conn:close() end) @@ -82,4 +90,4 @@ tmr.alarm(0, 100, 1, function() startTimeupdate() end) end -end) \ No newline at end of file +end) From 9f79147c78f50083137c6b3a06089d645501f9fb Mon Sep 17 00:00:00 2001 From: C3MA Date: Tue, 19 Apr 2016 20:56:45 +0200 Subject: [PATCH 2/2] Included some units tests --- unit/example.lua | 130 +++++++++++++++++++++++++++++++++++++++++++++++ wordclock.lua | 17 ++++--- 2 files changed, 139 insertions(+), 8 deletions(-) diff --git a/unit/example.lua b/unit/example.lua index 877ab28..059e339 100644 --- a/unit/example.lua +++ b/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) + diff --git a/wordclock.lua b/wordclock.lua index a1646c1..905196c 100755 --- a/wordclock.lua +++ b/wordclock.lua @@ -9,7 +9,7 @@ function display_timestat(hours, minutes, longmode) end -- generate an empty return type - local ret = { itis=0, fiveMin=0, tenMin=0, beforeMin=0, threeHour=0, quater=0, after=0, beforeHour=0, half=0, s=0, + local ret = { itis=0, fiveMin=0, tenMin=0, after=0, before=0, threeHour=0, quater=0, half=0, s=0, one=0, two=0, three=0, four=0, five=0, six=0, seven=0, eight=0, nine=0, ten=0, eleven=0, twelve=0, clock=0, sr_nc=0, min1=0, min2=0, min3=0, min4=0 } @@ -42,33 +42,34 @@ function display_timestat(hours, minutes, longmode) ret.after=1 elseif (minutes==3) then ret.quater=1 + ret.after=1 elseif (minutes==4) then ret.tenMin=1 ret.half=1 - ret.beforeMin=1 + ret.before=1 elseif (minutes==5) then ret.fiveMin=1 ret.half=1 - ret.beforeMin=1 + ret.before=1 elseif (minutes==6) then ret.half=1 elseif (minutes==7) then ret.fiveMin=1 ret.half=1 - ret.afterMin=1 + ret.after=1 elseif (minutes==8) then ret.tenMin=1 ret.half=1 - ret.afterMin=1 + ret.after=1 elseif (minutes==9) then ret.quater=1 - ret.threeHour=1 + ret.before=1 elseif (minutes==10) then ret.tenMin=1 - ret.beforeHour=1 + ret.before=1 elseif (minutes==11) then ret.fiveMin=1 - ret.beforeHour=1 + ret.before=1 end if (minutes >= 4) then