react / wstein / node_modules / browserify / node_modules / insert-module-globals / node_modules / combine-source-map / node_modules / inline-source-map / node_modules / source-map / test / source-map / test-binary-search.js
80620 views/* -*- Mode: js; js-indent-level: 2; -*- */1/*2* Copyright 2011 Mozilla Foundation and contributors3* Licensed under the New BSD license. See LICENSE or:4* http://opensource.org/licenses/BSD-3-Clause5*/6if (typeof define !== 'function') {7var define = require('amdefine')(module, require);8}9define(function (require, exports, module) {1011var binarySearch = require('../../lib/source-map/binary-search');1213function numberCompare(a, b) {14return a - b;15}1617exports['test too high with lub bias'] = function (assert, util) {18var needle = 30;19var haystack = [2,4,6,8,10,12,14,16,18,20];2021assert.doesNotThrow(function () {22binarySearch.search(needle, haystack, numberCompare);23});2425assert.equal(binarySearch.search(needle, haystack, numberCompare), -1);26};2728exports['test too low with lub bias'] = function (assert, util) {29var needle = 1;30var haystack = [2,4,6,8,10,12,14,16,18,20];3132assert.doesNotThrow(function () {33binarySearch.search(needle, haystack, numberCompare, true);34});3536assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 2);37};3839exports['test exact search with lub bias'] = function (assert, util) {40var needle = 4;41var haystack = [2,4,6,8,10,12,14,16,18,20];4243assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 4);44};4546exports['test fuzzy search with lub bias'] = function (assert, util) {47var needle = 19;48var haystack = [2,4,6,8,10,12,14,16,18,20];4950assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 20);51};5253exports['test too high with glb bias'] = function (assert, util) {54var needle = 30;55var haystack = [2,4,6,8,10,12,14,16,18,20];5657assert.doesNotThrow(function () {58binarySearch.search(needle, haystack, numberCompare);59});6061assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare,62binarySearch.GREATEST_LOWER_BOUND)], 20);63};6465exports['test too low with glb bias'] = function (assert, util) {66var needle = 1;67var haystack = [2,4,6,8,10,12,14,16,18,20];6869assert.doesNotThrow(function () {70binarySearch.search(needle, haystack, numberCompare,71binarySearch.GREATEST_LOWER_BOUND);72});7374assert.equal(binarySearch.search(needle, haystack, numberCompare,75binarySearch.GREATEST_LOWER_BOUND), -1);76};7778exports['test exact search with glb bias'] = function (assert, util) {79var needle = 4;80var haystack = [2,4,6,8,10,12,14,16,18,20];8182assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare,83binarySearch.GREATEST_LOWER_BOUND)], 4);84};8586exports['test fuzzy search with glb bias'] = function (assert, util) {87var needle = 19;88var haystack = [2,4,6,8,10,12,14,16,18,20];8990assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare,91binarySearch.GREATEST_LOWER_BOUND)], 18);92};93});949596