1 $:.unshift(File.dirname(__FILE__) + "/../lib/")
5 module ElectionTestHelper
6 def test_winner(expected, result)
7 puts "\nUsing the #{result.class.to_s.gsub(/Result/,'')} voting method..."
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(", ")
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!")
18 msg = "There is a single winner: #{result.winners[0]}"
19 assert_equal(expected, result.winners[0], msg)
23 msg = "There is no winner"
24 assert_nil(expected, msg)