Add testcases for calling results to empty votes.
authorJohn Dong <jdong@mit.edu>
Wed, 15 Aug 2007 19:50:14 +0000 (19:50 +0000)
committerJohn Dong <jdong@mit.edu>
Wed, 15 Aug 2007 19:50:14 +0000 (19:50 +0000)
TODO: IRV Logic has same bug

git-svn-id: svn://rubyforge.org/var/svn/rubyvote/trunk@34 1440c7f4-e209-0410-9a04-881b5eb134a8

test/condorcet_test.rb
test/election_test.rb
test/irv_test.rb
test/positional_test.rb
test/range_test.rb

index 4607163a6fee8c96e8a3c6605693cbce1b6cca9d..9d10169011a93d6d0f06746fee080eabc1a8c260 100644 (file)
@@ -5,6 +5,10 @@ require 'rubyvote/election'
 require 'rubyvote/condorcet'
 
 class TestCondorcetVote < Test::Unit::TestCase
+  def test_condorcet_empty
+    vote_array =  [[]]
+    assert_nil PureCondorcetVote.new(vote_array).result.winners[0]
+  end
 
   def test_condorcet
     vote_array = Array.new
@@ -27,6 +31,11 @@ class TestCondorcetVote < Test::Unit::TestCase
     assert_equal [['6', '7'], ['8']], v.results
   end
 
+  def test_ssd_empty
+    vote_array = [[]]
+    assert_nil  CloneproofSSDVote.new(vote_array).result.winners[0]
+  end
+  
   def test_ssd
     vote_array = Array.new
     5.times {vote_array << "ACBED".split("")}
index 7675e58a01c8eb1fe4a254d57f6204062dc27619..2afab27475f6c38b1a7d1c01ed8ad2bb02d2f1ed 100644 (file)
@@ -5,6 +5,11 @@ require 'rubyvote/election'
 
 class TestElectionVote < Test::Unit::TestCase
 
+  def test_plurality_empty
+    vote_array = []
+    assert_nil PluralityVote.new(vote_array).result.winners[0]
+  end
+  
   def test_plurality
     vote_array = "ABCABCABCCCBBAAABABABCCCCCCCCCCCCCA".split("")
 
@@ -21,6 +26,11 @@ class TestElectionVote < Test::Unit::TestCase
     assert_raise(InvalidVoteError) { PluralityVote.new(vote_array).result.winners[0] }
   end
   
+  def test_approval_empty
+    vote_array = []
+    assert_nil ApprovalVote.new(vote_array).result.winners[0]
+  end
+  
   def test_approval
     vote_array = Array.new
     10.times {vote_array << "AB".split("")}
index 49aa540e02a958bb1220ef22f47987e7d227b64d..fa05dc99bd62ebef470826eec4bad690a1b6d94b 100644 (file)
@@ -6,6 +6,11 @@ require 'rubyvote/irv'
 
 class TestRunoffVote < Test::Unit::TestCase
 
+  def test_irv_empty
+    vote_array = Array.new
+    assert_nil InstantRunoffVote.new(vote_array).result.winners[0]
+  end
+  
   def test_irv
     vote_array = Array.new
     142.times {vote_array << "ABCD".split("")}
@@ -50,7 +55,12 @@ class TestRunoffVote < Test::Unit::TestCase
 
     assert_equal( "C", InstantRunoffVote.new(vote_array).result.winners[0] )
   end
-
+  
+  def test_irv_logic_empty
+    vote_array = Array.new
+    assert_nil InstantRunoffLogicVote.new(vote_array).result.winners[0]
+  end
+  
   def test_irv_logic1
     vote_array = Array.new
     42.times {vote_array << "ABCD".split("")}
index 1dc6c125099a80126517bc4bc8c0e7542e547fee..76be74d7c55e2b88c32b6874e888e3d46a00e495 100644 (file)
@@ -5,7 +5,12 @@ require 'rubyvote/election'
 require 'rubyvote/positional'
 
 class TestPositionalVote < Test::Unit::TestCase
-
+  
+  def test_borda_empty
+    vote_array = Array.new
+    assert_nil BordaVote.new(vote_array).result.winners[0]
+  end
+  
   def test_borda
     vote_array = Array.new
     2.times {vote_array << "BAC".split("")}
index 26d8600e3b1d2650ed75ffa6418225d189d25d41..79635ecca08ce4619c1478b0ef3da67e482825cb 100644 (file)
@@ -6,6 +6,11 @@ require 'rubyvote/range'
 
 class TestRangeVote < Test::Unit::TestCase
 
+  def test_range_empty
+    vote_array = []
+    assert_nil RangeVote.new(vote_array).result.winners[0]
+  end
+  
   def test_range
     vote_array = []
     42.times {vote_array << {'A' => 10, 'B' => 5, 'C' => 2, 'D' => 1}}

Benjamin Mako Hill || Want to submit a patch?