|
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 */ |
|
7 |
|
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) { |
|
16 |
|
17 var binarySearch = require('source-map/binary-search'); |
|
18 |
|
19 function numberCompare(a, b) { |
|
20 return a - b; |
|
21 } |
|
22 |
|
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]; |
|
26 |
|
27 assert.doesNotThrow(function () { |
|
28 binarySearch.search(needle, haystack, numberCompare); |
|
29 }); |
|
30 |
|
31 assert.equal(binarySearch.search(needle, haystack, numberCompare), 20); |
|
32 }; |
|
33 |
|
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]; |
|
37 |
|
38 assert.doesNotThrow(function () { |
|
39 binarySearch.search(needle, haystack, numberCompare); |
|
40 }); |
|
41 |
|
42 assert.equal(binarySearch.search(needle, haystack, numberCompare), null); |
|
43 }; |
|
44 |
|
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]; |
|
48 |
|
49 assert.equal(binarySearch.search(needle, haystack, numberCompare), 4); |
|
50 }; |
|
51 |
|
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]; |
|
55 |
|
56 assert.equal(binarySearch.search(needle, haystack, numberCompare), 18); |
|
57 }; |
|
58 |
|
59 }); |
|
60 function run_test() { |
|
61 runSourceMapTests('test/source-map/test-binary-search', do_throw); |
|
62 } |