]> projects.mako.cc - rubyvote/blob - test/election_test_helper.rb
abc37cd15b4fe65109f8ba732050b907cd42314c
[rubyvote] / test / election_test_helper.rb
1 $:.unshift(File.dirname(__FILE__) + "/../lib/")
2
3 require 'rubyvote'
4
5 module ElectionTestHelper
6   def test_winner(expected, result) 
7     puts "\nUsing the #{result.class.to_s.gsub(/Result/,'')} voting method..."
8
9     if result.winner?
10       if expected.is_a?(Array) && expected.length > 1 # Array is passed to test for a tie!
11         msg = "There is a tie: %s" % result.winners.join(", ")
12
13         assert_equal(expected.length, result.winners.length, 
14                      "Not the correct number of winners!")
15         assert(expected.all?{|c| result.winners.include?(c)}, 
16                "Tie winners do not match expected!")
17       else 
18         msg = "There is a single winner: #{result.winners[0]}"
19         assert_equal(expected, result.winners[0], msg) 
20       end
21
22     else
23       msg = "There is no winner"
24       assert_nil(expected, msg)
25     end
26
27     puts msg
28   end
29 end

Benjamin Mako Hill || Want to submit a patch?