5b5664e7eaabf55c9dc9e0ed63da5c7e211be7aa
[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
20   def test_approval
21     vote_array = Array.new
22     10.times {vote_array << "AB".split("")}
23     10.times {vote_array << "CB".split("")}
24     11.times {vote_array << "AC".split("")}
25     5.times {vote_array << "A".split("")}
26
27     assert_equal( "A", ApprovalVote.new(vote_array).result.winners[0] )
28   end
29 end
30

Benjamin Mako Hill || Want to submit a patch?