]> projects.mako.cc - rubyvote/blob - test/election_test.rb
7675e58a01c8eb1fe4a254d57f6204062dc27619
[rubyvote] / test / election_test.rb
1 #!/usr/bin/ruby -Ilib
2
3 require 'test/unit'
4 require 'rubyvote/election'
5
6 class TestElectionVote < Test::Unit::TestCase
7
8   def test_plurality
9     vote_array = "ABCABCABCCCBBAAABABABCCCCCCCCCCCCCA".split("")
10
11     assert_equal( "C", PluralityVote.new(vote_array).result.winners[0] )
12   end
13
14   def test_plurality_nonstring
15     vote_array = [1,2,3,1,1,1,2,3]
16     assert_equal( 1, PluralityVote.new(vote_array).result.winners[0] )
17   end
18
19   def test_invalid_voteobj
20     vote_array = [1,2,nil,1]
21     assert_raise(InvalidVoteError) { PluralityVote.new(vote_array).result.winners[0] }
22   end
23   
24   def test_approval
25     vote_array = Array.new
26     10.times {vote_array << "AB".split("")}
27     10.times {vote_array << "CB".split("")}
28     11.times {vote_array << "AC".split("")}
29     5.times {vote_array << "A".split("")}
30
31     assert_equal( "A", ApprovalVote.new(vote_array).result.winners[0] )
32   end
33 end
34

Benjamin Mako Hill || Want to submit a patch?