~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tools/node_modules/source-map/test/source-map/test-binary-search.js

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-09-20 22:44:35 UTC
  • mfrom: (4.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130920224435-apuwj4fsl3fqv1a6
Tags: 1.5.6~20130920~6010666-1
* New snapshot release
* Update the list of supported architectures to the same as libv8
  (Closes: #723129)
* emlibtool has been removed from upstream.
* Fix warning syntax-error-in-dep5-copyright
* Refresh of the patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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);
 
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(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), null);
 
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(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(binarySearch.search(needle, haystack, numberCompare), 18);
 
52
  };
 
53
 
 
54
});