<commit_before>// Load in dependencies
var assert = require('assert');
var expect = require('chai').expect;
var config = require('./config');
var spritesmithUtils = require('./utils/spritesmith');

// Define our tests
exports._interpretImage = function (singleImage) {
  return function _interpretImageFn (params) {
    describe(params.engineName, function () {
      describe('interpretting an ' + singleImage.ext + ' image file', function () {
        spritesmithUtils.interpretImages(params.engine, singleImage.filepaths);

        it('gathers statistics', function () {
          // Fallback images and grab first one
          var imgs = this.imgs || [];
          var img = imgs[0];

          // Assert against image
          expect(img).to.have.property('height', singleImage.height);
          expect(img).to.have.property('width', singleImage.width);
        });
      });
    });
  };
};
exports.interpretPngImage = exports._interpretImage(config.singlePngImage);
exports.interpretJpgImage = exports._interpretImage(config.singleJpgImage);
exports.interpretGifImage = exports._interpretImage(config.singleGifImage);

exports._renderCanvas = function (multipleImages) {
  return function _renderCanvasFn (params) {
    describe(params.engineName, function () {
      describe('parsing multiple ' + multipleImages.ext + ' images', function () {
        spritesmithUtils.interpretImages(params.engine, multipleImages.filepaths);

        describe('rendering them into a canvas', function () {
          // Render the canvas into a binary image string
          spritesmithUtils.renderCanvas({
            engine: params.engine,
            width: multipleImages.width,
            height: multipleImages.height,
            coordinateArr: multipleImages.coordinateArr,
            exportParams: {
              format: multipleImages.ext
            }
          });

          // Allow for debugging
          if (process.env.TEST_DEBUG) {
            spritesmithUtils.debugResult();
          }

          // Load pixels for comparison
          spritesmithUtils.loadActualPixels(multipleImages.type);
          spritesmithUtils.loadExpectedPixels(multipleImages.expectedImage, multipleImages.type);

          it('can output an image', function () {
            // Localize pixel info
            var actualPixels = this.actualPixels;
            var expectedPixels = this.expectedPixels;

            // Compare pixels
            var i = 0;
            var len = actualPixels.length;
            assert.notEqual(len, undefined, 'Expected `len` to not be `undefined`');
            assert.notEqual(actualPixels[0], undefined, 'Expected `actualPixels[0]` to not be `undefined`');
            assert.notEqual(expectedPixels[0], undefined, 'Expected `expectedPixels[0]` to not be `undefined`');
            for (; i < len; i++) {
              // If the pixels did not match, complain and throw
              var pixelsWithinThreshold = Math.abs(expectedPixels[i] - actualPixels[i]) <= 10;
              expect(pixelsWithinThreshold).to.equal(true,
                'Expected ' + expectedPixels[i] + ' and ' + actualPixels[i] + ' ' +
                'to be at most 10 apart. Index was ' + i);
            }
          });
        });
      });
    });
  };
};

exports.interpretManyPngImages = function (params) {
  describe(params.engineName, function () {
    describe('interpretting a ridiculous amount of png images', function () {
      // Interpret an array of 500 images
      var manyPngImages = config.manyPngImages;
      spritesmithUtils.interpretImages(params.engine, manyPngImages.filepaths);<commit_msg>Added missing test cases<commit_after>// Load in dependencies
var assert = require('assert');
var expect = require('chai').expect;
var config = require('./config');
var spritesmithUtils = require('./utils/spritesmith');

// Define our tests
exports._interpretImage = function (singleImage) {
  return function _interpretImageFn (params) {
    describe(params.engineName, function () {
      describe('interpretting an ' + singleImage.ext + ' image file', function () {
        spritesmithUtils.interpretImages(params.engine, singleImage.filepaths);

        it('gathers statistics', function () {
          // Fallback images and grab first one
          var imgs = this.imgs || [];
          var img = imgs[0];

          // Assert against image
          expect(img).to.have.property('height', singleImage.height);
          expect(img).to.have.property('width', singleImage.width);
        });
      });
    });
  };
};
exports.interpretPngImage = exports._interpretImage(config.singlePngImage);
exports.interpretJpgImage = exports._interpretImage(config.singleJpgImage);
exports.interpretGifImage = exports._interpretImage(config.singleGifImage);

exports._renderCanvas = function (multipleImages) {
  return function _renderCanvasFn (params) {
    describe(params.engineName, function () {
      describe('parsing multiple ' + multipleImages.ext + ' images', function () {
        spritesmithUtils.interpretImages(params.engine, multipleImages.filepaths);

        describe('rendering them into a canvas', function () {
          // Render the canvas into a binary image string
          spritesmithUtils.renderCanvas({
            engine: params.engine,
            width: multipleImages.width,
            height: multipleImages.height,
            coordinateArr: multipleImages.coordinateArr,
            exportParams: {
              format: multipleImages.ext
            }
          });

          // Allow for debugging
          if (process.env.TEST_DEBUG) {
            spritesmithUtils.debugResult();
          }

          // Load pixels for comparison
          spritesmithUtils.loadActualPixels(multipleImages.type);
          spritesmithUtils.loadExpectedPixels(multipleImages.expectedImage, multipleImages.type);

          it('can output an image', function () {
            // Localize pixel info
            var actualPixels = this.actualPixels;
            var expectedPixels = this.expectedPixels;

            // Compare pixels
            var i = 0;
            var len = actualPixels.length;
            assert.notEqual(len, undefined, 'Expected `len` to not be `undefined`');
            assert.notEqual(actualPixels[0], undefined, 'Expected `actualPixels[0]` to not be `undefined`');
            assert.notEqual(expectedPixels[0], undefined, 'Expected `expectedPixels[0]` to not be `undefined`');
            for (; i < len; i++) {
              // If the pixels did not match, complain and throw
              var pixelsWithinThreshold = Math.abs(expectedPixels[i] - actualPixels[i]) <= 10;
              expect(pixelsWithinThreshold).to.equal(true,
                'Expected ' + expectedPixels[i] + ' and ' + actualPixels[i] + ' ' +
                'to be at most 10 apart. Index was ' + i);
            }
          });
        });
      });
    });
  };
};
exports.renderPngCanvas = exports._interpretImage(config.multiplePngImages);
exports.renderJpgCanvas = exports._interpretImage(config.multipleJpgImages);
exports.renderGifCanvas = exports._interpretImage(config.multipleGifImages);

exports.interpretManyPngImages = function (params) {
  describe(params.engineName, function () {
    describe('interpretting a ridiculous amount of png images', function () {
      // Interpret an array of 500 images
      var manyPngImages = config.manyPngImages;
      spritesmithUtils.interpretImages(params.engine, manyPngImages.filepaths);
{'fraction_non_alphanumeric': 0.11068090787716955, 'fraction_numerical': 0.003471295060080107, 'mean_word_length': 2.6756624141315015, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6049938', 'n_tokens_mistral': 1996, 'n_tokens_neox': 1907, 'n_words': 450}