Initial commit
[yaffs-website] / node_modules / performance-now / test / performance-now.coffee
1 assert = require "assert"
2
3 delay = (ms, fn) -> setTimeout fn, ms
4 now = undefined
5 describe "now", ->
6   it "initially gives a near zero (< 20 ms) time ", ->
7     now = require "../"
8     assert now() < 20
9     
10   it "gives a positive time", ->
11     assert now() > 0
12
13   it "two subsequent calls return an increasing number", ->
14     a = now()
15     b = now()      
16     assert now() < now()
17     
18   it "has less than 10 microseconds overhead", ->
19     Math.abs(now() - now()) < 0.010
20   
21   it "can do 1,000,000 calls really quickly", ->
22     now() for i in [0...1000000]
23     
24   it "shows that at least 990 ms has passed after a timeout of 1 second", (done) ->
25     a = now()
26     delay 1000, ->
27       b = now()
28       diff = b - a
29       return done new Error "Diff (#{diff}) lower than 990." if diff < 990
30       return done null
31
32   it "shows that not more than 1020 ms has passed after a timeout of 1 second", (done) ->
33     a = now()
34     delay 1000, ->
35       b = now()
36       diff = b - a
37       return done new Error "Diff (#{diff}) higher than 1020." if diff > 1020
38       return done null