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:
liyuqian
2018-07-02 13:30:02 -07:00
committed by GitHub
parent 647076d767
commit 34da4a5ffd
2 changed files with 30 additions and 13 deletions

View File

@@ -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],