* Add testcase for checking InvalidVoteError is properly raised
git-svn-id: svn://rubyforge.org/var/svn/rubyvote/trunk@31
1440c7f4-e209-0410-9a04-
881b5eb134a8
if votes
if votes.instance_of?( Array )
votes.each do |vote|
- self.tally_vote(vote) if self.verify_vote(vote)
+ if self.verify_vote(vote)
+ self.tally_vote(vote)
+ else
+ raise InvalidVoteError.new ("Invalid vote object", vote)
+ end
end
else
raise ElectionError, "Votes must be in the form of an array.", caller
class ElectionError < ArgumentError
end
+class InvalidVoteError < ElectionError
+ attr_accessor :voteobj
+ def initialize(msg=nil, voteobj=nil)
+ super(msg)
+ @voteobj=voteobj
+ end
+end
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
vote_array = Array.new
10.times {vote_array << "AB".split("")}