<commit_before>/* globals describe, it */

var assert = require('chai').assert

var geoTz = require('../index.js')
var issueCoords = require('./fixtures/issues.json')

process.chdir('/tmp')

describe('find tests', function () {

  describe('without options object', function() {
    it('should find the timezone name for a valid coordinate', function () {
      var tz = geoTz.tz(47.650499, -122.350070)
      assert.isString(tz)
      assert.equal(tz, 'America/Los_Angeles')
    })
  });

  describe('with options object', function() {
    var featureProviders = [
      { name: 'unspecified', provider: undefined },
      { name: 'preloaded', provider: geoTz.createPreloadedFeatureProvider() }
    ];

    featureProviders.forEach(function(featureProvider) {
      var options = { featureProvider: featureProvider.provider };

      describe('with ' + featureProvider.name + ' feature provider', function() {
        it('should find the timezone name for a valid coordinate', function () {
          var tz = geoTz.tz(47.650499, -122.350070, options)
          assert.isString(tz)
          assert.equal(tz, 'America/Los_Angeles')
        })

        it('should find the timezone name for a valid coordinate via subfile examination', function () {
          var tz = geoTz.tz(1.44, 104.04, options)
          assert.isString(tz)
          assert.equal(tz, 'Asia/Singapore')
        })

        it('should return null timezone name for coordinate in ocean', function () {
          var tz = geoTz.tz(0, 0, options)
          assert.isNull(tz)
        })

        it('should return a moment-timezone', function () {
          var tzMoment = geoTz.tzMoment(47.650499, -122.350070, null, options)
          assert.isObject(tzMoment)
          assert.equal(tzMoment._z.name, 'America/Los_Angeles')
        })

        it('should return null timezone moment for coordinate in ocean', function () {
          var tz = geoTz.tzMoment(0, 0, options)
          assert.isNull(tz)
        })

        it('should parse time correctly', function () {
          var tzMoment = geoTz.tzMoment(47.650499, -122.350070, '2016-03-30T01:23:45Z', options)
          assert.equal(tzMoment.format('LLLL'), 'Tuesday, March 29, 2016 6:23 PM')
        })

        describe('issue cases', function () {
          issueCoords.forEach(function (spot) {
            it('should find ' + spot.zid + ' (' + spot.description + ')', function () {
              var tz = geoTz.tz(spot.lat, spot.lon, options)
              assert.isString(tz)
              assert.equal(tz, spot.zid)
            })
          })
        })

        describe('performance aspects', function() {
          this.timeout(10000)

          var europeTopLeft = [56.432158, -11.9263934]
          var europeBottomRight = [39.8602076, 34.9127951]
          var count = 2000

          it('should find timezone of ' + count + ' random european positions', function () {
            var timingStr = 'find tz of ' + count + ' random european positions with ' + featureProvider.name
            console.time(timingStr)<commit_msg>test(find): bump up test timeout to 20s<commit_after>/* globals describe, it */

var assert = require('chai').assert

var geoTz = require('../index.js')
var issueCoords = require('./fixtures/issues.json')

process.chdir('/tmp')

describe('find tests', function () {

  describe('without options object', function() {
    it('should find the timezone name for a valid coordinate', function () {
      var tz = geoTz.tz(47.650499, -122.350070)
      assert.isString(tz)
      assert.equal(tz, 'America/Los_Angeles')
    })
  });

  describe('with options object', function() {
    var featureProviders = [
      { name: 'unspecified', provider: undefined },
      { name: 'preloaded', provider: geoTz.createPreloadedFeatureProvider() }
    ];

    featureProviders.forEach(function(featureProvider) {
      var options = { featureProvider: featureProvider.provider };

      describe('with ' + featureProvider.name + ' feature provider', function() {
        it('should find the timezone name for a valid coordinate', function () {
          var tz = geoTz.tz(47.650499, -122.350070, options)
          assert.isString(tz)
          assert.equal(tz, 'America/Los_Angeles')
        })

        it('should find the timezone name for a valid coordinate via subfile examination', function () {
          var tz = geoTz.tz(1.44, 104.04, options)
          assert.isString(tz)
          assert.equal(tz, 'Asia/Singapore')
        })

        it('should return null timezone name for coordinate in ocean', function () {
          var tz = geoTz.tz(0, 0, options)
          assert.isNull(tz)
        })

        it('should return a moment-timezone', function () {
          var tzMoment = geoTz.tzMoment(47.650499, -122.350070, null, options)
          assert.isObject(tzMoment)
          assert.equal(tzMoment._z.name, 'America/Los_Angeles')
        })

        it('should return null timezone moment for coordinate in ocean', function () {
          var tz = geoTz.tzMoment(0, 0, options)
          assert.isNull(tz)
        })

        it('should parse time correctly', function () {
          var tzMoment = geoTz.tzMoment(47.650499, -122.350070, '2016-03-30T01:23:45Z', options)
          assert.equal(tzMoment.format('LLLL'), 'Tuesday, March 29, 2016 6:23 PM')
        })

        describe('issue cases', function () {
          issueCoords.forEach(function (spot) {
            it('should find ' + spot.zid + ' (' + spot.description + ')', function () {
              var tz = geoTz.tz(spot.lat, spot.lon, options)
              assert.isString(tz)
              assert.equal(tz, spot.zid)
            })
          })
        })

        describe('performance aspects', function() {
          this.timeout(20000)

          var europeTopLeft = [56.432158, -11.9263934]
          var europeBottomRight = [39.8602076, 34.9127951]
          var count = 2000

          it('should find timezone of ' + count + ' random european positions', function () {
            var timingStr = 'find tz of ' + count + ' random european positions with ' + featureProvider.name
            console.time(timingStr)
{'fraction_non_alphanumeric': 0.12910035725885027, 'fraction_numerical': 0.04806755440077947, 'mean_word_length': 2.423568649249583, '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': '7615923', 'n_tokens_mistral': 2043, 'n_tokens_neox': 1788, 'n_words': 443}