diff options
author | Oscar Lim <olim@ucla.edu> | 2016-02-21 21:42:04 -0800 |
---|---|---|
committer | Oscar Lim <olim@ucla.edu> | 2016-02-21 22:01:26 -0800 |
commit | cbea9c7432f9cdd12797ef32b1316f7a534b280a (patch) | |
tree | 13417fe79664e7edc40d423eeecff3a1cdd9e147 /spec | |
parent | 5aac9ad8c9760f264ce529e18e29e0a82a8a063a (diff) | |
download | luasystem-cbea9c7432f9cdd12797ef32b1316f7a534b280a.zip |
Make test for `gettime` more robust
Diffstat (limited to 'spec')
-rw-r--r-- | spec/time_spec.lua | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/spec/time_spec.lua b/spec/time_spec.lua index 8bee5f7..c9d3d6d 100644 --- a/spec/time_spec.lua +++ b/spec/time_spec.lua @@ -2,7 +2,14 @@ local system = require 'system.core' describe('Test time functions', function() it('gettime returns current time', function() - assert.is_near(os.time(), system.gettime(), 1.0) + local starttime = system.gettime() + local expected = os.time() + local endtime = system.gettime() + local delta = endtime - starttime + local avg = starttime + delta/2 + assert.is_true(expected >= math.floor(starttime)) + assert.is_true(expected <= math.ceil(endtime)) + assert.is_near(expected, avg, 1 + delta) end) it('sleep will wait for specified amount of time', function() |