Fix vote percentage.
GitOrigin-RevId: 9e847cdd0d848f9b1cd29415af08b173fb27c2e1
This commit is contained in:
parent
8476dd88af
commit
7143ac4070
@ -376,7 +376,7 @@ vector<int32> PollManager::get_vote_percentage(const vector<int32> &voter_counts
|
||||
// do not round to wrong direction
|
||||
continue;
|
||||
}
|
||||
if (gap[pos] == total_voter_count / 2 && result[pos] >= 50) {
|
||||
if (total_voter_count % 2 == 0 && gap[pos] == total_voter_count / 2 && result[pos] >= 50) {
|
||||
// round halves to the 50%
|
||||
continue;
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ TEST(Poll, get_vote_percentage) {
|
||||
check_vote_percentage({1}, 1, {100});
|
||||
check_vote_percentage({999}, 999, {100});
|
||||
check_vote_percentage({0}, 0, {0});
|
||||
check_vote_percentage({2, 1}, 3, {67, 33});
|
||||
check_vote_percentage({100, 100}, 200, {50, 50});
|
||||
check_vote_percentage({101, 99}, 200, {50, 50});
|
||||
check_vote_percentage({102, 98}, 200, {51, 49});
|
||||
|
Reference in New Issue
Block a user