]> git.r.bdr.sh - rbdr/dotfiles/blob
f1c9e0fc56658d8ccfe270e11d9e8c55a69af6d7
[rbdr/dotfiles] /
1 /* -*- Mode: js; js-indent-level: 2; -*- */
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
6 */
7 if (typeof define !== 'function') {
8 var define = require('amdefine')(module, require);
9 }
10 define(function (require, exports, module) {
11
12 var binarySearch = require('../../lib/source-map/binary-search');
13
14 function numberCompare(a, b) {
15 return a - b;
16 }
17
18 exports['test too high'] = function (assert, util) {
19 var needle = 30;
20 var haystack = [2,4,6,8,10,12,14,16,18,20];
21
22 assert.doesNotThrow(function () {
23 binarySearch.search(needle, haystack, numberCompare);
24 });
25
26 assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 20);
27 };
28
29 exports['test too low'] = function (assert, util) {
30 var needle = 1;
31 var haystack = [2,4,6,8,10,12,14,16,18,20];
32
33 assert.doesNotThrow(function () {
34 binarySearch.search(needle, haystack, numberCompare);
35 });
36
37 assert.equal(binarySearch.search(needle, haystack, numberCompare), -1);
38 };
39
40 exports['test exact search'] = function (assert, util) {
41 var needle = 4;
42 var haystack = [2,4,6,8,10,12,14,16,18,20];
43
44 assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 4);
45 };
46
47 exports['test fuzzy search'] = function (assert, util) {
48 var needle = 19;
49 var haystack = [2,4,6,8,10,12,14,16,18,20];
50
51 assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 18);
52 };
53
54 });