Added tie-breaking rules and multicandidate elimination of weak candidates
[rubyvote] / test / irv_test.rb
1 #!/usr/bin/ruby
2
3 require 'test/unit'
4 require 'election_test_helper'
5
6 class TestRunoffVote < Test::Unit::TestCase
7   include ElectionTestHelper
8
9   def test_irv
10     vote_array = Array.new
11     142.times {vote_array << "ABCD".split("")}
12     26.times {vote_array << "BCDA".split("")}
13     15.times {vote_array << "CDBA".split("")}
14     17.times {vote_array << "DCBA".split("")}
15
16     test_winner( "A", InstantRunoffVote.new(vote_array).result )
17   end
18
19   def test_irv2
20     vote_array = Array.new
21     42.times {vote_array << "ABCD".split("")}
22     26.times {vote_array << "BCDA".split("")}
23     15.times {vote_array << "CDBA".split("")}
24     17.times {vote_array << "DCBA".split("")}
25
26     test_winner( "D", InstantRunoffVote.new(vote_array).result )
27   end
28
29   def test_irv3
30     vote_array = Array.new
31     42.times {vote_array << "ABCD".split("")}
32     26.times {vote_array << "ACBD".split("")}
33     15.times {vote_array << "BACD".split("")}
34     32.times {vote_array << "BCAD".split("")}
35     14.times {vote_array << "CABD".split("")}
36     49.times {vote_array << "CBAD".split("")}
37     17.times {vote_array << "ABDC".split("")}
38     23.times {vote_array << "BADC".split("")}
39     37.times {vote_array << "BCDA".split("")}
40     11.times {vote_array << "CADB".split("")}
41     16.times {vote_array << "CBDA".split("")}
42     54.times {vote_array << "ADBC".split("")}
43     36.times {vote_array << "BDCA".split("")}
44     42.times {vote_array << "CDAB".split("")}
45     13.times {vote_array << "CDBA".split("")}
46     51.times {vote_array << "DABC".split("")}
47     33.times {vote_array << "DBCA".split("")}
48     39.times {vote_array << "DCAB".split("")}
49     12.times {vote_array << "DCBA".split("")}
50
51     test_winner( "C", InstantRunoffVote.new(vote_array).result )
52   end
53
54   def test_irv_logic1
55     vote_array = Array.new
56     42.times {vote_array << "ABCD".split("")}
57     26.times {vote_array << "BCDA".split("")}
58     15.times {vote_array << "CDBA".split("")}
59     15.times {vote_array << "DCBA".split("")}
60
61     test_winner ( "B", InstantRunoffLogicVote.new(vote_array).result )
62   end
63   ###TODO: test all the other variants
64 end
65

Benjamin Mako Hill || Want to submit a patch?