← Watch feed
units: Extend test coverage for weight module
What changed, and why it matters
This commit only adds new unit tests for the Sum trait on a Weight type. It does not change any production code, fix a bug, or alter behavior. There is no security relevance.
Recommended action
No action required; this is a test-only change with no security implications.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds three test cases to units/src/weight.rs covering iterator summation of Weight values: owned iterator sum, reference iterator sum, and empty iterator sum. No implementation code is modified.
Changed components
units/src/weight.rs (tests only)Inspect captured patch +36 / −0
diff --git a/units/src/weight.rs b/units/src/weight.rs
index 558d8339..b2d27e12 100644
--- a/units/src/weight.rs
+++ b/units/src/weight.rs
@@ -576,4 +576,40 @@ mod tests {
weight %= 3;
assert_eq!(weight, Weight::from_wu(1));
}
+
+ #[test]
+ fn iter_sum() {
+ let values = [
+ Weight::from_wu(10),
+ Weight::from_wu(50),
+ Weight::from_wu(30),
+ Weight::from_wu(5),
+ Weight::from_wu(5),
+ ];
+ let got: Weight = values.into_iter().sum();
+ let want = Weight::from_wu(100);
+ assert_eq!(got, want);
+ }
+
+ #[test]
+ fn iter_sum_ref() {
+ let values = [
+ Weight::from_wu(10),
+ Weight::from_wu(50),
+ Weight::from_wu(30),
+ Weight::from_wu(5),
+ Weight::from_wu(5),
+ ];
+ let got: Weight = values.iter().sum();
+ let want = Weight::from_wu(100);
+ assert_eq!(got, want);
+ }
+
+ #[test]
+ fn iter_sum_empty() {
+ let values: [Weight; 0] = [];
+ let got: Weight = values.into_iter().sum();
+ let want = Weight::from_wu(0);
+ assert_eq!(got, want);
+ }
}
Risk score
Our methodology →Why this scored 15/100
Human-validated context
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
No validated notes yet.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.