OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <!-- |
| 3 Copyright 2016 The Chromium Authors. All rights reserved. |
| 4 Use of this source code is governed by a BSD-style license that can be |
| 5 found in the LICENSE file. |
| 6 --> |
| 7 |
| 8 <link rel="import" href="/tracing/base/utils.html"> |
| 9 <link rel="import" href="/tracing/ui/base/deep_utils.html"> |
| 10 <link rel="import" href="/tracing/value/ui/value_set_table.html"> |
| 11 <link rel="import" href="/tracing/value/value_set.html"> |
| 12 |
| 13 <script> |
| 14 'use strict'; |
| 15 |
| 16 tr.b.unittest.testSuite(function() { |
| 17 var TEST_NUMERIC_BUILDER = tr.v.NumericBuilder.createLinear( |
| 18 tr.v.Unit.byName.timeDurationInMs_smallerIsBetter, |
| 19 tr.b.Range.fromExplicitRange(0, 1000), 20); |
| 20 |
| 21 function getTableRowAtPath(table, path) { |
| 22 var row = table.tableRows[0]; |
| 23 for (var index of path) |
| 24 row = row.subRows[index]; |
| 25 return row; |
| 26 } |
| 27 |
| 28 test('instantiate_1x1', function() { |
| 29 var table = document.createElement('tr-v-ui-value-set-table'); |
| 30 var values = new tr.v.ValueSet(); |
| 31 assert.isTrue(table.supportsValueSet(values)); |
| 32 var numeric = TEST_NUMERIC_BUILDER.build(); |
| 33 for (var i = 0; i < 100; ++i) |
| 34 numeric.add(Math.random() * 1000); |
| 35 values.addValue(new tr.v.NumericValue('foo', numeric)); |
| 36 table.values = values; |
| 37 this.addHTMLOutput(table); |
| 38 var baseTable = tr.b.findDeepElementMatchingPredicate( |
| 39 table, elem => elem.tagName === 'TR-UI-B-TABLE'); |
| 40 assert.strictEqual(baseTable.tableRows.length, 1); |
| 41 }); |
| 42 |
| 43 // TODO(benjhayden): Test requestSelectionChange. |
| 44 // TODO(benjhayden): Test search keyup. |
| 45 |
| 46 test('instantiate_2x2', function() { |
| 47 var table = document.createElement('tr-v-ui-value-set-table'); |
| 48 var values = new tr.v.ValueSet(); |
| 49 assert.isTrue(table.supportsValueSet(values)); |
| 50 |
| 51 var numeric0a = TEST_NUMERIC_BUILDER.build(); |
| 52 for (var i = 0; i < 100; ++i) |
| 53 numeric0a.add(Math.random() * 1000); |
| 54 var fooA = new tr.v.NumericValue('foo', numeric0a, { |
| 55 description: 'they should have sent a poet' |
| 56 }); |
| 57 values.addValue(fooA); |
| 58 new tr.v.d.IterationInfo({ |
| 59 label: 'iteration A', |
| 60 benchmarkStartMs: new Date().getTime(), |
| 61 }).addToValue(fooA); |
| 62 |
| 63 var numeric1a = TEST_NUMERIC_BUILDER.build(); |
| 64 for (var i = 0; i < 100; ++i) |
| 65 numeric1a.add(Math.random() * 1000); |
| 66 var barA = new tr.v.NumericValue('bar', numeric1a, { |
| 67 description: 'indescribable' |
| 68 }); |
| 69 values.addValue(barA); |
| 70 new tr.v.d.IterationInfo({ |
| 71 label: 'iteration A', |
| 72 benchmarkStartMs: new Date().getTime(), |
| 73 }).addToValue(barA); |
| 74 |
| 75 var numeric0b = TEST_NUMERIC_BUILDER.build(); |
| 76 for (var i = 0; i < 100; ++i) |
| 77 numeric0b.add(Math.random() * 1000); |
| 78 var fooB = new tr.v.NumericValue('foo', numeric0b, { |
| 79 description: 'they should have sent a poet' |
| 80 }); |
| 81 values.addValue(fooB); |
| 82 new tr.v.d.IterationInfo({ |
| 83 label: 'iteration B', |
| 84 benchmarkStartMs: new Date().getTime(), |
| 85 }).addToValue(fooB); |
| 86 |
| 87 var numeric1b = TEST_NUMERIC_BUILDER.build(); |
| 88 for (var i = 0; i < 100; ++i) |
| 89 numeric1b.add(Math.random() * 1000); |
| 90 var barB = new tr.v.NumericValue('bar', numeric1b, { |
| 91 description: 'indescribable' |
| 92 }); |
| 93 values.addValue(barB); |
| 94 new tr.v.d.IterationInfo({ |
| 95 label: 'iteration B', |
| 96 benchmarkStartMs: new Date().getTime(), |
| 97 }).addToValue(barB); |
| 98 |
| 99 table.values = values; |
| 100 this.addHTMLOutput(table); |
| 101 |
| 102 var baseTable = tr.b.findDeepElementMatchingPredicate( |
| 103 table, elem => elem.tagName === 'TR-UI-B-TABLE'); |
| 104 |
| 105 assert.lengthOf(baseTable.tableColumns, 3); |
| 106 assert.strictEqual('Name', baseTable.tableColumns[0].title); |
| 107 assert.strictEqual('iteration A', baseTable.tableColumns[1].title); |
| 108 assert.strictEqual('iteration B', baseTable.tableColumns[2].title); |
| 109 }); |
| 110 |
| 111 test('instantiation_mergeNumerics', function() { |
| 112 var table = document.createElement('tr-v-ui-value-set-table'); |
| 113 var values = new tr.v.ValueSet(); |
| 114 // Add 32 NumericValues, all named 'foo', with different IterationInfos. |
| 115 var benchmarkNames = ['bm A', 'bm B']; |
| 116 var storyGroupingKeys0 = ['A', 'B']; |
| 117 var storyGroupingKeys1 = ['C', 'D']; |
| 118 var storyNames = ['story A', 'story B']; |
| 119 var starts = [1439708400000, 1439794800000]; |
| 120 var labels = ['label A', 'label B']; |
| 121 |
| 122 for (var benchmarkName of benchmarkNames) { |
| 123 for (var storyGroupingKey0 of storyGroupingKeys0) { |
| 124 for (var storyGroupingKey1 of storyGroupingKeys1) { |
| 125 for (var storyName of storyNames) { |
| 126 for (var startMs of starts) { |
| 127 for (var storysetCounter = 0; storysetCounter < 2; |
| 128 ++storysetCounter) { |
| 129 for (var storyCounter = 0; storyCounter < 2; ++storyCounter) { |
| 130 for (var label of labels) { |
| 131 var numeric = TEST_NUMERIC_BUILDER.build(); |
| 132 for (var i = 0; i < 100; ++i) |
| 133 numeric.add(Math.random() * 1000); |
| 134 |
| 135 var value = new tr.v.NumericValue('foo', numeric); |
| 136 values.addValue(value); |
| 137 |
| 138 new tr.v.d.IterationInfo({ |
| 139 storyGroupingKeys: { |
| 140 storyGroupingKey0: storyGroupingKey0, |
| 141 storyGroupingKey1: storyGroupingKey1 |
| 142 }, |
| 143 benchmarkName: benchmarkName, |
| 144 storyDisplayName: storyName, |
| 145 benchmarkStartMs: startMs, |
| 146 storysetRepeatCounter: storysetCounter, |
| 147 storyRepeatCounter: storyCounter, |
| 148 label: label, |
| 149 }).addToValue(value); |
| 150 } |
| 151 } |
| 152 } |
| 153 } |
| 154 } |
| 155 } |
| 156 } |
| 157 } |
| 158 |
| 159 table.values = values; |
| 160 this.addHTMLOutput(table); |
| 161 var baseTable = tr.b.findDeepElementMatchingPredicate( |
| 162 table, elem => elem.tagName === 'TR-UI-B-TABLE'); |
| 163 |
| 164 assert.lengthOf(baseTable.tableColumns, 3); |
| 165 assert.strictEqual('Name', baseTable.tableColumns[0].title); |
| 166 assert.strictEqual('label A', baseTable.tableColumns[1].title); |
| 167 assert.strictEqual('label B', baseTable.tableColumns[2].title); |
| 168 |
| 169 assert.lengthOf(baseTable.tableRows, 1); |
| 170 assert.strictEqual('foo', baseTable.tableRows[0].name); |
| 171 assert.lengthOf(baseTable.tableRows[0].subRows, 2); |
| 172 |
| 173 // assertions only report their arguments, which is not enough information |
| 174 // to diagnose problems with nested structures like tableRows -- the path to |
| 175 // the particular row is needed. This code would be a bit simpler if each |
| 176 // row were given a named variable, but the path to each subRow would still |
| 177 // need to be tracked in order to provide for diagnosing. |
| 178 var subRowPath = []; |
| 179 var getSubRow = () => getTableRowAtPath(baseTable, subRowPath); |
| 180 |
| 181 for (var i = 0; i < benchmarkNames.length; ++i) { |
| 182 subRowPath.push(i); |
| 183 assert.lengthOf(getSubRow().subRows, 2, subRowPath); |
| 184 assert.strictEqual(benchmarkNames[i], getSubRow().name, subRowPath); |
| 185 |
| 186 for (var s = 0; s < storyGroupingKeys0.length; ++s) { |
| 187 subRowPath.push(s); |
| 188 assert.lengthOf(getSubRow().subRows, 2, subRowPath); |
| 189 assert.strictEqual('storyGroupingKey0: ' + storyGroupingKeys0[s], |
| 190 getSubRow().name, subRowPath); |
| 191 |
| 192 for (var t = 0; t < storyGroupingKeys1.length; ++t) { |
| 193 subRowPath.push(t); |
| 194 assert.lengthOf(getSubRow().subRows, 2, subRowPath); |
| 195 assert.strictEqual('storyGroupingKey1: ' + storyGroupingKeys1[t], |
| 196 getSubRow().name, subRowPath); |
| 197 |
| 198 for (var j = 0; j < storyNames.length; ++j) { |
| 199 subRowPath.push(j); |
| 200 assert.lengthOf(getSubRow().subRows, 2, subRowPath); |
| 201 assert.strictEqual(storyNames[j], getSubRow().name, subRowPath); |
| 202 |
| 203 for (var k = 0; k < starts.length; ++k) { |
| 204 subRowPath.push(k); |
| 205 assert.lengthOf(getSubRow().subRows, 2, subRowPath); |
| 206 assert.strictEqual(tr.b.formatDate(new Date(starts[k])), |
| 207 getSubRow().name, subRowPath); |
| 208 |
| 209 for (var l = 0; l < 2; ++l) { |
| 210 subRowPath.push(l); |
| 211 assert.lengthOf(getSubRow().subRows, 2, subRowPath); |
| 212 assert.strictEqual('storyset repeat ' + l, getSubRow().name, |
| 213 subRowPath); |
| 214 |
| 215 for (var m = 0; m < 2; ++m) { |
| 216 subRowPath.push(m); |
| 217 assert.lengthOf(getSubRow().subRows, 1, subRowPath); |
| 218 assert.strictEqual('story repeat ' + m, getSubRow().name, |
| 219 subRowPath); |
| 220 |
| 221 subRowPath.push(0); |
| 222 assert.strictEqual('iteration', getSubRow().name, subRowPath); |
| 223 subRowPath.pop(); |
| 224 |
| 225 subRowPath.pop(); |
| 226 } |
| 227 subRowPath.pop(); |
| 228 } |
| 229 subRowPath.pop(); |
| 230 } |
| 231 subRowPath.pop(); |
| 232 } |
| 233 subRowPath.pop(); |
| 234 } |
| 235 subRowPath.pop(); |
| 236 } |
| 237 subRowPath.pop(); |
| 238 } |
| 239 }); |
| 240 |
| 241 test('instantiation_mergeScalarNumerics', function() { |
| 242 var table = document.createElement('tr-v-ui-value-set-table'); |
| 243 var values = new tr.v.ValueSet(); |
| 244 // Add 32 NumericValues, all named 'foo', with different IterationInfos. |
| 245 var benchmarkNames = ['bm A', 'bm B']; |
| 246 var storyNames = ['story A', 'story B']; |
| 247 var starts = [1439708400000, 1439794800000]; |
| 248 var labels = ['label A', 'label B']; |
| 249 |
| 250 for (var benchmarkName of benchmarkNames) { |
| 251 for (var storyName of storyNames) { |
| 252 for (var startMs of starts) { |
| 253 for (var storysetCounter = 0; storysetCounter < 2; |
| 254 ++storysetCounter) { |
| 255 for (var storyCounter = 0; storyCounter < 2; ++storyCounter) { |
| 256 for (var label of labels) { |
| 257 var numeric = new tr.v.ScalarNumeric( |
| 258 tr.v.Unit.byName.timeDurationInMs_smallerIsBetter, |
| 259 Math.random() * 1000); |
| 260 var value = new tr.v.NumericValue('foo', numeric); |
| 261 values.addValue(value); |
| 262 |
| 263 new tr.v.d.IterationInfo({ |
| 264 benchmarkName: benchmarkName, |
| 265 storyDisplayName: storyName, |
| 266 benchmarkStartMs: startMs, |
| 267 storysetRepeatCounter: storysetCounter, |
| 268 storyRepeatCounter: storyCounter, |
| 269 label: label, |
| 270 }).addToValue(value); |
| 271 } |
| 272 } |
| 273 } |
| 274 } |
| 275 } |
| 276 } |
| 277 |
| 278 table.values = values; |
| 279 this.addHTMLOutput(table); |
| 280 var baseTable = tr.b.findDeepElementMatchingPredicate( |
| 281 table, elem => elem.tagName === 'TR-UI-B-TABLE'); |
| 282 |
| 283 assert.lengthOf(baseTable.tableColumns, 3); |
| 284 assert.strictEqual('Name', baseTable.tableColumns[0].title); |
| 285 assert.strictEqual('label A', baseTable.tableColumns[1].title); |
| 286 assert.strictEqual('label B', baseTable.tableColumns[2].title); |
| 287 |
| 288 assert.lengthOf(baseTable.tableRows, 1); |
| 289 assert.strictEqual('foo', baseTable.tableRows[0].name); |
| 290 assert.lengthOf(baseTable.tableRows[0].subRows, 2); |
| 291 |
| 292 // assertions only report their arguments, which is not enough information |
| 293 // to diagnose problems with nested structures like tableRows -- the path to |
| 294 // the particular row is needed. This code would be a bit simpler if each |
| 295 // row were given a named variable, but the path to each subRow would still |
| 296 // need to be tracked in order to provide for diagnosing. |
| 297 var subRowPath = []; |
| 298 var getSubRow = () => getTableRowAtPath(baseTable, subRowPath); |
| 299 |
| 300 for (var i = 0; i < benchmarkNames.length; ++i) { |
| 301 subRowPath.push(i); |
| 302 assert.lengthOf(getSubRow().subRows, 2, subRowPath); |
| 303 assert.strictEqual(benchmarkNames[i], getSubRow().name, subRowPath); |
| 304 |
| 305 for (var j = 0; j < storyNames.length; ++j) { |
| 306 subRowPath.push(j); |
| 307 assert.lengthOf(getSubRow().subRows, 2, subRowPath); |
| 308 assert.strictEqual(storyNames[j], getSubRow().name, subRowPath); |
| 309 |
| 310 for (var k = 0; k < starts.length; ++k) { |
| 311 subRowPath.push(k); |
| 312 assert.lengthOf(getSubRow().subRows, 2, subRowPath); |
| 313 assert.strictEqual(tr.b.formatDate(new Date(starts[k])), |
| 314 getSubRow().name, subRowPath); |
| 315 |
| 316 for (var l = 0; l < 2; ++l) { |
| 317 subRowPath.push(l); |
| 318 assert.lengthOf(getSubRow().subRows, 2, subRowPath); |
| 319 assert.strictEqual('storyset repeat ' + l, getSubRow().name, |
| 320 subRowPath); |
| 321 |
| 322 for (var m = 0; m < 2; ++m) { |
| 323 subRowPath.push(m); |
| 324 assert.lengthOf(getSubRow().subRows, 1, subRowPath); |
| 325 assert.strictEqual('story repeat ' + m, getSubRow().name, |
| 326 subRowPath); |
| 327 subRowPath.push(0); |
| 328 assert.strictEqual('iteration', getSubRow().name, subRowPath); |
| 329 subRowPath.pop(); |
| 330 subRowPath.pop(); |
| 331 } |
| 332 subRowPath.pop(); |
| 333 } |
| 334 subRowPath.pop(); |
| 335 } |
| 336 subRowPath.pop(); |
| 337 } |
| 338 subRowPath.pop(); |
| 339 } |
| 340 }); |
| 341 }); |
| 342 </script> |
OLD | NEW |