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