every is working. minor tests outstanding

This commit is contained in:
Enrique García Cota 2011-04-24 16:56:54 +02:00
parent e014cee5aa
commit aaa9741b3c
2 changed files with 12 additions and 6 deletions

View File

@ -36,13 +36,12 @@ end
local function updatePeriodicEntry(self, dt) local function updatePeriodicEntry(self, dt)
self.running = self.running + dt self.running = self.running + dt
if self.running >= self.time then while self.running >= self.time do
self.callback(unpack(self.args)) self.callback(unpack(self.args))
self.running=0 self.running = self.running - self.time
end end
end end
local cron = {} local cron = {}
function cron.reset() function cron.reset()

View File

@ -70,16 +70,23 @@ context( 'cron', function()
end) end)
test( 'Should execute periodical actions periodically', function() test( 'Should execute periodical actions periodically', function()
cron.every(2, count) cron.every(3, count)
cron.update(1) cron.update(1)
assert_equal(counter, 0) assert_equal(counter, 0)
cron.update(1) cron.update(2)
assert_equal(counter, 1) assert_equal(counter, 1)
cron.update(2) cron.update(2)
assert_equal(counter, 2) assert_equal(counter, 1)
cron.update(1) cron.update(1)
assert_equal(counter, 2) assert_equal(counter, 2)
end) end)
test( 'Should execute the same action multiple times on a single update if appropiate', function()
cron.every(1, count)
cron.update(2)
assert_equal(counter, 2)
end)
end) end)