Sha256: f8bd18ec32ed10efb9ecd544f48864656f0cabb1602f24b8e02bf84f0ca097bb

Contents?: true

Size: 1.5 KB

Versions: 31

Compression:

Stored size: 1.5 KB

Contents

require("../env");
require("../../d3");

var vows = require("vows"),
    assert = require("assert");

var suite = vows.describe("d3.timer");

suite.addBatch({
  "timer": {
    topic: function() {
      return d3.timer;
    },
    "with no delay": {
      topic: timer(),
      "first calls after 17 ms or less": function(info) {
        assert.inDelta(info.start - info.scheduled, 17, 20);
      },
      "calls until the function returns true": function(info) {
        assert.equal(info.count, 4);
      },
      "calls every 17 ms": function(info) {
        assert.inDelta(info.stop - info.start, 17 * 3, 20);
      }
    },
    "with a specified delay": {
      topic: timer(250),
      "first calls after the delay": function(info) {
        assert.inDelta(info.start - info.scheduled, 250, 20);
      },
      "calls until the function returns true": function(info) {
        assert.equal(info.count, 4);
      },
      "calls every 17 ms": function(info) {
        assert.inDelta(info.stop - info.start, 17 * 3, 20);
      }
    }
  }
});

function timer(delay) {
  var args = Array.prototype.slice.call(arguments);
  return function() {
    var cb = this.callback,
        info = {scheduled: Date.now(), count: 0};

    args.unshift(function() {
      var count = ++info.count;
      if (count === 1) {
        info.start = Date.now();
      } else if (count === 4) {
        info.stop = Date.now();
        cb(null, info);
        return true;
      }
    });

    d3.timer.apply(this, args);
  };
}

suite.export(module);

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
picky-statistics-4.5.0 lib/picky-statistics/application/javascripts/d3/test/core/timer-test.js
picky-statistics-4.4.2 lib/picky-statistics/application/javascripts/d3/test/core/timer-test.js
picky-statistics-4.4.1 lib/picky-statistics/application/javascripts/d3/test/core/timer-test.js
picky-statistics-4.4.0 lib/picky-statistics/application/javascripts/d3/test/core/timer-test.js
picky-statistics-4.3.2 lib/picky-statistics/application/javascripts/d3/test/core/timer-test.js
picky-statistics-4.3.1 lib/picky-statistics/application/javascripts/d3/test/core/timer-test.js
picky-statistics-4.3.0 lib/picky-statistics/application/javascripts/d3/test/core/timer-test.js
picky-statistics-4.2.4 lib/picky-statistics/application/javascripts/d3/test/core/timer-test.js
picky-statistics-4.2.3 lib/picky-statistics/application/javascripts/d3/test/core/timer-test.js
picky-statistics-4.2.2 lib/picky-statistics/application/javascripts/d3/test/core/timer-test.js
picky-statistics-4.2.1 lib/picky-statistics/application/javascripts/d3/test/core/timer-test.js
picky-statistics-4.2.0 lib/picky-statistics/application/javascripts/d3/test/core/timer-test.js
picky-statistics-4.1.0 lib/picky-statistics/application/javascripts/d3/test/core/timer-test.js
picky-statistics-4.0.9 lib/picky-statistics/application/javascripts/d3/test/core/timer-test.js
picky-statistics-4.0.8 lib/picky-statistics/application/javascripts/d3/test/core/timer-test.js
picky-statistics-4.0.7 lib/picky-statistics/application/javascripts/d3/test/core/timer-test.js
picky-statistics-4.0.6 lib/picky-statistics/application/javascripts/d3/test/core/timer-test.js
picky-statistics-4.0.5 lib/picky-statistics/application/javascripts/d3/test/core/timer-test.js
picky-statistics-4.0.4 lib/picky-statistics/application/javascripts/d3/test/core/timer-test.js
picky-statistics-4.0.3 lib/picky-statistics/application/javascripts/d3/test/core/timer-test.js