2015-02-11 13:13:49 -05:00
|
|
|
import {describe, ddescribe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/test_lib';
|
|
|
|
|
2015-05-27 17:57:54 -04:00
|
|
|
import {isBlank, isPresent, Date, DateWrapper} from 'angular2/src/facade/lang';
|
|
|
|
import {List, ListWrapper} from 'angular2/src/facade/collection';
|
2015-02-11 13:13:49 -05:00
|
|
|
|
|
|
|
import {
|
2015-05-27 17:57:54 -04:00
|
|
|
SampleState,
|
|
|
|
Reporter,
|
|
|
|
bind,
|
|
|
|
Injector,
|
|
|
|
ConsoleReporter,
|
|
|
|
SampleDescription,
|
|
|
|
MeasureValues
|
2015-03-02 12:23:09 -05:00
|
|
|
} from 'benchpress/common';
|
2015-02-11 13:13:49 -05:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('console reporter', () => {
|
|
|
|
var reporter;
|
|
|
|
var log;
|
|
|
|
|
2015-05-27 17:57:54 -04:00
|
|
|
function createReporter({columnWidth = null, sampleId = null, descriptions = null, metrics = null}:{
|
|
|
|
columnWidth?, sampleId?, descriptions?, metrics?
|
|
|
|
}) {
|
2015-02-11 13:13:49 -05:00
|
|
|
log = [];
|
|
|
|
if (isBlank(descriptions)) {
|
|
|
|
descriptions = [];
|
|
|
|
}
|
|
|
|
if (isBlank(sampleId)) {
|
|
|
|
sampleId = 'null';
|
|
|
|
}
|
|
|
|
var bindings = [
|
|
|
|
ConsoleReporter.BINDINGS,
|
|
|
|
bind(SampleDescription).toValue(new SampleDescription(sampleId, descriptions, metrics)),
|
|
|
|
bind(ConsoleReporter.PRINT).toValue((line) => ListWrapper.push(log, line))
|
|
|
|
];
|
|
|
|
if (isPresent(columnWidth)) {
|
|
|
|
ListWrapper.push(bindings, bind(ConsoleReporter.COLUMN_WIDTH).toValue(columnWidth));
|
|
|
|
}
|
2015-04-10 20:05:31 -04:00
|
|
|
reporter = Injector.resolveAndCreate(bindings).get(ConsoleReporter);
|
2015-02-11 13:13:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
it('should print the sample id, description and table header', () => {
|
|
|
|
createReporter({
|
|
|
|
columnWidth: 8,
|
|
|
|
sampleId: 'someSample',
|
2015-05-27 17:57:54 -04:00
|
|
|
descriptions: [{'a': 1, 'b': 2}],
|
|
|
|
metrics: {'m1': 'some desc', 'm2': 'some other desc'}
|
2015-02-11 13:13:49 -05:00
|
|
|
});
|
|
|
|
expect(log).toEqual([
|
|
|
|
'BENCHMARK someSample',
|
|
|
|
'Description:',
|
|
|
|
'- a: 1',
|
|
|
|
'- b: 2',
|
|
|
|
'Metrics:',
|
|
|
|
'- m1: some desc',
|
|
|
|
'- m2: some other desc',
|
|
|
|
'',
|
|
|
|
' m1 | m2',
|
|
|
|
'-------- | --------',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should print a table row', () => {
|
2015-05-27 17:57:54 -04:00
|
|
|
createReporter({columnWidth: 8, metrics: {'a': '', 'b': ''}});
|
2015-02-11 13:13:49 -05:00
|
|
|
log = [];
|
2015-05-27 17:57:54 -04:00
|
|
|
reporter.reportMeasureValues(mv(0, 0, {'a': 1.23, 'b': 2}));
|
|
|
|
expect(log).toEqual([' 1.23 | 2.00']);
|
2015-02-11 13:13:49 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should print the table footer and stats when there is a valid sample', () => {
|
2015-05-27 17:57:54 -04:00
|
|
|
createReporter({columnWidth: 8, metrics: {'a': '', 'b': ''}});
|
2015-02-11 13:13:49 -05:00
|
|
|
log = [];
|
2015-05-27 17:57:54 -04:00
|
|
|
reporter.reportSample([], [mv(0, 0, {'a': 3, 'b': 6}), mv(1, 1, {'a': 5, 'b': 9})]);
|
|
|
|
expect(log).toEqual(['======== | ========', '4.00+-25% | 7.50+-20%']);
|
2015-02-11 13:13:49 -05:00
|
|
|
});
|
|
|
|
|
2015-04-17 21:15:22 -04:00
|
|
|
it('should print the coefficient of variation only when it is meaningful', () => {
|
2015-05-27 17:57:54 -04:00
|
|
|
createReporter({columnWidth: 8, metrics: {'a': '', 'b': ''}});
|
2015-04-17 21:15:22 -04:00
|
|
|
log = [];
|
2015-05-27 17:57:54 -04:00
|
|
|
reporter.reportSample([], [mv(0, 0, {'a': 3, 'b': 0}), mv(1, 1, {'a': 5, 'b': 0})]);
|
|
|
|
expect(log).toEqual(['======== | ========', '4.00+-25% | 0.00']);
|
2015-04-17 21:15:22 -04:00
|
|
|
});
|
|
|
|
|
2015-02-11 13:13:49 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-02-17 17:30:24 -05:00
|
|
|
function mv(runIndex, time, values) {
|
|
|
|
return new MeasureValues(runIndex, DateWrapper.fromMillis(time), values);
|
|
|
|
}
|