<commit_before>'use strict';

var test = require('tap').test;
var tileReduce = require('../src');
var path = require('path');
var fs = require('fs');
var split = require('binary-split');

var sources = [
  {name: 'osm', mbtiles: path.join(__dirname, '/fixtures/osm.mbtiles'), raw: true},
  {name: 'tiger', mbtiles: path.join(__dirname, '/fixtures/tiger.mbtiles'), raw: true}
];

var remoteSources = [
  {name: 'osm', url: 'https://b.tiles.mapbox.com/v4/morganherlocker.3vsvfjjw/{z}/{x}/{y}.vector.pbf?access_token=<KEY>', raw: true},
  {name: 'tiger', url: 'https://b.tiles.mapbox.com/v4/morganherlocker.4c81vjdd/{z}/{x}/{y}.vector.pbf?access_token=<KEY>', raw: true}
];

var mapPath = path.join(__dirname, 'fixtures/count.js');

test('count implementation, bbox cover', function(t) {
  var numFeatures = 0;
  var startFired = false;
  var reduceFired = false;

  tileReduce({
    bbox: [-122.05862045288086, 36.93768132842635, -121.97296142578124, 37.00378647456494],
    zoom: 15,
    map: mapPath,
    sources: sources,
    log: false
  })
  .on('start', function() {
    startFired = true;
  })
  .on('reduce', function(num) {
    numFeatures += num;
    reduceFired = true;
  })
  .on('end', function() {
    t.equal(numFeatures, 16182, 'found all features in given bbox');
    t.equal(startFired, true, 'start fired');
    t.equal(reduceFired, true, 'reduce fired');
    t.end();
  });
});

test('count implementation, mbtiles cover', function(t) {
  var numFeatures = 0;

  tileReduce({
    zoom: 15,
    map: mapPath,
    sources: sources,
    log: false
  })
  .on('reduce', function(num) {
    numFeatures += num;
  })
  .on('end', function() {
    t.equal(numFeatures, 36597, 'found all features in overlapping mbtiles');
    t.end();
  });
});

test('count implementation, tileStream cover', function(t) {
  var numFeatures = 0;
<commit_msg>add test for sourceCover<commit_after>'use strict';

var test = require('tap').test;
var tileReduce = require('../src');
var path = require('path');
var fs = require('fs');
var split = require('binary-split');

var sources = [
  {name: 'osm', mbtiles: path.join(__dirname, '/fixtures/osm.mbtiles'), raw: true},
  {name: 'tiger', mbtiles: path.join(__dirname, '/fixtures/tiger.mbtiles'), raw: true}
];

var remoteSources = [
  {name: 'osm', url: 'https://b.tiles.mapbox.com/v4/morganherlocker.3vsvfjjw/{z}/{x}/{y}.vector.pbf?access_token=<KEY>', raw: true},
  {name: 'tiger', url: 'https://b.tiles.mapbox.com/v4/morganherlocker.4c81vjdd/{z}/{x}/{y}.vector.pbf?access_token=<KEY>', raw: true}
];

var mapPath = path.join(__dirname, 'fixtures/count.js');

test('count implementation, bbox cover', function(t) {
  var numFeatures = 0;
  var startFired = false;
  var reduceFired = false;

  tileReduce({
    bbox: [-122.05862045288086, 36.93768132842635, -121.97296142578124, 37.00378647456494],
    zoom: 15,
    map: mapPath,
    sources: sources,
    log: false
  })
  .on('start', function() {
    startFired = true;
  })
  .on('reduce', function(num) {
    numFeatures += num;
    reduceFired = true;
  })
  .on('end', function() {
    t.equal(numFeatures, 16182, 'found all features in given bbox');
    t.equal(startFired, true, 'start fired');
    t.equal(reduceFired, true, 'reduce fired');
    t.end();
  });
});

test('count implementation, mbtiles cover', function(t) {
  var numFeatures = 0;

  tileReduce({
    zoom: 15,
    map: mapPath,
    sources: sources,
    log: false
  })
  .on('reduce', function(num) {
    numFeatures += num;
  })
  .on('end', function() {
    t.equal(numFeatures, 36597, 'found all features in overlapping mbtiles');
    t.end();
  });
});

test('count implementation, explicit mbtiles cover', function(t) {
  var numFeatures = 0;

  tileReduce({
    zoom: 15,
    map: mapPath,
    sources: sources,
    sourceCover: 'tiger',
    log: false
  })
  .on('reduce', function(num) {
    numFeatures += num;
  })
  .on('end', function() {
    t.equal(numFeatures, 36597, 'found all features in overlapping mbtiles');
    t.end();
  });
});

test('count implementation, tileStream cover', function(t) {
  var numFeatures = 0;

{'fraction_non_alphanumeric': 0.1828793774319066, 'fraction_numerical': 0.045233463035019454, 'mean_word_length': 3.8274647887323945, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 4, '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': '2313248', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1507, 'n_words': 334}