Throw instead of return null if durations is empty (#18957)
See https://github.com/flutter/flutter/pull/18881#discussion_r199285256
This commit is contained in:
@@ -162,7 +162,7 @@ class TimelineSummary {
|
||||
|
||||
double _averageInMillis(Iterable<Duration> durations) {
|
||||
if (durations.isEmpty)
|
||||
return null;
|
||||
throw new ArgumentError('durations is empty!');
|
||||
|
||||
final int total = durations.fold<int>(0, (int t, Duration duration) => t + duration.inMilliseconds);
|
||||
return total / durations.length;
|
||||
@@ -170,7 +170,7 @@ class TimelineSummary {
|
||||
|
||||
double _percentileInMillis(Iterable<Duration> durations, double percentile) {
|
||||
if (durations.isEmpty)
|
||||
return null;
|
||||
throw new ArgumentError('durations is empty!');
|
||||
|
||||
assert(percentile >= 0.0 && percentile <= 100.0);
|
||||
final List<double> doubles = durations.map<double>((Duration duration) => duration.inMilliseconds.toDouble()).toList();
|
||||
@@ -181,7 +181,7 @@ class TimelineSummary {
|
||||
|
||||
double _maxInMillis(Iterable<Duration> durations) {
|
||||
if (durations.isEmpty)
|
||||
return null;
|
||||
throw new ArgumentError('durations is empty!');
|
||||
|
||||
return durations
|
||||
.map<double>((Duration duration) => duration.inMilliseconds.toDouble())
|
||||
|
||||
@@ -55,8 +55,11 @@ void main() {
|
||||
});
|
||||
|
||||
group('average_frame_build_time_millis', () {
|
||||
test('returns null when there is no data', () {
|
||||
expect(summarize(<Map<String, dynamic>>[]).computeAverageFrameBuildTimeMillis(), isNull);
|
||||
test('throws when there is no data', () {
|
||||
expect(
|
||||
() => summarize(<Map<String, dynamic>>[]).computeAverageFrameBuildTimeMillis(),
|
||||
throwsA(predicate<ArgumentError>((ArgumentError e) => e.message == 'durations is empty!'))
|
||||
);
|
||||
});
|
||||
|
||||
test('computes average frame build time in milliseconds', () {
|
||||
@@ -71,8 +74,11 @@ void main() {
|
||||
});
|
||||
|
||||
group('worst_frame_build_time_millis', () {
|
||||
test('returns null when there is no data', () {
|
||||
expect(summarize(<Map<String, dynamic>>[]).computeWorstFrameBuildTimeMillis(), isNull);
|
||||
test('throws when there is no data', () {
|
||||
expect(
|
||||
() => summarize(<Map<String, dynamic>>[]).computeWorstFrameBuildTimeMillis(),
|
||||
throwsA(predicate<ArgumentError>((ArgumentError e) => e.message == 'durations is empty!'))
|
||||
);
|
||||
});
|
||||
|
||||
test('computes worst frame build time in milliseconds', () {
|
||||
@@ -107,8 +113,11 @@ void main() {
|
||||
});
|
||||
|
||||
group('average_frame_rasterizer_time_millis', () {
|
||||
test('returns null when there is no data', () {
|
||||
expect(summarize(<Map<String, dynamic>>[]).computeAverageFrameRasterizerTimeMillis(), isNull);
|
||||
test('throws when there is no data', () {
|
||||
expect(
|
||||
() => summarize(<Map<String, dynamic>>[]).computeAverageFrameRasterizerTimeMillis(),
|
||||
throwsA(predicate<ArgumentError>((ArgumentError e) => e.message == 'durations is empty!'))
|
||||
);
|
||||
});
|
||||
|
||||
test('computes average frame rasterizer time in milliseconds', () {
|
||||
@@ -143,10 +152,14 @@ void main() {
|
||||
});
|
||||
|
||||
group('worst_frame_rasterizer_time_millis', () {
|
||||
test('returns null when there is no data', () {
|
||||
expect(summarize(<Map<String, dynamic>>[]).computeWorstFrameRasterizerTimeMillis(), isNull);
|
||||
test('throws when there is no data', () {
|
||||
expect(
|
||||
() => summarize(<Map<String, dynamic>>[]).computeWorstFrameRasterizerTimeMillis(),
|
||||
throwsA(predicate<ArgumentError>((ArgumentError e) => e.message == 'durations is empty!'))
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
test('computes worst frame rasterizer time in milliseconds', () {
|
||||
expect(
|
||||
summarize(<Map<String, dynamic>>[
|
||||
@@ -186,10 +199,14 @@ void main() {
|
||||
});
|
||||
|
||||
group('percentile_frame_rasterizer_time_millis', () {
|
||||
test('returns null when there is no data', () {
|
||||
expect(summarize(<Map<String, dynamic>>[]).computeWorstFrameRasterizerTimeMillis(), isNull);
|
||||
test('throws when there is no data', () {
|
||||
expect(
|
||||
() => summarize(<Map<String, dynamic>>[]).computePercentileFrameRasterizerTimeMillis(90.0),
|
||||
throwsA(predicate<ArgumentError>((ArgumentError e) => e.message == 'durations is empty!'))
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
const List<List<int>> sequences = <List<int>>[
|
||||
<int>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
<int>[1, 2, 3, 4, 5],
|
||||
|
||||
Reference in New Issue
Block a user