<commit_before>/* istanbul ignore next */
describe('ticktock', function () {
  'use strict';

  var assume = require('assume')
    , Tick = require('./')
    , tock;

  function fail() {
    throw new Error('I should never be executed');
  }

  //
  // Make sure that we do not break on missing hasOwn checks.
  //
  Object.prototype.checkHasOwn = true;

  context = { foo: 'bar' };

  beforeEach(function () {
    tock = new Tick();
  });

  afterEach(function () {
    tock.end();
  });

  this.timeout(30000);

  it('is exported as a function', function () {
    assume(Tick).is.a('function');
  });

  it('can be constructed without new', function () {
    var tick = Tick();

    assume(tick).is.instanceOf(Tick);
  });

  describe('#tock', function () {
    it('returns a function', function () {
      assume(tock.tock('name')).is.a('function');
    });

    it('is save to execute', function () {
      tock.tock('name')();
    });

    it('can execute timers', function () {
      var called = false;

      tock.setTimeout('function', function () {
        called = true;
      }, 0);

      assume(called).is.false();
      tock.tock('function', true)();
      assume(called).is.true();
    });
  });

  describe('#setInterval', function () {
    it('adds a setInterval', function (next) {
      var start = Date.now()
        , i = 0;

      tock.setInterval('test', function () {
        var taken = Date.now() - start;<commit_msg>[test] Added test for new timer methods<commit_after>/* istanbul ignore next */
describe('ticktock', function () {
  'use strict';

  var assume = require('assume')
    , Tick = require('./')
    , Timer = Tick.Timer
    , tock;

  function fail() {
    throw new Error('I should never be executed');
  }

  //
  // Make sure that we do not break on missing hasOwn checks.
  //
  Object.prototype.checkHasOwn = true;

  context = { foo: 'bar' };

  beforeEach(function () {
    tock = new Tick();
  });

  afterEach(function () {
    tock.end();
  });

  this.timeout(30000);

  it('is exported as a function', function () {
    assume(Tick).is.a('function');
  });

  it('can be constructed without new', function () {
    var tick = Tick();

    assume(tick).is.instanceOf(Tick);
  });

  describe('Timer', function () {
    describe('#taken', function () {
      it('calculates the time it has taken since first creation', function (next) {
        var timer = new Timer(undefined, undefined, 100);

        assume(timer.taken()).between(0, 1);

        setTimeout(function () {
          assume(timer.taken()).between(5, 15);
          next();
        }, 10);
      });
    });

    describe('#remaining', function () {
      it('calculates the time remaining', function (next) {
        var timer = new Timer(undefined, undefined, 100);

        assume(timer.remaining()).between(99, 100);

        setTimeout(function () {
          assume(timer.remaining()).between(25, 35);
          next();
        }, 70);
      });
    });
  });

  describe('#tock', function () {
    it('returns a function', function () {
      assume(tock.tock('name')).is.a('function');
    });

    it('is save to execute', function () {
      tock.tock('name')();
    });

    it('can execute timers', function () {
      var called = false;

      tock.setTimeout('function', function () {
        called = true;
      }, 0);

      assume(called).is.false();
      tock.tock('function', true)();
      assume(called).is.true();
    });
  });

  describe('#setInterval', function () {
    it('adds a setInterval', function (next) {
      var start = Date.now()
        , i = 0;

      tock.setInterval('test', function () {
        var taken = Date.now() - start;
{'fraction_non_alphanumeric': 0.17800054185857492, 'fraction_numerical': 0.010295312923327011, 'mean_word_length': 2.5095057034220534, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5332797', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1131, 'n_words': 276}