diff options
author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2023-11-09 23:03:21 +0100 |
---|---|---|
committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2023-11-15 19:17:57 +0100 |
commit | d45768de3e6f7b28bfecf4d19b192ccac9ce5dc2 (patch) | |
tree | 2d4f86ec87eb87a77f6663924aaaa9286756ce3e /spec/time_spec.lua | |
parent | d4222ce6da2a2d7179fc79f9d0cc65fd6c09a686 (diff) | |
download | luasystem-d45768de3e6f7b28bfecf4d19b192ccac9ce5dc2.tar.gz luasystem-d45768de3e6f7b28bfecf4d19b192ccac9ce5dc2.tar.bz2 luasystem-d45768de3e6f7b28bfecf4d19b192ccac9ce5dc2.zip |
feat(*): add environment variable and random functions
Diffstat (limited to 'spec/time_spec.lua')
-rw-r--r-- | spec/time_spec.lua | 31 |
1 files changed, 0 insertions, 31 deletions
diff --git a/spec/time_spec.lua b/spec/time_spec.lua deleted file mode 100644 index a017cfe..0000000 --- a/spec/time_spec.lua +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | local system = require 'system.core' | ||
2 | |||
3 | describe('Test time functions', function() | ||
4 | it('gettime returns current time', function() | ||
5 | local starttime = system.gettime() | ||
6 | local expected = os.time() | ||
7 | local endtime = system.gettime() | ||
8 | local delta = endtime - starttime | ||
9 | local avg = starttime + delta/2 | ||
10 | assert.is_true(expected >= math.floor(starttime)) | ||
11 | assert.is_true(expected <= math.ceil(endtime)) | ||
12 | assert.is_near(expected, avg, 1 + delta) | ||
13 | end) | ||
14 | |||
15 | it('monottime returns monotonically increasing time', function() | ||
16 | local starttime = system.monotime() | ||
17 | local endtime = system.monotime() | ||
18 | local delta = endtime - starttime | ||
19 | assert.is_true(starttime > 0) | ||
20 | assert.is_true(delta >= 0) | ||
21 | assert.is_true(system.monotime() - endtime >= 0) | ||
22 | end) | ||
23 | |||
24 | it('sleep will wait for specified amount of time', function() | ||
25 | local starttime = system.gettime() | ||
26 | local starttick = system.monotime() | ||
27 | system.sleep(0.5) | ||
28 | assert.is_near(0.5, system.gettime() - starttime, 0.15) | ||
29 | assert.is_near(0.5, system.monotime() - starttick, 0.15) | ||
30 | end) | ||
31 | end) | ||