react / wstein / node_modules / browserify / node_modules / browser-pack / node_modules / combine-source-map / node_modules / source-map / dist / test / test_binary_search.js
80559 views/*1* WARNING!2*3* Do not edit this file directly, it is built from the sources at4* https://github.com/mozilla/source-map/5*/67Components.utils.import('resource://test/Utils.jsm');8/* -*- Mode: js; js-indent-level: 2; -*- */9/*10* Copyright 2011 Mozilla Foundation and contributors11* Licensed under the New BSD license. See LICENSE or:12* http://opensource.org/licenses/BSD-3-Clause13*/14define("test/source-map/test-binary-search", ["require", "exports", "module"], function (require, exports, module) {1516var binarySearch = require('source-map/binary-search');1718function numberCompare(a, b) {19return a - b;20}2122exports['test too high with lub bias'] = function (assert, util) {23var needle = 30;24var haystack = [2,4,6,8,10,12,14,16,18,20];2526assert.doesNotThrow(function () {27binarySearch.search(needle, haystack, numberCompare);28});2930assert.equal(binarySearch.search(needle, haystack, numberCompare), -1);31};3233exports['test too low with lub bias'] = function (assert, util) {34var needle = 1;35var haystack = [2,4,6,8,10,12,14,16,18,20];3637assert.doesNotThrow(function () {38binarySearch.search(needle, haystack, numberCompare, true);39});4041assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 2);42};4344exports['test exact search with lub bias'] = function (assert, util) {45var needle = 4;46var haystack = [2,4,6,8,10,12,14,16,18,20];4748assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 4);49};5051exports['test fuzzy search with lub bias'] = function (assert, util) {52var needle = 19;53var haystack = [2,4,6,8,10,12,14,16,18,20];5455assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 20);56};5758exports['test too high with glb bias'] = function (assert, util) {59var needle = 30;60var haystack = [2,4,6,8,10,12,14,16,18,20];6162assert.doesNotThrow(function () {63binarySearch.search(needle, haystack, numberCompare);64});6566assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare,67binarySearch.GREATEST_LOWER_BOUND)], 20);68};6970exports['test too low with glb bias'] = function (assert, util) {71var needle = 1;72var haystack = [2,4,6,8,10,12,14,16,18,20];7374assert.doesNotThrow(function () {75binarySearch.search(needle, haystack, numberCompare,76binarySearch.GREATEST_LOWER_BOUND);77});7879assert.equal(binarySearch.search(needle, haystack, numberCompare,80binarySearch.GREATEST_LOWER_BOUND), -1);81};8283exports['test exact search with glb bias'] = function (assert, util) {84var needle = 4;85var haystack = [2,4,6,8,10,12,14,16,18,20];8687assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare,88binarySearch.GREATEST_LOWER_BOUND)], 4);89};9091exports['test fuzzy search with glb bias'] = function (assert, util) {92var needle = 19;93var haystack = [2,4,6,8,10,12,14,16,18,20];9495assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare,96binarySearch.GREATEST_LOWER_BOUND)], 18);97};98});99function run_test() {100runSourceMapTests('test/source-map/test-binary-search', do_throw);101}102103104