Skip to content

Commit

Permalink
fix: Prevent endless loop
Browse files Browse the repository at this point in the history
  • Loading branch information
2martens committed Jun 9, 2024
1 parent 6c13815 commit 6add2ba
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ class CalculationService(
var assignedSeats: Long
var assignedSeatsPerVotingResult: Map<VotingResult, Int>
log.debug("Calculate assigned seats with initial election number {}", electionNumber)
var numberOfAttempts = 5
do {
electionNumberHistory.add(electionNumber)
val seatsPerVotingResult: MutableMap<VotingResult, Double> = mutableMapOf()
Expand Down Expand Up @@ -277,7 +278,11 @@ class CalculationService(
)
log.debug("Calculated higher election number {}", electionNumber)
}
} while (assignedSeats != numberOfSeats.toLong())
numberOfAttempts--
} while (assignedSeats != numberOfSeats.toLong() && numberOfAttempts > 0)
if (numberOfAttempts == 0 && assignedSeats != numberOfSeats.toLong()) {
log.error("With the given result, the solution can never be calculated")
}
return assignedSeatsPerVotingResult
}

Expand Down

0 comments on commit 6add2ba

Please sign in to comment.