]> projects.mako.cc - selectricity/commitdiff
Import latest RubyVote svn to fix infinite loop bug
authorJohn Dong <jdong@mit.edu>
Wed, 15 Aug 2007 19:53:26 +0000 (15:53 -0400)
committerJohn Dong <jdong@mit.edu>
Wed, 15 Aug 2007 19:53:26 +0000 (15:53 -0400)
lib/rubyvote/condorcet.rb
lib/rubyvote/irv.rb

index 65c664dd28a57417aa0a90395562289c8de0eed4..c0539abea5f02aa5b11ddda80fd41f68e78b9b8e 100644 (file)
@@ -184,7 +184,10 @@ class PureCondorcetResult < CondorcetResult
   def condorcet
     votes = @election.votes
     candidates = @election.candidates
   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
     victors = Hash.new
     candidates.each do |candidate|
       victors[candidate] = Array.new
index 38517381e2591770188aec70abec6f2d147adf61..b26b1d1990720fe85cf5e78774bbd8642098e378 100644 (file)
@@ -87,6 +87,11 @@ class InstantRunoffResult < ElectionResult
       apply_retention(votes, votes_sum * params['percent_retention'])
     end
     
       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]
     begin
       ranked_candidates = votes.sort do |a, b|
         b[1][0] <=> a[1][0]

Benjamin Mako Hill || Want to submit a patch?