<commit_before>'use strict';

var firefoxHelper = require('./firefox_helper');

firefoxHelper(function () {
  describe('shared map tests', function(){

    var pjs;
    var utils = require('../src/utils.js');

    before(function () {
      pjs = require('../src/index.js');
      pjs.init({maxWorkers:4});
    });

    after(function(){
      if (pjs.config){
        pjs.terminate();
      }
    });

    var normalSourceArray = [1,2,3,4,5,6,7,8,9,10,11,12,13,14];
    var sourceArray = new SharedUint32Array(normalSourceArray.length);
    sourceArray.set(normalSourceArray);

    it('Should map shared array', function (done) {
      var mapper = function (e) {
        return e * 3;
      };
      pjs(sourceArray).map(mapper).seq(function (err, result) {
        if (err) { return done(err); }
        normalSourceArray.map(mapper).forEach(function (e, i) {
          expect(result[i]).to.equal(e);
        });
        done();
      });
    });

    it('Should filter shared array', function (done) {
      var predicate = function (e) {
        return e % 2 === 0;
      };
      pjs(sourceArray).filter(predicate).seq(function (err, result) {
        if (err) { return done(err); }
        normalSourceArray.filter(predicate).forEach(function (e, i) {
          expect(result[i]).to.equal(e);
        });
        done();
      });
    });

    it('Should reduce shared array', function (done) {
      var seed = 0;
      var reducer = function (p, e) {
        return p + e;
      };
      pjs(sourceArray).reduce(reducer, seed, 0).seq(function (err, result) {
        if (err) { return done(err); }
        var reduced = normalSourceArray.reduce(reducer, seed);
        expect(result).to.equal(reduced);
        done();
      });
    });
  });
});<commit_msg>adds operations tests for all kind of shared typed arrays.<commit_after>'use strict';

var firefoxHelper = require('./firefox_helper');

firefoxHelper(function () {
  describe('shared map tests', function(){

    var pjs;
    var utils = require('../src/utils.js');

    before(function () {
      pjs = require('../src/index.js');
      pjs.init({maxWorkers:4});
    });

    after(function(){
      if (pjs.config){
        pjs.terminate();
      }
    });

    [SharedUint8Array,
    SharedUint8ClampedArray,
    SharedUint16Array,
    SharedUint32Array,
    SharedInt8Array,
    SharedInt16Array,
    SharedInt32Array,
    SharedFloat32Array,
    SharedFloat64Array].forEach(function (SharedTypedArray) {
      describe(utils.format('tests for {0}', utils.getTypedArrayConstructorType(SharedTypedArray)), function(){
        var normalSourceArray = [1,2,3,4,5,6,7,8,9,10,11,12,13,14];
        var sourceArray = new SharedTypedArray(normalSourceArray.length);
        sourceArray.set(normalSourceArray);

        it('Should map shared array', function (done) {
          var mapper = function (e) {
            return e * 3;
          };
          pjs(sourceArray).map(mapper).seq(function (err, result) {
            if (err) { return done(err); }
            normalSourceArray.map(mapper).forEach(function (e, i) {
              expect(result[i]).to.equal(e);
            });
            done();
          });
        });

        it('Should filter shared array', function (done) {
          var predicate = function (e) {
            return e % 2 === 0;
          };
          pjs(sourceArray).filter(predicate).seq(function (err, result) {
            if (err) { return done(err); }
            normalSourceArray.filter(predicate).forEach(function (e, i) {
              expect(result[i]).to.equal(e);
            });
            done();
          });
        });

        it('Should reduce shared array', function (done) {
          var seed = 0;
          var reducer = function (p, e) {
            return p + e;
          };
          pjs(sourceArray).reduce(reducer, seed, 0).seq(function (err, result) {
            if (err) { return done(err); }
            var reduced = normalSourceArray.reduce(reducer, seed);
            expect(result).to.equal(reduced);
            done();
          });
        });

        it('Should map-map shared array', function (done) {
          var mapper1 = function (e) {
            return e * 3;
          };
          var mapper2 = function (e) {
            return e * 2;
          };
          pjs(sourceArray).map(mapper1).map(mapper2).seq(function (err, result) {
            if (err) { return done(err); }
            normalSourceArray.map(mapper1).map(mapper2).forEach(function (e, i) {
              expect(result[i]).to.equal(e);
            });
            done();
          });
        });

        it('Should map-filter shared array', function (done) {
          var mapper = function (e) {
            return e * 3;
          };
          var predicate = function (e) {
            return e % 2 === 0;
          };
          pjs(sourceArray).map(mapper).filter(predicate).seq(function (err, result) {
            if (err) { return done(err); }
            normalSourceArray.map(mapper).filter(predicate).forEach(function (e, i) {
              expect(result[i]).to.equal(e);
            });
            done();
          });
        });

        it('Should map-reduce shared array', function (done) {
          var mapper = function (e) {
            return e * 2;
          };
          var seed = 0;
          var reducer = function (p, e) {
            return p + e;
          };
          pjs(sourceArray).map(mapper).reduce(reducer, seed, 0).seq(function (err, result) {
            if (err) { return done(err); }
            var r = normalSourceArray.map(mapper).reduce(reducer, seed);
            expect(result).to.equal(r);
            done();
          });
        });

        it('Should filter-map shared array', function (done) {
          var predicate = function (e) {
            return e % 2 === 0;
          };
          var mapper = function (e) {
            return e * 3;
          };
          pjs(sourceArray).filter(predicate).map(mapper).seq(function (err, result) {
            if (err) { return done(err); }
            normalSourceArray.filter(predicate).map(mapper).forEach(function (e, i) {
              expect(result[i]).to.equal(e);
            });
            done();
          });
        });

        it('Should filter-filter shared array', function (done) {
          var predicate1 = function (e) {
            return e % 2 === 0;
          };
          var predicate2 = function (e) {
            return e % 3 === 0;
          };
          pjs(sourceArray).filter(predicate1).filter(predicate2).seq(function (err, result) {
            if (err) { return done(err); }
            normalSourceArray.filter(predicate1).filter(predicate2).forEach(function (e, i) {
              expect(result[i]).to.equal(e);
            });
            done();
          });
        });

        it('Should filter-reduce shared array', function (done) {
          var predicate = function (e) {
            return e % 2 === 0;
          };
          var seed = 0;
          var reducer = function (p, e) {
            return p + e;
          };
          pjs(sourceArray).filter(predicate).reduce(reducer, seed, 0).seq(function (err, result) {
            if (err) { return done(err); }
            var r = normalSourceArray.filter(predicate).reduce(reducer, seed);
            expect(result).to.equal(r);
            done();
          });
        });
      });
    });
  });
});
{'fraction_non_alphanumeric': 0.14985862393967955, 'fraction_numerical': 0.013329742830214084, 'mean_word_length': 1.8394495412844036, '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': '3594902', 'n_tokens_mistral': 2240, 'n_tokens_neox': 2160, 'n_words': 463}