From: John Dong Date: Wed, 15 Aug 2007 19:50:14 +0000 (+0000) Subject: Add testcases for calling results to empty votes. X-Git-Url: https://projects.mako.cc/source/rubyvote/commitdiff_plain/0e05e46d80413a70fc4aa10bfabbbac048add5a8?ds=sidebyside Add testcases for calling results to empty votes. TODO: IRV Logic has same bug git-svn-id: svn://rubyforge.org/var/svn/rubyvote/trunk@34 1440c7f4-e209-0410-9a04-881b5eb134a8 --- diff --git a/test/condorcet_test.rb b/test/condorcet_test.rb index 4607163..9d10169 100644 --- a/test/condorcet_test.rb +++ b/test/condorcet_test.rb @@ -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("")} diff --git a/test/election_test.rb b/test/election_test.rb index 7675e58..2afab27 100644 --- a/test/election_test.rb +++ b/test/election_test.rb @@ -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("")} diff --git a/test/irv_test.rb b/test/irv_test.rb index 49aa540..fa05dc9 100644 --- a/test/irv_test.rb +++ b/test/irv_test.rb @@ -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("")} diff --git a/test/positional_test.rb b/test/positional_test.rb index 1dc6c12..76be74d 100644 --- a/test/positional_test.rb +++ b/test/positional_test.rb @@ -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("")} diff --git a/test/range_test.rb b/test/range_test.rb index 26d8600..79635ec 100644 --- a/test/range_test.rb +++ b/test/range_test.rb @@ -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}}