comparison tests/test_util_throttle.lua @ 8262:e6f3e440c843

tests: util.throttle: Fix time override to simply override util.time. Recent change bypasses current override method.
author Matthew Wild <mwild1@gmail.com>
date Sat, 23 Sep 2017 23:32:08 +0100
parents 8ce592e376ff
children
comparison
equal deleted inserted replaced
8261:012208387396 8262:e6f3e440c843
5 end 5 end
6 local function later(n) 6 local function later(n)
7 now = now + n; -- time passes at a different rate 7 now = now + n; -- time passes at a different rate
8 end 8 end
9 9
10 local function override_gettime(throttle) 10 package.loaded["util.time"] = {
11 local i = 0; 11 now = predictable_gettime;
12 repeat 12 }
13 i = i + 1;
14 local name = debug.getupvalue(throttle.update, i);
15 if name then
16 debug.setupvalue(throttle.update, i, predictable_gettime);
17 return throttle;
18 end
19 until not name;
20 end
21 13
22 function create(create) 14 function create(create)
23 local a = override_gettime( create(3, 10) ); 15 local a = create(3, 10);
24 16
25 assert_equal(a:poll(1), true); -- 3 -> 2 17 assert_equal(a:poll(1), true); -- 3 -> 2
26 assert_equal(a:poll(1), true); -- 2 -> 1 18 assert_equal(a:poll(1), true); -- 2 -> 1
27 assert_equal(a:poll(1), true); -- 1 -> 0 19 assert_equal(a:poll(1), true); -- 1 -> 0
28 assert_equal(a:poll(1), false); -- MEEP, out of credits! 20 assert_equal(a:poll(1), false); -- MEEP, out of credits!