4 require 'rubyvote/election'
7 class TestRunoffVote < Test::Unit::TestCase
10 vote_array = Array.new
11 assert_nil InstantRunoffVote.new(vote_array).result.winners[0]
15 vote_array = Array.new
16 142.times {vote_array << "ABCD".split("")}
17 26.times {vote_array << "BCDA".split("")}
18 15.times {vote_array << "CDBA".split("")}
19 17.times {vote_array << "DCBA".split("")}
21 assert_equal( "A", InstantRunoffVote.new(vote_array).result.winners[0] )
25 vote_array = Array.new
26 42.times {vote_array << "ABCD".split("")}
27 26.times {vote_array << "BCDA".split("")}
28 15.times {vote_array << "CDBA".split("")}
29 17.times {vote_array << "DCBA".split("")}
31 assert_equal( "D", InstantRunoffVote.new(vote_array).result.winners[0] )
35 vote_array = Array.new
36 42.times {vote_array << "ABCD".split("")}
37 26.times {vote_array << "ACBD".split("")}
38 15.times {vote_array << "BACD".split("")}
39 32.times {vote_array << "BCAD".split("")}
40 14.times {vote_array << "CABD".split("")}
41 49.times {vote_array << "CBAD".split("")}
42 17.times {vote_array << "ABDC".split("")}
43 23.times {vote_array << "BADC".split("")}
44 37.times {vote_array << "BCDA".split("")}
45 11.times {vote_array << "CADB".split("")}
46 16.times {vote_array << "CBDA".split("")}
47 54.times {vote_array << "ADBC".split("")}
48 36.times {vote_array << "BDCA".split("")}
49 42.times {vote_array << "CDAB".split("")}
50 13.times {vote_array << "CDBA".split("")}
51 51.times {vote_array << "DABC".split("")}
52 33.times {vote_array << "DBCA".split("")}
53 39.times {vote_array << "DCAB".split("")}
54 12.times {vote_array << "DCBA".split("")}
56 assert_equal( "C", InstantRunoffVote.new(vote_array).result.winners[0] )
59 def test_irv_logic_empty
60 vote_array = Array.new
61 assert_nil InstantRunoffLogicVote.new(vote_array).result.winners[0]
65 vote_array = Array.new
66 42.times {vote_array << "ABCD".split("")}
67 26.times {vote_array << "BCDA".split("")}
68 15.times {vote_array << "CDBA".split("")}
69 15.times {vote_array << "DCBA".split("")}
71 assert_equal( "B", InstantRunoffLogicVote.new(vote_array).result.winners[0] )
73 ###TODO: test all the other variants