Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: tracing/tracing/base/sorted_array_utils_test.html

Issue 2771723003: [tracing] Move math utilities from base into their own subdirectory (attempt 2) (Closed)
Patch Set: rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tracing/tracing/base/sorted_array_utils.html ('k') | tracing/tracing/base/statistics.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <!-- 2 <!--
3 Copyright (c) 2014 The Chromium Authors. All rights reserved. 3 Copyright (c) 2014 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be 4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file. 5 found in the LICENSE file.
6 --> 6 -->
7 <link rel="import" href="/tracing/base/sorted_array_utils.html"> 7 <link rel="import" href="/tracing/base/math/sorted_array_utils.html">
8 <script> 8 <script>
9 'use strict'; 9 'use strict';
10 10
11 tr.b.unittest.testSuite(function() { 11 tr.b.unittest.testSuite(function() {
12 var ArrayOfIntervals = function(array) { 12 var ArrayOfIntervals = function(array) {
13 this.array = array; 13 this.array = array;
14 }; 14 };
15 15
16 ArrayOfIntervals.prototype = { 16 ArrayOfIntervals.prototype = {
17 17
18 get: function(index) { 18 get: function(index) {
19 return this.array[index]; 19 return this.array[index];
20 }, 20 },
21 21
22 findLowElementIndex: function(ts) { 22 findLowElementIndex: function(ts) {
23 return tr.b.findLowIndexInSortedArray( 23 return tr.b.math.findLowIndexInSortedArray(
24 this.array, 24 this.array,
25 function(x) { return x.lo; }, 25 function(x) { return x.lo; },
26 ts); 26 ts);
27 }, 27 },
28 28
29 findIntervalIndex: function(ts) { 29 findIntervalIndex: function(ts) {
30 return tr.b.findIndexInSortedIntervals( 30 return tr.b.math.findIndexInSortedIntervals(
31 this.array, 31 this.array,
32 function(x) { return x.lo; }, 32 function(x) { return x.lo; },
33 function(x) { return x.hi - x.lo; }, 33 function(x) { return x.hi - x.lo; },
34 ts); 34 ts);
35 }, 35 },
36 36
37 findIndexInClosedIntervals: function(ts) { 37 findIndexInClosedIntervals: function(ts) {
38 return tr.b.findIndexInSortedClosedIntervals( 38 return tr.b.math.findIndexInSortedClosedIntervals(
39 this.array, 39 this.array,
40 function(x) { return x.lo; }, 40 function(x) { return x.lo; },
41 function(x) { return x.hi; }, 41 function(x) { return x.hi; },
42 ts); 42 ts);
43 }, 43 },
44 44
45 findIntersectingIntervals: function(tsA, tsB) { 45 findIntersectingIntervals: function(tsA, tsB) {
46 var array = this.array; 46 var array = this.array;
47 var result = []; 47 var result = [];
48 tr.b.iterateOverIntersectingIntervals( 48 tr.b.math.iterateOverIntersectingIntervals(
49 this.array, 49 this.array,
50 function(x) { return x.lo; }, 50 function(x) { return x.lo; },
51 function(x) { return x.hi - x.lo; }, 51 function(x) { return x.hi - x.lo; },
52 tsA, 52 tsA,
53 tsB, 53 tsB,
54 function(x) { result.push(array.indexOf(x)); }); 54 function(x) { result.push(array.indexOf(x)); });
55 return result; 55 return result;
56 }, 56 },
57 57
58 findClosestElement: function(ts, tsDiff) { 58 findClosestElement: function(ts, tsDiff) {
59 return tr.b.findClosestElementInSortedArray( 59 return tr.b.math.findClosestElementInSortedArray(
60 this.array, 60 this.array,
61 function(x) { return x.lo; }, 61 function(x) { return x.lo; },
62 ts, 62 ts,
63 tsDiff); 63 tsDiff);
64 }, 64 },
65 65
66 findClosestInterval: function(ts, tsDiff) { 66 findClosestInterval: function(ts, tsDiff) {
67 return tr.b.findClosestIntervalInSortedIntervals( 67 return tr.b.math.findClosestIntervalInSortedIntervals(
68 this.array, 68 this.array,
69 function(x) { return x.lo; }, 69 function(x) { return x.lo; },
70 function(x) { return x.hi; }, 70 function(x) { return x.hi; },
71 ts, 71 ts,
72 tsDiff); 72 tsDiff);
73 } 73 }
74 }; 74 };
75 75
76 test('findLowElementIndex', function() { 76 test('findLowElementIndex', function() {
77 var array = new ArrayOfIntervals([ 77 var array = new ArrayOfIntervals([
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 assert.equal(array.get(1), array.findClosestInterval(30, 0)); 230 assert.equal(array.get(1), array.findClosestInterval(30, 0));
231 assert.equal(array.get(1), array.findClosestInterval(35, 10)); 231 assert.equal(array.get(1), array.findClosestInterval(35, 10));
232 assert.equal(array.get(1), array.findClosestInterval(50, 100)); 232 assert.equal(array.get(1), array.findClosestInterval(50, 100));
233 233
234 assert.isNull(array.findClosestInterval(50, 19)); 234 assert.isNull(array.findClosestInterval(50, 19));
235 assert.isNull(array.findClosestInterval(100, 50)); 235 assert.isNull(array.findClosestInterval(100, 50));
236 assert.isNull(array.findClosestInterval(50, -100)); 236 assert.isNull(array.findClosestInterval(50, -100));
237 }); 237 });
238 }); 238 });
239 </script> 239 </script>
OLDNEW
« no previous file with comments | « tracing/tracing/base/sorted_array_utils.html ('k') | tracing/tracing/base/statistics.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698