<commit_before>var painless = require('../../assertion/painless')
var t = painless.assert
var test = painless.createGroup('Test array/filter')

var filter = require('../../../src/array/filter')
var filterd = require('../../../src/collection/filter')

test('should filter items', function () {
  var items = [1, 2, 3, 4, 5];
  var result = filter(items, function (val, i, arr) {
    return (val % 2) !== 0;
  });
  t.same(items.length, 5); //make sure it doesn't replace original array
  t.same(result, [1, 3, 5]);
});

test('should loop all array items, even if sparse.', function () {
  var items = new Array(6);
  items[2] = 3;
  items[5] = 8;
  var count = 0;
  var result = filter(items, function (val, i, arr) {
    t.is(arr, items);
    t.is(val, items[i]);
    count += 1;
    return val % 2 === 0;
  });
  t.same(result, [8]);
  // IMPORTANT
  // ---------
  // this behavior is different than ES5 Array#filter
  t.same(count, 6);
});

test('should return empty array if no items match', function () {
  var items = [1, 2, 3, 4, 5];
  var result = filter(items, function (val, i, arr) {
    return false;
  });
  t.same(result, []);
});

test('should return empty array if target is null/undefined', function () {
  var testFunc = function () {
    return true; }
  t.same(filter(undefined, testFunc), []);
  t.same(filter(null, testFunc), []);
});
<commit_msg>update test array/filter — coverage<commit_after>var painless = require('../../assertion/painless')
var t = painless.assert
var test = painless.createGroup('Test array/filter')

var filter = require('../../../src/array/filter')
var filterd = require('../../../src/collection/filter')

test('should filter items', function () {
  var items = [1, 2, 3, 4, 5];
  var result = filter(items, function (val, i, arr) {
    return (val % 2) !== 0;
  });
  t.same(items.length, 5); //make sure it doesn't replace original array
  t.same(result, [1, 3, 5]);
});

test('should loop all array items, even if sparse.', function () {
  var items = new Array(6);
  items[2] = 3;
  items[5] = 8;
  var count = 0;
  var result = filter(items, function (val, i, arr) {
    t.is(arr, items);
    t.is(val, items[i]);
    count += 1;
    return val % 2 === 0;
  });
  t.same(result, [8]);
  // IMPORTANT
  // ---------
  // this behavior is different than ES5 Array#filter
  t.same(count, 6);
});

test('should return empty array if no items match', function () {
  var items = [1, 2, 3, 4, 5];
  var result = filter(items, function (val, i, arr) {
    return false;
  });
  t.same(result, []);
});

test('should return empty array if target is null/undefined', function () {
  var testFunc = function () {
    return true; }
  t.same(filter(undefined, testFunc), []);
  t.same(filter(null, testFunc), []);
  t.same(filterd(undefined, testFunc), undefined);
  t.same(filterd(null, testFunc), undefined);
});

{'fraction_non_alphanumeric': 0.19460973048652433, 'fraction_numerical': 0.01960098004900245, 'mean_word_length': 3.190615835777126, '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': '3276749', 'n_tokens_mistral': 1013, 'n_tokens_neox': 964, 'n_words': 298}