<commit_before>var _ = require('underscore'),
  bag = require('bagofholding'),
  sandbox = require('sandboxed-module'),
  should = require('should'),
  checks, mocks,
  functions;

describe('functions', function () {

  function create(checks, mocks) {
    return sandbox.require('../lib/functions', {
      requires: mocks ? mocks.requires : {},
      globals: {}
    });
  }

  beforeEach(function () {
    checks = {};
    mocks = {};
    functions = require('../lib/functions');
  });

  describe('integer', function () {

    it('should evaluate integer function when it has no argument', function (done) {
      functions.integer(function (data) {
        checks.data = data;
        done();
      });
      (_.isNaN(checks.data)).should.equal(false);
      checks.data.should.not.match(/.+\..+/);
    });

    it('should evaluate ranged integer function when it has min max arguments', function (done) {
      functions.integer(100, 200, function (data) {
        checks.data = data;
        done();
      });
      (_.isNaN(checks.data)).should.equal(false);
      checks.data.should.not.match(/.+\..+/);
      parseInt(checks.data, 10).should.be.within(100, 200);
    });

    it('should evaluate identical integer function when it has identical min max arguments', function (done) {
      functions.integer(100, 100, function (data) {
        checks.data = data;
        done();
      });
      (_.isNaN(checks.data)).should.equal(false);
      checks.data.should.not.match(/.+\..+/);
      parseInt(checks.data, 10).should.equal(100);
    });
  });

  describe('float', function () {
  });

  describe('date', function () {
  });

  describe('select', function () {
  });

  describe('word', function () {
  });

  describe('firstName', function () {
  });

  describe('lastName', function () {<commit_msg>Add tests for non-integer funcs.<commit_after>var _ = require('underscore'),
  bag = require('bagofholding'),
  sandbox = require('sandboxed-module'),
  should = require('should'),
  checks, mocks,
  functions;

describe('functions', function () {

  function create(checks, mocks) {
    return sandbox.require('../lib/functions', {
      requires: mocks ? mocks.requires : {},
      globals: {}
    });
  }

  beforeEach(function () {
    checks = {};
    mocks = {};
    functions = require('../lib/functions');
  });

  describe('integer', function () {

    it('should evaluate integer function when it has no argument', function (done) {
      functions.integer(function (data) {
        checks.data = data;
        done();
      });
      (_.isNaN(checks.data)).should.equal(false);
      checks.data.should.not.match(/.+\..+/);
    });

    it('should evaluate ranged integer function when it has min max arguments', function (done) {
      functions.integer(100, 200, function (data) {
        checks.data = data;
        done();
      });
      (_.isNaN(checks.data)).should.equal(false);
      checks.data.should.not.match(/.+\..+/);
      checks.data.should.be.within(100, 200);
    });

    it('should evaluate identical integer function when it has identical min max arguments', function (done) {
      functions.integer(100, 100, function (data) {
        checks.data = data;
        done();
      });
      (_.isNaN(checks.data)).should.equal(false);
      checks.data.should.not.match(/.+\..+/);
      checks.data.should.equal(100);
    });
  });

  describe('float', function () {

    it('should evaluate float function when it has no argument', function (done) {
      functions.float(function (data) {
        checks.data = data;
        done();
      });
      (_.isNaN(checks.data)).should.equal(false);
      checks.data.should.match(/.+\..+/);
    });

    it('should evaluate ranged float function when it has min max arguments', function (done) {
      functions.float(100.0, 200.0, function (data) {
        checks.data = data;
        done();
      });
      (_.isNaN(checks.data)).should.equal(false);
      checks.data.should.match(/.+\..+/);
      checks.data.should.be.within(100.0, 200.0);
    });

    it('should evaluate identical float function when it has identical min max arguments', function (done) {
      functions.float(567.89, 567.89, function (data) {
        checks.data = data;
        done();
      });
      checks.data.should.match(/.+\..+/);
      checks.data.should.equal(567.89);
    });
  });

  describe('date', function () {

    it('should evaluate date function with ISO format when it has no argument', function (done) {
      functions.date(function (data) {
        checks.data = data;
        done();
      });
      checks.data.should.match(/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}/);
    });

    it('should evaluate date function with custom format when it has format argument', function (done) {
      functions.date('yyyy/mm/dd', function (data) {
        checks.data = data;
        done();
      });
      checks.data.should.match(/[0-9]{4}\/[0-9]{2}\/[0-9]{2}/);
    });

    it('should evaluate date function with default format and ranged date when it has min max arguments and no format argument', function (done) {
      functions.date(1998, 2000, function (data) {
        checks.data = data;
        done();
      });
      checks.data.should.match(/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}/);
      parseInt(checks.data.match(/^[0-9]{4}/), 10).should.be.within(1998, 1999);
    });

    it('should evaluate date function with custom format and ranged date when it has min max format arguments', function (done) {
      functions.date('yyyy/mm/dd', 1998, 2000, function (data) {
        checks.data = data;
        done();
      });
      checks.data.should.match(/[0-9]{4}\/[0-9]{2}\/[0-9]{2}/);
      parseInt(checks.data.match(/^[0-9]{4}/), 10).should.be.within(1998, 1999);
    });
  });

  describe('select', function () {

    it('should evaluate select function when it has arguments', function (done) {
      functions.select('aaa', 'bbb', 'ccc', function (data) {
        checks.data = data;
        done();
      });
      ['aaa','bbb','ccc'].indexOf(checks.data).should.be.within(0, 2);
    });

    it('should evaluate identical select function when it has only 1 argument', function (done) {
      functions.select('aaa', function (data) {
        checks.data = data;
        done();
      });
      ['aaa'].indexOf(checks.data).should.equal(0);
    });

    it('should evaluate to empty when select function has no argument', function (done) {
      functions.select(function (data) {
        checks.data = data;
        done();
      });
      ['aaa','bbb','ccc'].indexOf(checks.data).should.equal(-1);
    });
  });

  describe('word', function () {

    it('should evaluate a single word when word function has no argument', function (done) {
      functions.word(function (data) {
        checks.data = data;
        done();
      });
      (_.isString(checks.data)).should.equal(true);
      (checks.data.match(/[a-zA-Z]+/) !== null).should.equal(true);
    });

    it('should evaluate multiple words when word function has an argument', function (done) {
      functions.word(5, function (data) {
        checks.data = data;
        done();
      });
      function _check(word) {
        (_.isString(word)).should.equal(true);
        (word.match(/[a-zA-Z]+/) !== null).should.equal(true);
      }
      var words = checks.data.split(' ');
      words.length.should.equal(5);
      words.forEach(_check);
    });
  });

  describe('firstName', function () {

    it('should evaluate first name function', function (done) {
      functions.first_name(function (data) {
        checks.data = data;
        done();
      });
      (_.isString(checks.data)).should.equal(true);
      (checks.data.match(/[a-zA-Z]+/) !== null).should.equal(true);
    });
  });

  describe('lastName', function () {

    it('should evaluate last name function', function (done) {
      functions.last_name(function (data) {
        checks.data = data;
        done();
      });
      (_.isString(checks.data)).should.equal(true);
      (checks.data.match(/[a-zA-Z]+/) !== null).should.equal(true);
    });
{'fraction_non_alphanumeric': 0.18412307692307692, 'fraction_numerical': 0.022153846153846152, 'mean_word_length': 2.606746560142033, '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': '2050024', 'n_tokens_mistral': 2635, 'n_tokens_neox': 2434, 'n_words': 527}