Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /*
2 * WARNING!
3 *
4 * Do not edit this file directly, it is built from the sources at
5 * https://github.com/mozilla/source-map/
6 */
8 Components.utils.import('resource://test/Utils.jsm');
9 /* -*- Mode: js; js-indent-level: 2; -*- */
10 /*
11 * Copyright 2011 Mozilla Foundation and contributors
12 * Licensed under the New BSD license. See LICENSE or:
13 * http://opensource.org/licenses/BSD-3-Clause
14 */
15 define("test/source-map/test-binary-search", ["require", "exports", "module"], function (require, exports, module) {
17 var binarySearch = require('source-map/binary-search');
19 function numberCompare(a, b) {
20 return a - b;
21 }
23 exports['test too high'] = function (assert, util) {
24 var needle = 30;
25 var haystack = [2,4,6,8,10,12,14,16,18,20];
27 assert.doesNotThrow(function () {
28 binarySearch.search(needle, haystack, numberCompare);
29 });
31 assert.equal(binarySearch.search(needle, haystack, numberCompare), 20);
32 };
34 exports['test too low'] = function (assert, util) {
35 var needle = 1;
36 var haystack = [2,4,6,8,10,12,14,16,18,20];
38 assert.doesNotThrow(function () {
39 binarySearch.search(needle, haystack, numberCompare);
40 });
42 assert.equal(binarySearch.search(needle, haystack, numberCompare), null);
43 };
45 exports['test exact search'] = function (assert, util) {
46 var needle = 4;
47 var haystack = [2,4,6,8,10,12,14,16,18,20];
49 assert.equal(binarySearch.search(needle, haystack, numberCompare), 4);
50 };
52 exports['test fuzzy search'] = function (assert, util) {
53 var needle = 19;
54 var haystack = [2,4,6,8,10,12,14,16,18,20];
56 assert.equal(binarySearch.search(needle, haystack, numberCompare), 18);
57 };
59 });
60 function run_test() {
61 runSourceMapTests('test/source-map/test-binary-search', do_throw);
62 }