From 7143ac407091f30f02ded3fc288a69d6e96cc676 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 10 Mar 2019 21:49:10 +0300 Subject: [PATCH] Fix vote percentage. GitOrigin-RevId: 9e847cdd0d848f9b1cd29415af08b173fb27c2e1 --- td/telegram/PollManager.cpp | 2 +- test/poll.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) 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});