react / wstein / node_modules / react / node_modules / envify / node_modules / jstransform / node_modules / source-map / test / source-map / test-binary-search.js
80559 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'] = 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), 20);26};2728exports['test too low'] = 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);34});3536assert.equal(binarySearch.search(needle, haystack, numberCompare), null);37};3839exports['test exact search'] = function (assert, util) {40var needle = 4;41var haystack = [2,4,6,8,10,12,14,16,18,20];4243assert.equal(binarySearch.search(needle, haystack, numberCompare), 4);44};4546exports['test fuzzy search'] = function (assert, util) {47var needle = 19;48var haystack = [2,4,6,8,10,12,14,16,18,20];4950assert.equal(binarySearch.search(needle, haystack, numberCompare), 18);51};5253});545556