4 require 'rubyvote/election'
6 class TestElectionVote < Test::Unit::TestCase
8 def test_plurality_empty
10 assert_nil PluralityVote.new(vote_array).result.winners[0]
11 assert_equal(false, PluralityVote.new(vote_array).result.winner?)
15 vote_array = "ABCABCABCCCBBAAABABABCCCCCCCCCCCCCA".split("")
17 assert_equal( "C", PluralityVote.new(vote_array).result.winners[0] )
20 def test_plurality_nonstring
21 vote_array = [1,2,3,1,1,1,2,3]
22 assert_equal( 1, PluralityVote.new(vote_array).result.winners[0] )
25 def test_invalid_voteobj
26 vote_array = [1,2,nil,1]
27 assert_raise(InvalidVoteError) { PluralityVote.new(vote_array).result.winners[0] }
30 def test_approval_empty
32 assert_nil ApprovalVote.new(vote_array).result.winners[0]
33 assert_equal(false, ApprovalVote.new(vote_array).result.winner?)
37 vote_array = Array.new
38 10.times {vote_array << "AB".split("")}
39 10.times {vote_array << "CB".split("")}
40 11.times {vote_array << "AC".split("")}
41 5.times {vote_array << "A".split("")}
43 assert_equal( "A", ApprovalVote.new(vote_array).result.winners[0] )