<commit_before>const CoTest = module.exports;

const chai = require('chai');

require('../src/co');

CoTest.launchGenerator = function* launchGenerator(input1, input2) {
  chai.expect(input1).to.equal(1);
  chai.expect(input2).to.equal(2);
  return input1 + input2;
};

CoTest.launchFunction = function launchFunction(input) {
  chai.expect(input).to.equal(4);
  return input + 1;
};

CoTest.launchUndefined = function launchUndefined(input) {
  chai.expect(input).to.equal(undefined);
  return null;
};

CoTest.launchAction = input => Promise.resolve(input + 1);

CoTest.waitedFunction = function waitedFunction() {
  return 25;
};

CoTest.waitedAction = () => Promise.resolve(27);

CoTest.fastWaitForIterator = function* fastWaitForIterator() {
  const result = yield* CoTest.launchGenerator(1, 2);
  chai.expect(result).to.equal(3);
  return result + 3;
};

CoTest.waitForIterator = function* waitForIterator() {
  const result = yield CoTest.launchGenerator(1, 2);
  chai.expect(result).to.equal(3);
  return result + 3;
};

CoTest.waitForGenerator = function* waitForGenerator() {
  const result = 1 + (yield CoTest.fastWaitForIterator);
  chai.expect(result).to.equal(7);
  return result + 3;
};

CoTest.waitForFunction = function* waitForFunction() {
  const result = 1 + (yield CoTest.waitedFunction);
  chai.expect(result).to.equal(26);
  return result + 3;
};

CoTest.waitForAction = function* waitForAction() {
  const result = 1 + (yield CoTest.waitedAction);
  chai.expect(result).to.equal(28);
  return result + 3;
};

CoTest.waitForPromise = function* waitForPromise() {
  const result = 1 + (yield Promise.resolve(19));
  chai.expect(result).to.equal(20);
  return result + 3;
};

CoTest.waitForValue = function* waitForValue() {
  const result = 1 + (yield 13);
  chai.expect(result).to.equal(14);
  return result + 3;
};

CoTest.waitForFalsyValue = function* waitForFalsyValue() {
  const result = yield;
  chai.expect(result).to.equal(undefined);
  return null;
};

CoTest.waitForObject = function* waitForObject() {
  const result = yield ({
    ofIterator: CoTest.launchGenerator(1, 2),
    ofAction: CoTest.launchAction(6),
    ofPromise: Promise.resolve(81),
    ofValue: 82,
    ofFalsyValue: undefined
  });

  chai.expect(result).to.deep.equal({
    ofIterator: 3,
    ofAction: 7,
    ofPromise: 81,
    ofValue: 82,
    ofFalsyValue: undefined
  });

  return result;
};

CoTest.waitForArray = function* waitForArray() {
  const result = yield [
    CoTest.launchGenerator(1, 2),
    CoTest.launchAction(6),
    Promise.resolve(83),
    84,
    undefined
  ];

  chai.expect(result).to.deep.equal([3, 7, 83, 84, undefined]);
  return result;
};

CoTest.launchContext = function* launchContext(input) {
  return this + input;
};

CoTest.context = context;

CoTest.waitForObjectCustom = function* waitForObjectCustom() {
  const result = yield ({
    ofGenerator: CoTest.launchGenerator,
    ofContext: CoTest.launchContext,
    ofAction: CoTest.launchAction,
    ofPromise: Promise.resolve(81),
    ofValue: 82,
    ofFalsyValue: undefined
  }) [args](1, 2) [CoTest.context](3);

  chai.expect(result).to.deep.equal({
    ofGenerator: 3,
    ofContext: 4,
    ofAction: 2,
    ofPromise: 81,
    ofValue: 82,
    ofFalsyValue: undefined
  });

  return result;
};

CoTest.waitForArrayCustom = function* waitForArrayCustom() {
  const result = yield [
    CoTest.launchGenerator,
    CoTest.launchContext,
    CoTest.launchAction,
    Promise.resolve(83),
    84,
    undefined
  ] [args](1, 2) [CoTest.context](3);

  chai.expect(result).to.deep.equal([3, 4, 2, 83, 84, undefined]);
  return result;
};

CoTest.waitForDelay = function* waitForDelay() {
  const startAt = process.uptime();
  yield delay(1 / 10);
  const duration = Math.floor((process.uptime() - startAt) * 10);
  chai.expect(duration).to.equal(1);
  return duration;
};

CoTest.callbacks = {
  delay(sec, callback) {
    if (!sec) return setImmediate(callback, null, this);
    return setTimeout(callback, sec * 1000, null, this);
  }
};

CoTest.wrapped = CoTest[callbacks]('callbacks.delay');

CoTest.waitForDelayCallback = function* waitForDelayCallback() {
  const startAt = process.uptime();
  const context = yield CoTest.wrapped.callbacks.delay(1 / 10);
  const duration = Math.floor((process.uptime() - startAt) * 10);
  chai.expect(duration).to.equal(1);
  chai.expect(context).to.equal(CoTest.callbacks);<commit_msg>release 0.1.0 +delay test rounded time<commit_after>const CoTest = module.exports;

const chai = require('chai');

require('../src/co');

CoTest.launchGenerator = function* launchGenerator(input1, input2) {
  chai.expect(input1).to.equal(1);
  chai.expect(input2).to.equal(2);
  return input1 + input2;
};

CoTest.launchFunction = function launchFunction(input) {
  chai.expect(input).to.equal(4);
  return input + 1;
};

CoTest.launchUndefined = function launchUndefined(input) {
  chai.expect(input).to.equal(undefined);
  return null;
};

CoTest.launchAction = input => Promise.resolve(input + 1);

CoTest.waitedFunction = function waitedFunction() {
  return 25;
};

CoTest.waitedAction = () => Promise.resolve(27);

CoTest.fastWaitForIterator = function* fastWaitForIterator() {
  const result = yield* CoTest.launchGenerator(1, 2);
  chai.expect(result).to.equal(3);
  return result + 3;
};

CoTest.waitForIterator = function* waitForIterator() {
  const result = yield CoTest.launchGenerator(1, 2);
  chai.expect(result).to.equal(3);
  return result + 3;
};

CoTest.waitForGenerator = function* waitForGenerator() {
  const result = 1 + (yield CoTest.fastWaitForIterator);
  chai.expect(result).to.equal(7);
  return result + 3;
};

CoTest.waitForFunction = function* waitForFunction() {
  const result = 1 + (yield CoTest.waitedFunction);
  chai.expect(result).to.equal(26);
  return result + 3;
};

CoTest.waitForAction = function* waitForAction() {
  const result = 1 + (yield CoTest.waitedAction);
  chai.expect(result).to.equal(28);
  return result + 3;
};

CoTest.waitForPromise = function* waitForPromise() {
  const result = 1 + (yield Promise.resolve(19));
  chai.expect(result).to.equal(20);
  return result + 3;
};

CoTest.waitForValue = function* waitForValue() {
  const result = 1 + (yield 13);
  chai.expect(result).to.equal(14);
  return result + 3;
};

CoTest.waitForFalsyValue = function* waitForFalsyValue() {
  const result = yield;
  chai.expect(result).to.equal(undefined);
  return null;
};

CoTest.waitForObject = function* waitForObject() {
  const result = yield ({
    ofIterator: CoTest.launchGenerator(1, 2),
    ofAction: CoTest.launchAction(6),
    ofPromise: Promise.resolve(81),
    ofValue: 82,
    ofFalsyValue: undefined
  });

  chai.expect(result).to.deep.equal({
    ofIterator: 3,
    ofAction: 7,
    ofPromise: 81,
    ofValue: 82,
    ofFalsyValue: undefined
  });

  return result;
};

CoTest.waitForArray = function* waitForArray() {
  const result = yield [
    CoTest.launchGenerator(1, 2),
    CoTest.launchAction(6),
    Promise.resolve(83),
    84,
    undefined
  ];

  chai.expect(result).to.deep.equal([3, 7, 83, 84, undefined]);
  return result;
};

CoTest.launchContext = function* launchContext(input) {
  return this + input;
};

CoTest.context = context;

CoTest.waitForObjectCustom = function* waitForObjectCustom() {
  const result = yield ({
    ofGenerator: CoTest.launchGenerator,
    ofContext: CoTest.launchContext,
    ofAction: CoTest.launchAction,
    ofPromise: Promise.resolve(81),
    ofValue: 82,
    ofFalsyValue: undefined
  }) [args](1, 2) [CoTest.context](3);

  chai.expect(result).to.deep.equal({
    ofGenerator: 3,
    ofContext: 4,
    ofAction: 2,
    ofPromise: 81,
    ofValue: 82,
    ofFalsyValue: undefined
  });

  return result;
};

CoTest.waitForArrayCustom = function* waitForArrayCustom() {
  const result = yield [
    CoTest.launchGenerator,
    CoTest.launchContext,
    CoTest.launchAction,
    Promise.resolve(83),
    84,
    undefined
  ] [args](1, 2) [CoTest.context](3);

  chai.expect(result).to.deep.equal([3, 4, 2, 83, 84, undefined]);
  return result;
};

CoTest.waitForDelay = function* waitForDelay() {
  const startAt = process.uptime();
  yield delay(1 / 10);
  const duration = Math.round((process.uptime() - startAt) * 10);
  chai.expect(duration).to.equal(1);
  return duration;
};

CoTest.callbacks = {
  delay(sec, callback) {
    if (!sec) return setImmediate(callback, null, this);
    return setTimeout(callback, sec * 1000, null, this);
  }
};

CoTest.wrapped = CoTest[callbacks]('callbacks.delay');

CoTest.waitForDelayCallback = function* waitForDelayCallback() {
  const startAt = process.uptime();
  const context = yield CoTest.wrapped.callbacks.delay(1 / 10);
  const duration = Math.round((process.uptime() - startAt) * 10);
  chai.expect(duration).to.equal(1);
  chai.expect(context).to.equal(CoTest.callbacks);
{'fraction_non_alphanumeric': 0.1449847681371996, 'fraction_numerical': 0.026514724134040393, 'mean_word_length': 4.207990599294948, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5542610', 'n_tokens_mistral': 3206, 'n_tokens_neox': 2998, 'n_words': 606}