X-Git-Url: https://projects.mako.cc/source/rubyvote/blobdiff_plain/0ef8f53fb812bcc40337a92f9c4d11ab193f73a9..0e05e46d80413a70fc4aa10bfabbbac048add5a8:/test/election_test.rb diff --git a/test/election_test.rb b/test/election_test.rb index b182e2d..2afab27 100644 --- a/test/election_test.rb +++ b/test/election_test.rb @@ -1,18 +1,36 @@ -#!/usr/bin/ruby +#!/usr/bin/ruby -Ilib require 'test/unit' -require 'election_test_helper' +require 'rubyvote/election' class TestElectionVote < Test::Unit::TestCase - include ElectionTestHelper + def test_plurality_empty + vote_array = [] + assert_nil PluralityVote.new(vote_array).result.winners[0] + end + def test_plurality vote_array = "ABCABCABCCCBBAAABABABCCCCCCCCCCCCCA".split("") - test_winner( "C", PluralityVote.new(vote_array).result ) + assert_equal( "C", PluralityVote.new(vote_array).result.winners[0] ) end + def test_plurality_nonstring + vote_array = [1,2,3,1,1,1,2,3] + assert_equal( 1, PluralityVote.new(vote_array).result.winners[0] ) + end + def test_invalid_voteobj + vote_array = [1,2,nil,1] + assert_raise(InvalidVoteError) { PluralityVote.new(vote_array).result.winners[0] } + end + + def test_approval_empty + vote_array = [] + assert_nil ApprovalVote.new(vote_array).result.winners[0] + end + def test_approval vote_array = Array.new 10.times {vote_array << "AB".split("")} @@ -20,7 +38,7 @@ class TestElectionVote < Test::Unit::TestCase 11.times {vote_array << "AC".split("")} 5.times {vote_array << "A".split("")} - test_winner( "A", ApprovalVote.new(vote_array).result ) + assert_equal( "A", ApprovalVote.new(vote_array).result.winners[0] ) end end