Skip to content

Commit

Permalink
FixedPointMath 100% coverage (#966)
Browse files Browse the repository at this point in the history
* full branch coverage for weighted average

* remove infeasible branch
  • Loading branch information
jrhea authored Apr 17, 2024
1 parent 5914901 commit 91d0e7f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 3 additions & 4 deletions contracts/src/libraries/FixedPointMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,12 @@ library FixedPointMath {
// min(_delta, _average) <= average <= max(_delta, _average)
//
// To ensure that this is always the case, we clamp the weighted
// average to this range.
// average to this range. We don't have to worry about the
// case where average > _delta.max(average) because rounding down when
// computing this average makes this case infeasible.
uint256 minAverage = _delta.min(_average);
uint256 maxAverage = _delta.max(_average);
if (average < minAverage) {
average = minAverage;
} else if (average > maxAverage) {
average = maxAverage;
}
}
// If the delta weight should be subtracted from the total weight, we
Expand Down
10 changes: 10 additions & 0 deletions test/units/libraries/FixedPointMath.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ contract FixedPointMathTest is Test {
),
1e18
);
assertEq(
mockFixedPointMath.updateWeightedAverage(
100e18,
10e18,
200e18,
10e18,
true
),
150e18
);
}

// This test verifies that update weighted average always performs as a
Expand Down

0 comments on commit 91d0e7f

Please sign in to comment.