<commit_before>'use strict';

var util     = require('util');
var inherits = util.inherits;
var format   = util.format;

var objectAssign = require('object-assign');
var assert       = require('assert');
var EventEmitter = require('events').EventEmitter;

var asserts = require('./utils/asserts.js');
var logger  = require('./utils/ThaliLogger')('TestFramework');

var TestDevice = require('./TestDevice');


// Base for classes that manage collections of devices and associated tests.
function TestFramework(options) {
  var self = this;

  TestFramework.super_.call(this);

  this._setOptions(options);

  var devices    = this._options.devices;
  var minDevices = this._options.minDevices;
  this.platforms = Object.keys(devices)
  .reduce(function (platforms, platformName) {
    var count    = devices[platformName];
    var minCount = minDevices[platformName];
    asserts.isNumber(count);
    asserts.isNumber(minCount);

    if (count === -1) {
      var timeout = self._options.waiting_for_devices_timeout;
      asserts.isNumber(timeout);
      setTimeout(function () {
        self.startTests(platformName);
      }, timeout);
    }

    if (count === -1 || count > 0) {
      platforms[platformName] = {
        count: count,
        minCount: minCount,
        devices: [],
        deviceIndexes: {},
        state: TestFramework.platformStates.created
      };
    }
    return platforms;
  }, {});
}

inherits(TestFramework, EventEmitter);

TestFramework.platformStates = {
  created:   'created',
  started:   'started',
  succeeded: 'succeeded',
  failed:    'failed'
}

TestFramework.prototype._setOptions = function (options) {
  var self = this;

  // 'options' provided by the user.
  // Tells us how many devices we need.
  this._options = objectAssign({}, options);

  asserts.isObject(this._options);
  asserts.isObject(this._options.devices);

  // 'this._options.devices' is options for our required platforms.
  var platformNames = Object.keys(this._options.devices);
  assert(
    platformNames.length > 0,
    '\'platformNames\' should not be an empty array'
  );
  platformNames.forEach(function (platformName) {
    asserts.isString(platformName);
    asserts.isNumber(self._options.devices[platformName]);
  });

  // 'minDevices' is options for all our desired platforms.
  asserts.isObject(this._options.minDevices);
  var minPlatformNames = Object.keys(this._options.minDevices);
  minPlatformNames.forEach(function (platformName) {
    asserts.isString(platformName);
    asserts.isNumber(self._options.minDevices[platformName]);
  });

  // Required platforms can not be equals to desiged platforms.
  // Required platforms should be included in desired platforms.
  // For example: desired platforms are [ 'android', 'desktop', 'ios' ],
  //   required platforms are [ 'android', 'ios' ].
  platformNames.forEach(function (platformName) {
    asserts.isNumber(self._options.minDevices[platformName]);
  });
}

TestFramework.prototype.addDevice = function (device) {
  asserts.instanceOf(device, TestDevice);

  var platform = this.platforms[device.platformName];
  asserts.isObject(platform);

  var devices = platform.devices;
  var deviceIndexes = platform.deviceIndexes;
  var count = platform.count;

  if (!device.hasRequiredHardware) {
    logger.info(
      'disqualifying device with unsupported hardware, name: \'%s\'',
      device.name
    );
    device.disqualify();
    // We can require less devices.
    if (count > 0) {
      count --;
    }
    return;<commit_msg>cosmetics<commit_after>'use strict';

var util     = require('util');
var inherits = util.inherits;
var format   = util.format;

var objectAssign = require('object-assign');
var assert       = require('assert');
var EventEmitter = require('events').EventEmitter;

var asserts = require('./utils/asserts.js');
var logger  = require('./utils/ThaliLogger')('TestFramework');

var TestDevice = require('./TestDevice');


// Base for classes that manage collections of devices and associated tests.
function TestFramework(options) {
  var self = this;

  TestFramework.super_.call(this);

  this._setOptions(options);

  var devices    = this._options.devices;
  var minDevices = this._options.minDevices;
  this.platforms = Object.keys(devices)
  .reduce(function (platforms, platformName) {
    var count    = devices[platformName];
    var minCount = minDevices[platformName];
    asserts.isNumber(count);
    asserts.isNumber(minCount);

    if (count === -1) {
      var timeout = self._options.waiting_for_devices_timeout;
      asserts.isNumber(timeout);
      setTimeout(function () {
        self.startTests(platformName);
      }, timeout);
    }

    if (count === -1 || count > 0) {
      platforms[platformName] = {
        count: count,
        minCount: minCount,
        devices: [],
        deviceIndexes: {},
        state: TestFramework.platformStates.created
      };
    }
    return platforms;
  }, {});
}

inherits(TestFramework, EventEmitter);

TestFramework.platformStates = {
  created:   'created',
  started:   'started',
  succeeded: 'succeeded',
  failed:    'failed'
}

TestFramework.prototype._setOptions = function (options) {
  var self = this;

  // 'options' provided by the user.
  // Tells us how many devices we need.
  this._options = objectAssign({}, options);

  asserts.isObject(this._options);
  asserts.isObject(this._options.devices);

  // 'this._options.devices' is options for our required platforms.
  var platformNames = Object.keys(this._options.devices);
  assert(
    platformNames.length > 0,
    '\'platformNames\' should not be an empty array'
  );
  platformNames.forEach(function (platformName) {
    asserts.isString(platformName);
    asserts.isNumber(self._options.devices[platformName]);
  });

  // 'minDevices' is options for all our desired platforms.
  asserts.isObject(this._options.minDevices);
  var minPlatformNames = Object.keys(this._options.minDevices);
  minPlatformNames.forEach(function (platformName) {
    asserts.isString(platformName);
    asserts.isNumber(self._options.minDevices[platformName]);
  });

  // Required platforms can not be equal to desired platforms.
  // Required platforms should be included in desired platforms.
  // For example: desired platforms are [ 'android', 'desktop', 'ios' ],
  //   required platforms are [ 'android', 'ios' ].
  platformNames.forEach(function (platformName) {
    asserts.isNumber(self._options.minDevices[platformName]);
  });
}

TestFramework.prototype.addDevice = function (device) {
  asserts.instanceOf(device, TestDevice);

  var platform = this.platforms[device.platformName];
  asserts.isObject(platform);

  var devices = platform.devices;
  var deviceIndexes = platform.deviceIndexes;
  var count = platform.count;

  if (!device.hasRequiredHardware) {
    logger.info(
      'disqualifying device with unsupported hardware, name: \'%s\'',
      device.name
    );
    device.disqualify();
    // We can require less devices.
    if (count > 0) {
      count --;
    }
    return;
{'fraction_non_alphanumeric': 0.12626190814730556, 'fraction_numerical': 0.0014218683349921798, 'mean_word_length': 3.6003924133420537, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '906848', 'n_tokens_mistral': 2075, 'n_tokens_neox': 2040, 'n_words': 477}