toolkit/devtools/sourcemap/tests/unit/test_binary_search.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial