From 9565924bed8f9afd0682d4d029378711b905c550 Mon Sep 17 00:00:00 2001 From: John Dong Date: Wed, 15 Aug 2007 15:53:26 -0400 Subject: [PATCH 1/1] Import latest RubyVote svn to fix infinite loop bug --- lib/rubyvote/condorcet.rb | 5 ++++- lib/rubyvote/irv.rb | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/rubyvote/condorcet.rb b/lib/rubyvote/condorcet.rb index 65c664d..c0539ab 100644 --- a/lib/rubyvote/condorcet.rb +++ b/lib/rubyvote/condorcet.rb @@ -184,7 +184,10 @@ class PureCondorcetResult < CondorcetResult def condorcet votes = @election.votes candidates = @election.candidates - + unless votes.length>0 and candidates.length>0 + @winners=[nil] + return @winners + end victors = Hash.new candidates.each do |candidate| victors[candidate] = Array.new diff --git a/lib/rubyvote/irv.rb b/lib/rubyvote/irv.rb index 3851738..b26b1d1 100644 --- a/lib/rubyvote/irv.rb +++ b/lib/rubyvote/irv.rb @@ -87,6 +87,11 @@ class InstantRunoffResult < ElectionResult apply_retention(votes, votes_sum * params['percent_retention']) end + unless votes.length > 0 + @winners=[nil] + return + end + begin ranked_candidates = votes.sort do |a, b| b[1][0] <=> a[1][0] -- 2.39.2