]> projects.mako.cc - rubyvote/commitdiff
Fix problem with a [nil] result being taken as having a winner; add testcases
authorJohn Dong <jdong@mit.edu>
Wed, 15 Aug 2007 20:17:05 +0000 (20:17 +0000)
committerJohn Dong <jdong@mit.edu>
Wed, 15 Aug 2007 20:17:05 +0000 (20:17 +0000)
git-svn-id: svn://rubyforge.org/var/svn/rubyvote/trunk@36 1440c7f4-e209-0410-9a04-881b5eb134a8

lib/rubyvote/condorcet.rb
lib/rubyvote/election.rb
lib/rubyvote/irv.rb
test/condorcet_test.rb
test/election_test.rb
test/irv_test.rb
test/positional_test.rb
test/range_test.rb

index c0539abea5f02aa5b11ddda80fd41f68e78b9b8e..0b7a3062afce476f5711fe8ce471c61264d61a87 100644 (file)
@@ -185,7 +185,7 @@ class PureCondorcetResult < CondorcetResult
     votes = @election.votes
     candidates = @election.candidates
     unless votes.length>0 and candidates.length>0
-      @winners=[nil]
+      @winners=[]
       return @winners
     end
     victors = Hash.new
@@ -224,7 +224,7 @@ class CloneproofSSDResult < CondorcetResult
   def cpssd
     votes = @election.votes
     candidates = *@election.candidates
-
+    
     def in_schwartz_set?(candidate, candidates, transitive_defeats)
       candidates.each do |challenger|
         next if candidate == challenger
index b9bb5574c7ea03b4d9d5d6e1b544fdca640e3ee3..42f18bb6c9fa7470e34c46051787573b377fdce2 100644 (file)
@@ -133,7 +133,7 @@ class ElectionResult
   end
 
   def winner?
-    @winners.length > 0
+    @winners.length > 0 and not @winners[0].nil?
   end
 
 end
index b26b1d1990720fe85cf5e78774bbd8642098e378..c3fabe6e488de75352c1ae53305e0a1b0785022c 100644 (file)
@@ -88,7 +88,7 @@ class InstantRunoffResult < ElectionResult
     end
     
     unless votes.length > 0
-      @winners=[nil]
+      @winners=[]
       return
     end
 
index 9d10169011a93d6d0f06746fee080eabc1a8c260..b2d5dc46ad9864d4787c78596551aae1cfac2ab9 100644 (file)
@@ -8,6 +8,7 @@ class TestCondorcetVote < Test::Unit::TestCase
   def test_condorcet_empty
     vote_array =  [[]]
     assert_nil PureCondorcetVote.new(vote_array).result.winners[0]
+    assert_equal(false, PureCondorcetVote.new(vote_array).result.winner?)
   end
 
   def test_condorcet
@@ -34,6 +35,7 @@ class TestCondorcetVote < Test::Unit::TestCase
   def test_ssd_empty
     vote_array = [[]]
     assert_nil  CloneproofSSDVote.new(vote_array).result.winners[0]
+    assert_equal(false, CloneproofSSDVote.new(vote_array).result.winner?)
   end
   
   def test_ssd
index 2afab27475f6c38b1a7d1c01ed8ad2bb02d2f1ed..26d8b917bd548c686ef7e0f20a31128b6ff8e81f 100644 (file)
@@ -8,6 +8,7 @@ class TestElectionVote < Test::Unit::TestCase
   def test_plurality_empty
     vote_array = []
     assert_nil PluralityVote.new(vote_array).result.winners[0]
+    assert_equal(false, PluralityVote.new(vote_array).result.winner?)
   end
   
   def test_plurality
@@ -29,6 +30,7 @@ class TestElectionVote < Test::Unit::TestCase
   def test_approval_empty
     vote_array = []
     assert_nil ApprovalVote.new(vote_array).result.winners[0]
+    assert_equal(false, ApprovalVote.new(vote_array).result.winner?)
   end
   
   def test_approval
index fa05dc99bd62ebef470826eec4bad690a1b6d94b..d3a57a7c7d8cec68e31a4c85cf0ba89c675cea2b 100644 (file)
@@ -9,6 +9,7 @@ class TestRunoffVote < Test::Unit::TestCase
   def test_irv_empty
     vote_array = Array.new
     assert_nil InstantRunoffVote.new(vote_array).result.winners[0]
+    assert_equal(false, InstantRunoffVote.new(vote_array).result.winner?)
   end
   
   def test_irv
@@ -59,6 +60,7 @@ class TestRunoffVote < Test::Unit::TestCase
   def test_irv_logic_empty
     vote_array = Array.new
     assert_nil InstantRunoffLogicVote.new(vote_array).result.winners[0]
+    assert_equal(false, InstantRunoffLogicVote.new(vote_array).result.winner?)
   end
   
   def test_irv_logic1
index 76be74d7c55e2b88c32b6874e888e3d46a00e495..bb81c7ec7109729c9652266aa3ed65bc67a0dba3 100644 (file)
@@ -9,6 +9,7 @@ class TestPositionalVote < Test::Unit::TestCase
   def test_borda_empty
     vote_array = Array.new
     assert_nil BordaVote.new(vote_array).result.winners[0]
+    assert_equal(false, BordaVote.new(vote_array).result.winner?)
   end
   
   def test_borda
index 79635ecca08ce4619c1478b0ef3da67e482825cb..799ba3f84e37bb729846756f5a7895395408ba50 100644 (file)
@@ -9,6 +9,7 @@ class TestRangeVote < Test::Unit::TestCase
   def test_range_empty
     vote_array = []
     assert_nil RangeVote.new(vote_array).result.winners[0]
+    assert_equal(false, RangeVote.new(vote_array).result.winner?)
   end
   
   def test_range

Benjamin Mako Hill || Want to submit a patch?