X-Git-Url: https://projects.mako.cc/source/rubyvote/blobdiff_plain/74e5c5f3c50a36d8d8589c243395b9158977f4db..0ef8f53fb812bcc40337a92f9c4d11ab193f73a9:/test/range_test.rb diff --git a/test/range_test.rb b/test/range_test.rb new file mode 100644 index 0000000..953df78 --- /dev/null +++ b/test/range_test.rb @@ -0,0 +1,32 @@ +#!/usr/bin/ruby + +require 'test/unit' +require 'election_test_helper' + +class TestRangeVote < Test::Unit::TestCase + include ElectionTestHelper + + def test_range + vote_array = [] + 42.times {vote_array << {'A' => 10, 'B' => 5, 'C' => 2, 'D' => 1}} + 26.times {vote_array << {'A' => 1, 'B' => 10, 'C' => 5, 'D' => 2}} + 15.times {vote_array << {'A' => 1, 'B' => 2, 'C' => 10, 'D' => 5}} + 17.times {vote_array << {'A' => 1, 'B' => 2, 'C' => 5, 'D' => 10}} + + test_winner('B', RangeVote.new(vote_array).result ) + end + + def test_tie + vote_array = [] + 10.times {vote_array << {'A' => 5, 'B' => 2}} + 10.times {vote_array << {'A' => 2, 'B' => 5}} + + test_winner(['A','B'], RangeVote.new(vote_array).result ) + end + + def test_no_win + vote_array = [] + + test_winner(nil, RangeVote.new(vote_array).result ) + end +end