At this time, only Condorcet votes collect the appropriate information.
git-svn-id: svn://rubyforge.org/var/svn/rubyvote/trunk@16
1440c7f4-e209-0410-9a04-
881b5eb134a8
+ def result
+ top_result = resultFactory( self )
+ until @candidates.empty?
+ aResult = resultFactory( self )
+ top_result.full_results << aResult
+ filter_out(aResult)
+ end
+ top_result
+ end
+
protected
def verify_vote(vote=nil)
vote.instance_of?( Array ) and
vote == vote.uniq
end
protected
def verify_vote(vote=nil)
vote.instance_of?( Array ) and
vote == vote.uniq
end
end
class PureCondorcetVote < CondorcetVote
end
class PureCondorcetVote < CondorcetVote
- def result
- PureCondorcetResult.new( self )
+ def resultFactory(init)
+ PureCondorcetResult.new(init)
end
end
class CloneproofSSDVote < CondorcetVote
end
end
class CloneproofSSDVote < CondorcetVote
- def result
- CloneproofSSDResult.new( self )
+ def resultFactory(init)
+ CloneproofSSDResult.new(init)
def tally_vote
self.verify_vote(vote)
end
def tally_vote
self.verify_vote(vote)
end
+
+ def filter_out(winner)
+ if winner.winners[0].class == Array
+ to_filter = winner.winners[0]
+ else
+ to_filter = [winner.winners[0]]
+ end
+ @candidates.delete_if {|x| to_filter.include?(x)}
+ end
+
end
class PluralityVote < ElectionVote
end
class PluralityVote < ElectionVote
class ElectionResult
attr_reader :winners
class ElectionResult
attr_reader :winners
+ attr_accessor :full_results
def initialize(voteobj=nil)
unless voteobj and voteobj.kind_of?( ElectionVote )
def initialize(voteobj=nil)
unless voteobj and voteobj.kind_of?( ElectionVote )
@election = voteobj
@winners = Array.new
@election = voteobj
@winners = Array.new
+ @full_results = Array.new
+ def get_full_results
+ @full_results.collect {|x| x.winners}
+ end
+
end
class PluralityResult < ElectionResult
end
class PluralityResult < ElectionResult
8.times {vote_array << "EBADC".split("")}
assert_equal "E", CloneproofSSDVote.new(vote_array).result.winners[0]
8.times {vote_array << "EBADC".split("")}
assert_equal "E", CloneproofSSDVote.new(vote_array).result.winners[0]
+ assert_equal [['E'], ['A'], ['C'], ['B'], ['D']],
+ CloneproofSSDVote.new(vote_array).result.get_full_results
4.times {vote_array << "DCBA".split("")}
assert_equal "D", CloneproofSSDVote.new(vote_array).result.winners[0]
4.times {vote_array << "DCBA".split("")}
assert_equal "D", CloneproofSSDVote.new(vote_array).result.winners[0]
+ assert_equal [['D'], ['A'], ['C'], ['B']],
+ CloneproofSSDVote.new(vote_array).result.get_full_results
2.times {vote_array << "CBDA".split("")}
assert_equal "B", CloneproofSSDVote.new(vote_array).result.winners[0]
2.times {vote_array << "CBDA".split("")}
assert_equal "B", CloneproofSSDVote.new(vote_array).result.winners[0]
+ assert_equal [['B'], ['C'], ['D'], ['A']],
+ CloneproofSSDVote.new(vote_array).result.get_full_results