michael@0: /* michael@0: * WARNING! michael@0: * michael@0: * Do not edit this file directly, it is built from the sources at michael@0: * https://github.com/mozilla/source-map/ michael@0: */ michael@0: michael@0: Components.utils.import('resource://test/Utils.jsm'); michael@0: /* -*- Mode: js; js-indent-level: 2; -*- */ michael@0: /* michael@0: * Copyright 2011 Mozilla Foundation and contributors michael@0: * Licensed under the New BSD license. See LICENSE or: michael@0: * http://opensource.org/licenses/BSD-3-Clause michael@0: */ michael@0: define("test/source-map/test-binary-search", ["require", "exports", "module"], function (require, exports, module) { michael@0: michael@0: var binarySearch = require('source-map/binary-search'); michael@0: michael@0: function numberCompare(a, b) { michael@0: return a - b; michael@0: } michael@0: michael@0: exports['test too high'] = function (assert, util) { michael@0: var needle = 30; michael@0: var haystack = [2,4,6,8,10,12,14,16,18,20]; michael@0: michael@0: assert.doesNotThrow(function () { michael@0: binarySearch.search(needle, haystack, numberCompare); michael@0: }); michael@0: michael@0: assert.equal(binarySearch.search(needle, haystack, numberCompare), 20); michael@0: }; michael@0: michael@0: exports['test too low'] = function (assert, util) { michael@0: var needle = 1; michael@0: var haystack = [2,4,6,8,10,12,14,16,18,20]; michael@0: michael@0: assert.doesNotThrow(function () { michael@0: binarySearch.search(needle, haystack, numberCompare); michael@0: }); michael@0: michael@0: assert.equal(binarySearch.search(needle, haystack, numberCompare), null); michael@0: }; michael@0: michael@0: exports['test exact search'] = function (assert, util) { michael@0: var needle = 4; michael@0: var haystack = [2,4,6,8,10,12,14,16,18,20]; michael@0: michael@0: assert.equal(binarySearch.search(needle, haystack, numberCompare), 4); michael@0: }; michael@0: michael@0: exports['test fuzzy search'] = function (assert, util) { michael@0: var needle = 19; michael@0: var haystack = [2,4,6,8,10,12,14,16,18,20]; michael@0: michael@0: assert.equal(binarySearch.search(needle, haystack, numberCompare), 18); michael@0: }; michael@0: michael@0: }); michael@0: function run_test() { michael@0: runSourceMapTests('test/source-map/test-binary-search', do_throw); michael@0: }