new file
[rubyvote] / test / range_test.rb
1 #!/usr/bin/ruby -Ilib
2
3 require 'test/unit'
4 require 'rubyvote/election'
5 require 'rubyvote/range'
6
7 class TestRangeVote < Test::Unit::TestCase
8
9   def test_range
10     vote_array = []
11     42.times {vote_array << {'A' => 10, 'B' => 5, 'C' => 2, 'D' => 1}}
12     26.times {vote_array << {'A' => 1, 'B' => 10, 'C' => 5, 'D' => 2}}
13     15.times {vote_array << {'A' => 1, 'B' => 2, 'C' => 10, 'D' => 5}}
14     17.times {vote_array << {'A' => 1, 'B' => 2, 'C' => 5, 'D' => 10}}
15
16     assert_equal('B', RangeVote.new(vote_array).result.winners[0] )
17   end
18
19   def test_tie
20     vote_array = []
21     10.times {vote_array << {'A' => 5, 'B' => 2}}
22     10.times {vote_array << {'A' => 2, 'B' => 5}}
23
24     assert_equal(['A','B'], RangeVote.new(vote_array).result.winners )
25   end
26
27   def test_no_win
28     vote_array = []
29
30     assert_equal(nil, RangeVote.new(vote_array).result.winners[0] )
31   end
32 end

Benjamin Mako Hill || Want to submit a patch?