]> projects.mako.cc - rubyvote/blob - test/election_test.rb
Add testcases for calling results to empty votes.
[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_empty
9     vote_array = []
10     assert_nil PluralityVote.new(vote_array).result.winners[0]
11   end
12   
13   def test_plurality
14     vote_array = "ABCABCABCCCBBAAABABABCCCCCCCCCCCCCA".split("")
15
16     assert_equal( "C", PluralityVote.new(vote_array).result.winners[0] )
17   end
18
19   def test_plurality_nonstring
20     vote_array = [1,2,3,1,1,1,2,3]
21     assert_equal( 1, PluralityVote.new(vote_array).result.winners[0] )
22   end
23
24   def test_invalid_voteobj
25     vote_array = [1,2,nil,1]
26     assert_raise(InvalidVoteError) { PluralityVote.new(vote_array).result.winners[0] }
27   end
28   
29   def test_approval_empty
30     vote_array = []
31     assert_nil ApprovalVote.new(vote_array).result.winners[0]
32   end
33   
34   def test_approval
35     vote_array = Array.new
36     10.times {vote_array << "AB".split("")}
37     10.times {vote_array << "CB".split("")}
38     11.times {vote_array << "AC".split("")}
39     5.times {vote_array << "A".split("")}
40
41     assert_equal( "A", ApprovalVote.new(vote_array).result.winners[0] )
42   end
43 end
44

Benjamin Mako Hill || Want to submit a patch?