1 /* -*- Mode: js; js-indent-level: 2; -*- */
3 * Copyright 2011 Mozilla Foundation and contributors
4 * Licensed under the New BSD license. See LICENSE or:
5 * http://opensource.org/licenses/BSD-3-Clause
7 if (typeof define !== 'function') {
8 var define = require('amdefine')(module, require);
10 define(function (require, exports, module) {
12 var binarySearch = require('../../lib/source-map/binary-search');
14 function numberCompare(a, b) {
18 exports['test too high'] = function (assert, util) {
20 var haystack = [2,4,6,8,10,12,14,16,18,20];
22 assert.doesNotThrow(function () {
23 binarySearch.search(needle, haystack, numberCompare);
26 assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 20);
29 exports['test too low'] = function (assert, util) {
31 var haystack = [2,4,6,8,10,12,14,16,18,20];
33 assert.doesNotThrow(function () {
34 binarySearch.search(needle, haystack, numberCompare);
37 assert.equal(binarySearch.search(needle, haystack, numberCompare), -1);
40 exports['test exact search'] = function (assert, util) {
42 var haystack = [2,4,6,8,10,12,14,16,18,20];
44 assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 4);
47 exports['test fuzzy search'] = function (assert, util) {
49 var haystack = [2,4,6,8,10,12,14,16,18,20];
51 assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 18);