Sha256: b9307a3dd4a6d1f928d15c1cd6ef09b2d3e4bfc5cccb2ef40ffef8b447bb5250

Contents?: true

Size: 1.51 KB

Versions: 284

Compression:

Stored size: 1.51 KB

Contents

/* -*- Mode: js; js-indent-level: 2; -*- */
/*
 * Copyright 2011 Mozilla Foundation and contributors
 * Licensed under the New BSD license. See LICENSE or:
 * http://opensource.org/licenses/BSD-3-Clause
 */
if (typeof define !== 'function') {
    var define = require('amdefine')(module, require);
}
define(function (require, exports, module) {

  var binarySearch = require('../../lib/source-map/binary-search');

  function numberCompare(a, b) {
    return a - b;
  }

  exports['test too high'] = function (assert, util) {
    var needle = 30;
    var haystack = [2,4,6,8,10,12,14,16,18,20];

    assert.doesNotThrow(function () {
      binarySearch.search(needle, haystack, numberCompare);
    });

    assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 20);
  };

  exports['test too low'] = function (assert, util) {
    var needle = 1;
    var haystack = [2,4,6,8,10,12,14,16,18,20];

    assert.doesNotThrow(function () {
      binarySearch.search(needle, haystack, numberCompare);
    });

    assert.equal(binarySearch.search(needle, haystack, numberCompare), -1);
  };

  exports['test exact search'] = function (assert, util) {
    var needle = 4;
    var haystack = [2,4,6,8,10,12,14,16,18,20];

    assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 4);
  };

  exports['test fuzzy search'] = function (assert, util) {
    var needle = 19;
    var haystack = [2,4,6,8,10,12,14,16,18,20];

    assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 18);
  };

});

Version data entries

284 entries across 173 versions & 12 rubygems

Version Path
trusty-festivity-extension-2.3.9 node_modules/bower/node_modules/handlebars/node_modules/uglify-js/node_modules/source-map/test/source-map/test-binary-search.js
trusty-festivity-extension-2.3.8 node_modules/bower/node_modules/handlebars/node_modules/uglify-js/node_modules/source-map/test/source-map/test-binary-search.js
trusty-festivity-extension-2.3.7 node_modules/bower/node_modules/handlebars/node_modules/uglify-js/node_modules/source-map/test/source-map/test-binary-search.js
trusty-festivity-extension-2.3.6 node_modules/bower/node_modules/handlebars/node_modules/uglify-js/node_modules/source-map/test/source-map/test-binary-search.js
trusty-festivity-extension-2.3.5 node_modules/bower/node_modules/handlebars/node_modules/uglify-js/node_modules/source-map/test/source-map/test-binary-search.js
trusty-festivity-extension-2.3.4 node_modules/bower/node_modules/handlebars/node_modules/uglify-js/node_modules/source-map/test/source-map/test-binary-search.js
trusty-festivity-extension-2.3.3 node_modules/bower/node_modules/handlebars/node_modules/uglify-js/node_modules/source-map/test/source-map/test-binary-search.js
trusty-festivity-extension-2.3.2 node_modules/bower/node_modules/handlebars/node_modules/uglify-js/node_modules/source-map/test/source-map/test-binary-search.js
trusty-festivity-extension-2.3.1 node_modules/bower/node_modules/handlebars/node_modules/uglify-js/node_modules/source-map/test/source-map/test-binary-search.js
trusty-festivity-extension-2.3.0 node_modules/bower/node_modules/handlebars/node_modules/uglify-js/node_modules/source-map/test/source-map/test-binary-search.js
hooch-0.4.2 jasmine/node_modules/karma/node_modules/source-map/test/source-map/test-binary-search.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/source-map/test/source-map/test-binary-search.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/source-map/test/source-map/test-binary-search.js
gulp_assets-1.0.0.pre.5 template/node_modules/gulp-sass/node_modules/vinyl-sourcemaps-apply/node_modules/source-map/test/source-map/test-binary-search.js
gulp_assets-1.0.0.pre.4 template/node_modules/gulp-sass/node_modules/vinyl-sourcemaps-apply/node_modules/source-map/test/source-map/test-binary-search.js
gulp_assets-1.0.0.pre.3 template/node_modules/gulp-sass/node_modules/vinyl-sourcemaps-apply/node_modules/source-map/test/source-map/test-binary-search.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/source-map/test/source-map/test-binary-search.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/source-map/test/source-map/test-binary-search.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/source-map/test/source-map/test-binary-search.js
hooch-0.1.0 jasmine/node_modules/karma/node_modules/source-map/test/source-map/test-binary-search.js