mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Fix error in plate calculator
The smallest plate was never being taken into consideration, as the loop never reached it
This commit is contained in:
@@ -26,16 +26,16 @@ List<num> plateCalculator(num totalWeight, num barWeight, List<num> plates) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Remove the bar and divide by two to get weight on each side
|
||||
totalWeight = (totalWeight - barWeight) / 2;
|
||||
|
||||
// Weight can't be divided with the smallest plate
|
||||
if (totalWeight % plates.first > 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Remove the bar and divide by two to get weight on each side
|
||||
totalWeight = (totalWeight - barWeight) / 2;
|
||||
|
||||
// Find the plates
|
||||
for (int i = (platesCount - 1); i > 0; i--) {
|
||||
for (int i = (platesCount - 1); i >= 0; i--) {
|
||||
var plate = plates[i];
|
||||
|
||||
while (totalWeight >= plate) {
|
||||
|
||||
@@ -25,6 +25,7 @@ void main() {
|
||||
test('Regular weights', () async {
|
||||
expect(plateCalculator(40, BAR_WEIGHT, AVAILABLE_PLATES), [10]);
|
||||
expect(plateCalculator(100, BAR_WEIGHT, AVAILABLE_PLATES), [15, 15, 10]);
|
||||
expect(plateCalculator(102.5, BAR_WEIGHT, AVAILABLE_PLATES), [15, 15, 10, 1.25]);
|
||||
expect(plateCalculator(140, BAR_WEIGHT, AVAILABLE_PLATES), [15, 15, 15, 15]);
|
||||
expect(plateCalculator(45, BAR_WEIGHT, AVAILABLE_PLATES), [10, 2.5]);
|
||||
expect(plateCalculator(85, BAR_WEIGHT, AVAILABLE_PLATES), [15, 15, 2.5]);
|
||||
|
||||
Reference in New Issue
Block a user