11import { statDataType } from '../statistics'
22
33export function convertOutput ( displayType , dataType , value ) {
4- let output = ''
5- if ( dataType === statDataType . COUNT || dataType === statDataType . OTHER ) {
6- output = value
7- } else if ( displayType !== dataType ) {
4+ let output = value
5+ if (
6+ ! ( dataType === statDataType . COUNT || dataType === statDataType . OTHER ) &&
7+ displayType !== dataType
8+ ) {
89 if (
910 dataType === statDataType . NANOS &&
1011 displayType === statDataType . MILLIS
1112 ) {
12- output = output + value / 1000000
13+ output = value / 1000000
1314 } else if (
1415 dataType === statDataType . MILLIS &&
1516 displayType === statDataType . NANOS
1617 ) {
17- output = output + value * 1000000
18+ output = value * 1000000
1819 } else if (
1920 dataType === statDataType . MILLIS &&
2021 displayType === statDataType . SECONDS
2122 ) {
22- output = output + value / 1000
23+ output = value / 1000
2324 } else if (
2425 dataType === statDataType . NANOS &&
2526 displayType === statDataType . SECONDS
2627 ) {
27- output = output + value / 1000000000
28+ output = value / 1000000000
2829 } else if (
2930 dataType === statDataType . SECONDS &&
3031 displayType === statDataType . MILLIS
3132 ) {
32- output = output + value * 1000
33+ output = value * 1000
3334 } else if (
3435 dataType === statDataType . SECONDS &&
3536 displayType === statDataType . NANOS
3637 ) {
37- output = output + value * 1000000000
38+ output = value * 1000000000
3839 }
39- } else {
40- output = output + value
4140 }
4241 return output
4342}
4443
45- export function formatSummary ( { colorFns, testRun } ) {
44+ export function formatSummary ( { displayType , colorFns, testRun } ) {
4645 let groupSummarys = ''
4746 testRun . groups . forEach ( ( group , index ) => {
4847 let v = getGroupSummary ( {
4948 colorFns : colorFns ,
5049 group : group ,
5150 statTypes : testRun . statTypes ,
51+ displayType : displayType ,
5252 } )
5353 groupSummarys += v
5454 } )
5555 const durationSummary = getDuration ( testRun . duration )
5656 return [
57- colorFns [ 'simulationTitle' ] ( 'Simulation: ' ) + testRun . name ,
57+ colorFns [ 'simulationTitle' ] ( 'Simulation: ' ) +
58+ testRun . name +
59+ colorFns [ 'statTitle' ] ( ' Start: ' ) +
60+ testRun . start +
61+ colorFns [ 'statTitle' ] ( ' Stop: ' ) +
62+ testRun . stop +
63+ colorFns [ 'statTitle' ] ( ' Duration: ' ) +
64+ durationSummary ,
5865 groupSummarys ,
59- 'Runtime: ' + durationSummary ,
6066 ] . join ( '\n' )
6167}
6268
63- function getGroupSummary ( { colorFns, group, statTypes } ) {
69+ function getGroupSummary ( { colorFns, group, statTypes, displayType } ) {
6470 let text =
6571 colorFns [ 'groupTitle' ] ( 'Group: ' ) +
6672 group . text +
6773 ' ' +
68- getStatistics ( { colorFns : colorFns , object : group , statTypes : statTypes } ) +
74+ getStatistics ( {
75+ colorFns : colorFns ,
76+ object : group ,
77+ statTypes : statTypes ,
78+ displayType : displayType ,
79+ } ) +
6980 '\n'
7081 group . testCases . forEach ( testCase => {
7182 text +=
@@ -77,6 +88,7 @@ function getGroupSummary({ colorFns, group, statTypes }) {
7788 colorFns : colorFns ,
7889 object : testCase ,
7990 statTypes : statTypes ,
91+ displayType : displayType ,
8092 } ) +
8193 '\n'
8294 testCase . steps . forEach ( step => {
@@ -89,20 +101,29 @@ function getGroupSummary({ colorFns, group, statTypes }) {
89101 colorFns : colorFns ,
90102 object : step ,
91103 statTypes : statTypes ,
104+ displayType : displayType ,
92105 } ) +
93106 '\n'
94107 } )
95108 } )
96109 return text
97110}
98111
99- function getStatistics ( { colorFns, object, statTypes } ) {
112+ function getStatistics ( { colorFns, object, statTypes, displayType } ) {
100113 let text = ''
101114 for ( let stat in statTypes ) {
102115 if ( statTypes [ stat ] . isFloatingPoint && object . stats [ stat ] != null ) {
103- text += `${ colorFns [ 'statTitle' ] ( stat ) } :${ object . stats [ stat ] . toFixed ( 3 ) } `
116+ text += `${ colorFns [ 'statTitle' ] ( stat ) } :${ convertOutput (
117+ displayType ,
118+ statTypes [ stat ] . dataType ,
119+ object . stats [ stat ]
120+ ) . toFixed ( 3 ) } `
104121 } else {
105- text += `${ colorFns [ 'statTitle' ] ( stat ) } :${ object . stats [ stat ] } `
122+ text += `${ colorFns [ 'statTitle' ] ( stat ) } :${ convertOutput (
123+ displayType ,
124+ statTypes [ stat ] . dataType ,
125+ object . stats [ stat ]
126+ ) } `
106127 }
107128 }
108129 return text
0 commit comments