diff --git a/td/telegram/PollManager.cpp b/td/telegram/PollManager.cpp index e50189c1..66f4274c 100644 --- a/td/telegram/PollManager.cpp +++ b/td/telegram/PollManager.cpp @@ -376,7 +376,7 @@ vector PollManager::get_vote_percentage(const vector &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; } diff --git a/test/poll.cpp b/test/poll.cpp index fcbd8ed0..518dd4c7 100644 --- a/test/poll.cpp +++ b/test/poll.cpp @@ -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});