Skip to content

Commit

Permalink
metrics: tests: replace .get(N).unwrap() with array indexing
Browse files Browse the repository at this point in the history
This is more concise and accomplishes the same thing. It also
incidentally avoids a clippy warning about using .get(0) instead of
.first().

BUG=b:344974550
TEST=tools/clippy

Change-Id: Ie8575f63ca7aacd91123c81a6f533b4a2d1408d2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5598299
Commit-Queue: Daniel Verkamp <[email protected]>
Reviewed-by: Noah Gold <[email protected]>
  • Loading branch information
danielverkamp authored and crosvm LUCI committed Jun 4, 2024
1 parent 24d6063 commit 642f964
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions metrics/src/local_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,9 @@ mod tests {
simple_stats.add(v);
}

bucket_check(histogram.buckets.get(0).unwrap(), &[0, 9, 5]);
bucket_check(histogram.buckets.get(1).unwrap(), &[20, 50]);
bucket_check(histogram.buckets.get(2).unwrap(), &[199, 120]);
bucket_check(&histogram.buckets[0], &[0, 9, 5]);
bucket_check(&histogram.buckets[1], &[20, 50]);
bucket_check(&histogram.buckets[2], &[199, 120]);
assert_eq!(histogram.buckets.len(), 3);
assert_eq!(histogram.simple_stat(), simple_stats);
assert_eq!(histogram.values, None);
Expand All @@ -592,9 +592,9 @@ mod tests {
simple_stats.add(v);
}

bucket_check(histogram.buckets.get(1).unwrap(), &[4, 9, 5]);
bucket_check(histogram.buckets.get(2).unwrap(), &[20, 50]);
bucket_check(histogram.buckets.get(3).unwrap(), &[199, 120]);
bucket_check(&histogram.buckets[1], &[4, 9, 5]);
bucket_check(&histogram.buckets[2], &[20, 50]);
bucket_check(&histogram.buckets[3], &[199, 120]);
assert_eq!(histogram.buckets.len(), 5);
assert_eq!(histogram.simple_stat(), simple_stats);
assert_eq!(histogram.values, None);
Expand Down Expand Up @@ -637,9 +637,9 @@ mod tests {
histogram.add(v.clone()).unwrap();
}

bucket_check(histogram.buckets.get(0).unwrap(), &[4, 9, 5]);
bucket_check(histogram.buckets.get(1).unwrap(), &[20, 50]);
bucket_check(histogram.buckets.get(2).unwrap(), &[199, 120]);
bucket_check(histogram.buckets[0], &[4, 9, 5]);
bucket_check(histogram.buckets[1], &[20, 50]);
bucket_check(histogram.buckets[2], &[199, 120]);
assert_eq!(histogram.buckets.len(), 3);
assert_eq!(histogram.simple_stat(), simple_stats);
assert_eq!(histogram.values, Some(values));
Expand All @@ -661,11 +661,11 @@ mod tests {
histogram.add(v.clone()).unwrap();
}

bucket_check(histogram.buckets.get(0).unwrap(), &[]);
bucket_check(histogram.buckets.get(4).unwrap(), &[]);
bucket_check(histogram.buckets.get(1).unwrap(), &[4, 9, 5]);
bucket_check(histogram.buckets.get(2).unwrap(), &[20, 50]);
bucket_check(histogram.buckets.get(3).unwrap(), &[199, 120]);
bucket_check(histogram.buckets[0], &[]);
bucket_check(histogram.buckets[4], &[]);
bucket_check(histogram.buckets[1], &[4, 9, 5]);
bucket_check(histogram.buckets[2], &[20, 50]);
bucket_check(histogram.buckets[3], &[199, 120]);
assert_eq!(histogram.buckets.len(), 5);
assert_eq!(histogram.simple_stat(), simple_stats);
assert_eq!(histogram.values, Some(values));
Expand Down

0 comments on commit 642f964

Please sign in to comment.