Created victories_and_ties method for table use.
[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     assert_equal(false, PluralityVote.new(vote_array).result.winner?)
12   end
13   
14   def test_plurality
15     vote_array = "ABCABCABCCCBBAAABABABCCCCCCCCCCCCCA".split("")
16
17     assert_equal( "C", PluralityVote.new(vote_array).result.winners[0] )
18   end
19
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] )
23   end
24
25   def test_invalid_voteobj
26     vote_array = [1,2,nil,1]
27     assert_raise(InvalidVoteError) { PluralityVote.new(vote_array).result.winners[0] }
28   end
29   
30   def test_approval_empty
31     vote_array = []
32     assert_nil ApprovalVote.new(vote_array).result.winners[0]
33     assert_equal(false, ApprovalVote.new(vote_array).result.winner?)
34   end
35   
36   def test_approval
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("")}
42
43     assert_equal( "A", ApprovalVote.new(vote_array).result.winners[0] )
44   end
45 end
46

Benjamin Mako Hill || Want to submit a patch?