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]
12 assert_equal(false, InstantRunoffVote.new(vote_array).result.winner?)
16 vote_array = Array.new
17 142.times {vote_array << "ABCD".split("")}
18 26.times {vote_array << "BCDA".split("")}
19 15.times {vote_array << "CDBA".split("")}
20 17.times {vote_array << "DCBA".split("")}
22 assert_equal( "A", InstantRunoffVote.new(vote_array).result.winners[0] )
26 vote_array = Array.new
27 42.times {vote_array << "ABCD".split("")}
28 26.times {vote_array << "BCDA".split("")}
29 15.times {vote_array << "CDBA".split("")}
30 17.times {vote_array << "DCBA".split("")}
32 assert_equal( "D", InstantRunoffVote.new(vote_array).result.winners[0] )
36 vote_array = Array.new
37 42.times {vote_array << "ABCD".split("")}
38 26.times {vote_array << "ACBD".split("")}
39 15.times {vote_array << "BACD".split("")}
40 32.times {vote_array << "BCAD".split("")}
41 14.times {vote_array << "CABD".split("")}
42 49.times {vote_array << "CBAD".split("")}
43 17.times {vote_array << "ABDC".split("")}
44 23.times {vote_array << "BADC".split("")}
45 37.times {vote_array << "BCDA".split("")}
46 11.times {vote_array << "CADB".split("")}
47 16.times {vote_array << "CBDA".split("")}
48 54.times {vote_array << "ADBC".split("")}
49 36.times {vote_array << "BDCA".split("")}
50 42.times {vote_array << "CDAB".split("")}
51 13.times {vote_array << "CDBA".split("")}
52 51.times {vote_array << "DABC".split("")}
53 33.times {vote_array << "DBCA".split("")}
54 39.times {vote_array << "DCAB".split("")}
55 12.times {vote_array << "DCBA".split("")}
57 assert_equal( "C", InstantRunoffVote.new(vote_array).result.winners[0] )
60 def test_irv_logic_empty
61 vote_array = Array.new
62 assert_nil InstantRunoffLogicVote.new(vote_array).result.winners[0]
63 assert_equal(false, InstantRunoffLogicVote.new(vote_array).result.winner?)
67 vote_array = Array.new
68 42.times {vote_array << "ABCD".split("")}
69 26.times {vote_array << "BCDA".split("")}
70 15.times {vote_array << "CDBA".split("")}
71 15.times {vote_array << "DCBA".split("")}
73 assert_equal( "B", InstantRunoffLogicVote.new(vote_array).result.winners[0] )
75 ###TODO: test all the other variants