22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5- // @dart = 2.8
6-
75import 'dart:math' as math;
8- import 'package:meta/meta.dart' ;
96
107import 'task_result.dart' ;
118
@@ -43,8 +40,8 @@ class ABTest {
4340 final String localEngine;
4441 final String taskName;
4542 final DateTime runStart;
46- DateTime _runEnd;
47- DateTime get runEnd => _runEnd;
43+ DateTime ? _runEnd;
44+ DateTime ? get runEnd => _runEnd;
4845
4946 final Map <String , List <double >> _aResults;
5047 final Map <String , List <double >> _bResults;
@@ -91,26 +88,26 @@ class ABTest {
9188 kLocalEngineKeyName: localEngine,
9289 kTaskNameKeyName: taskName,
9390 kRunStartKeyName: runStart.toIso8601String (),
94- kRunEndKeyName: runEnd.toIso8601String (),
91+ kRunEndKeyName: runEnd! .toIso8601String (),
9592 kAResultsKeyName: _aResults,
9693 kBResultsKeyName: _bResults,
9794 };
9895
99- static void updateColumnLengths (List <int > lengths, List <String > results) {
96+ static void updateColumnLengths (List <int > lengths, List <String ? > results) {
10097 for (int column = 0 ; column < lengths.length; column++ ) {
10198 if (results[column] != null ) {
102- lengths[column] = math.max (lengths[column], results[column].length);
99+ lengths[column] = math.max (lengths[column], results[column]? .length ?? 0 );
103100 }
104101 }
105102 }
106103
107104 static void formatResult (StringBuffer buffer,
108105 List <int > lengths,
109106 List <FieldJustification > aligns,
110- List <String > values) {
107+ List <String ? > values) {
111108 for (int column = 0 ; column < lengths.length; column++ ) {
112109 final int len = lengths[column];
113- String value = values[column];
110+ String ? value = values[column];
114111 if (value == null ) {
115112 value = '' .padRight (len);
116113 } else {
@@ -142,9 +139,9 @@ class ABTest {
142139 final Map <String , _ScoreSummary > summariesA = _summarize (_aResults);
143140 final Map <String , _ScoreSummary > summariesB = _summarize (_bResults);
144141
145- final List <List <String >> tableRows = < List <String >> [
142+ final List <List <String ? >> tableRows = < List <String ? >> [
146143 for (final String scoreKey in < String > {...summariesA.keys, ...summariesB.keys})
147- < String > [
144+ < String ? > [
148145 scoreKey,
149146 summariesA[scoreKey]? .averageString, summariesA[scoreKey]? .noiseString,
150147 summariesB[scoreKey]? .averageString, summariesB[scoreKey]? .noiseString,
@@ -167,7 +164,7 @@ class ABTest {
167164
168165 final List <int > lengths = List <int >.filled (6 , 0 );
169166 updateColumnLengths (lengths, titles);
170- for (final List <String > row in tableRows) {
167+ for (final List <String ? > row in tableRows) {
171168 updateColumnLengths (lengths, row);
172169 }
173170
@@ -177,7 +174,7 @@ class ABTest {
177174 FieldJustification .CENTER ,
178175 ...alignments.skip (1 ),
179176 ], titles);
180- for (final List <String > row in tableRows) {
177+ for (final List <String ? > row in tableRows) {
181178 formatResult (buffer, lengths, alignments, row);
182179 }
183180
@@ -192,7 +189,7 @@ class ABTest {
192189 buffer.writeln ('$scoreKey :' );
193190 buffer.write (' A:\t ' );
194191 if (_aResults.containsKey (scoreKey)) {
195- for (final double score in _aResults[scoreKey]) {
192+ for (final double score in _aResults[scoreKey]! ) {
196193 buffer.write ('${score .toStringAsFixed (2 )}\t ' );
197194 }
198195 } else {
@@ -202,7 +199,7 @@ class ABTest {
202199
203200 buffer.write (' B:\t ' );
204201 if (_bResults.containsKey (scoreKey)) {
205- for (final double score in _bResults[scoreKey]) {
202+ for (final double score in _bResults[scoreKey]! ) {
206203 buffer.write ('${score .toStringAsFixed (2 )}\t ' );
207204 }
208205 } else {
@@ -232,8 +229,8 @@ class ABTest {
232229 );
233230
234231 for (final String scoreKey in _allScoreKeys) {
235- final _ScoreSummary summaryA = summariesA[scoreKey];
236- final _ScoreSummary summaryB = summariesB[scoreKey];
232+ final _ScoreSummary ? summaryA = summariesA[scoreKey];
233+ final _ScoreSummary ? summaryB = summariesB[scoreKey];
237234 buffer.write ('$scoreKey \t ' );
238235
239236 if (summaryA != null ) {
@@ -261,8 +258,8 @@ class ABTest {
261258
262259class _ScoreSummary {
263260 _ScoreSummary ({
264- @ required this .average,
265- @ required this .noise,
261+ required this .average,
262+ required this .noise,
266263 });
267264
268265 /// Average (arithmetic mean) of a series of values collected by a benchmark.
@@ -275,14 +272,14 @@ class _ScoreSummary {
275272 String get averageString => average.toStringAsFixed (2 );
276273 String get noiseString => '(${_ratioToPercent (noise )})' ;
277274
278- String improvementOver (_ScoreSummary other) {
275+ String improvementOver (_ScoreSummary ? other) {
279276 return other == null ? '' : '${(average / other .average ).toStringAsFixed (2 )}x' ;
280277 }
281278}
282279
283280void _addResult (TaskResult result, Map <String , List <double >> results) {
284- for (final String scoreKey in result.benchmarkScoreKeys) {
285- final double score = (result.data[scoreKey] as num ).toDouble ();
281+ for (final String scoreKey in result.benchmarkScoreKeys ?? < String > [] ) {
282+ final double score = (result.data! [scoreKey] as num ).toDouble ();
286283 results.putIfAbsent (scoreKey, () => < double > []).add (score);
287284 }
288285}
0 commit comments