Unverified Commit 34da4a5f authored by liyuqian's avatar liyuqian Committed by GitHub

Throw instead of return null if durations is empty (#18957)

See https://github.com/flutter/flutter/pull/18881#discussion_r199285256
parent 647076d7
......@@ -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],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment