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] )
61 # this was causing selectricity to crash
63 raw_vote_array = ["GFECADBIH", "ABCDEFGHI", "IGHBADFCE",
64 "FABCDEGHI", "ABCDEFGHI", "ABCDEFGHI",
65 "ABCDEFGHI", "ABCDEFGHI", "ABCDEFGHI",
66 "EHBICDAGF", "ECGDFBIAH", "BDHIGFECA",
67 "ECDBFIHAG", "FEDBCAHIG", "CDABHIEFG",
68 "FCBDIHAEG", "AIHFBECGD", "BACHDEFIG",
69 "CDEFIBHAG", "BDICAFEGH", "ABCDEFGHI",
70 "CBIHDFAEG", "ABCDEFGHI", "CDFIBAGEH",
71 "ECDBIFHGA", "BDACEHFIG", "CFDIHABEG",
72 "ADCFGBIHE", "CDHIBEAGF", "ABCFDHIEG",
73 "ABCDEFGHI", "DCFHIBAGE", "CDFEABHIG",
74 "DFHIBEAGC", "EDCBFIGAH", "BAECDFHGI",
75 "BAHCEDFGI", "HBCDIAFEG", "ABCDEFGHI",
76 "ABCDEFGHI", "EDCBIGAHF", "EIBDCGAFH",
77 "HIACGDFBE", "DEACBIFGH", "CIDEFABGH",
78 "ABHDIECGF", "ECIDBFGHA", "CEDFBHIGA",
79 "ABHCEIDFG", "CFDBEIHGA", "ICEDBGFAH",
80 "EDCIFBAGH", "ECFDBAHGI", "EBCADFIGH",
81 "EFBHAGICD", "CDBIEFAHG", "ABCDEFGHI",
82 "FCDBEIHGA", "AIEBDCFHG", "CDFEBIGAH",
83 "CABDEFGHI", "DCEIBFGHA", "EADCIBHFG",
84 "DBCAHIGEF", "EDFBCIAHG", "EDCBIHAGF",
85 "CFIAEDGHB", "CDEIHABGF", "CEBHIDAFG",
86 "BCFEDIHAG", "CDIHBFGEA", "CFEDIGBAH",
87 "IHFEADCBG", "EBDCIGAHF", "BCEDFIAGH",
88 "ABHEGICDF", "CABFHDIEG", "HEABDCFGI",
89 "CDEBFAIHG", "CDBFIHAGE", "ABGFEDHCI",
90 "IBHDCAEFG", "EBDICHAFG", "ABCDEFGHI",
91 "EFBHAICGD", "CBDFHAIEG", "CDBAEIHGF",
92 "ABCDEFGHI", "BECDHIFGA", "DAGCIHFBE",
93 "BIECDGAHF", "ABCDEFGHI", "ACDEBHIFG",
94 "AEBCIDHFG", "ABCDEFGHI", "ABCDEFGHI",
95 "ABCDEFGHI", "ABCDEFGHI", "ABCDEFGHI",
96 "ABCDEFGHI", "ECFDIHBAG", "BIDCHEAGF",
97 "BCEDFIGHA", "CBDAFEGHI", "ABCDEFGHI",
98 "FACEGDHBI", "ABCDEFGHI", "FDIBCGHAE",
99 "EBIHADCFG", "EDBIHAGCF", "AHDICBFEG",
100 "DCBIHAGFE", "CABFIDEHG", "IFCBHADEG",
101 "EDCFHIBAG", "DCABEFGHI", "FCBDIGHEA",
102 "ABCDEFGHI", "HBACIDEFG", "ABCDEFGHI",
103 "ABCDEFGHI", "EADCBIHGF", "BDCIHAGFE",
104 "ABCDEFGHI", "ABCDEFGHI", "ABCDEFGHI",
105 "ABCDEFGHI", "ABCDEFGHI", "ICDGAHBEF",
106 "EGBCFIHDA", "DFGACHIEB", "BCAGDFHIE",
107 "DBGHCEAFI", "IGHEBCADF", "FEDIHBCAG",
108 "HAICBGEFD", "EBFDAICGH", "ECGAHFIBD",
109 "GEFICAHDB", "ACEHGIBDF", "EGIFBHCAD",
110 "GHFEDCIBA", "DGAEHFICB", "HGDICBAFE",
111 "HEACGDBFI", "IAGDFHCEB", "EGIACHBDF",
112 "CBFGDIEAH", "CGAIBDEFH", "AHEDIGCBF",
113 "BAEFHIDCG", "BIDGAFCHE", "CHBAEDFIG",
114 "IBGCFADEH", "GHACDEFIB", "CFDBEAHIG",
116 vote_array = raw_vote_array.collect {|v| v.split("")}
117 print InstantRunoffVote.new(vote_array).result.winners, "\n"
118 assert_equal(true, InstantRunoffVote.new(vote_array).result.winner?)
121 def test_irv_logic_empty
122 vote_array = Array.new
123 assert_nil InstantRunoffLogicVote.new(vote_array).result.winners[0]
124 assert_equal(false, InstantRunoffLogicVote.new(vote_array).result.winner?)
128 vote_array = Array.new
129 42.times {vote_array << "ABCD".split("")}
130 26.times {vote_array << "BCDA".split("")}
131 15.times {vote_array << "CDBA".split("")}
132 15.times {vote_array << "DCBA".split("")}
134 assert_equal( "B", InstantRunoffLogicVote.new(vote_array).result.winners[0] )
136 ###TODO: test all the other variants