79635ecca08ce4619c1478b0ef3da67e482825cb
[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_empty
10     vote_array = []
11     assert_nil RangeVote.new(vote_array).result.winners[0]
12   end
13   
14   def test_range
15     vote_array = []
16     42.times {vote_array << {'A' => 10, 'B' => 5, 'C' => 2, 'D' => 1}}
17     26.times {vote_array << {'A' => 1, 'B' => 10, 'C' => 5, 'D' => 2}}
18     15.times {vote_array << {'A' => 1, 'B' => 2, 'C' => 10, 'D' => 5}}
19     17.times {vote_array << {'A' => 1, 'B' => 2, 'C' => 5, 'D' => 10}}
20
21     assert_equal('B', RangeVote.new(vote_array).result.winners[0] )
22   end
23
24   def test_tie
25     vote_array = []
26     10.times {vote_array << {'A' => 5, 'B' => 2}}
27     10.times {vote_array << {'A' => 2, 'B' => 5}}
28
29     assert_equal(['A','B'], RangeVote.new(vote_array).result.winners )
30   end
31
32   def test_no_win
33     vote_array = []
34
35     assert_equal(nil, RangeVote.new(vote_array).result.winners[0] )
36   end
37 end

Benjamin Mako Hill || Want to submit a patch?