7b49bc66eda4f79f3cb6d2e623e88f145280b488
[rubyvote] / test / condorcet_test.rb
1 #!/usr/bin/ruby
2
3 require 'test/unit'
4 require 'election_test_helper'
5
6 class TestCondorcetVote < Test::Unit::TestCase
7   include ElectionTestHelper
8
9   def test_condorcet
10     vote_array = Array.new
11     3.times {vote_array << "ABC".split("")}
12     3.times {vote_array << "CBA".split("")}
13     2.times {vote_array << "BAC".split("")}
14
15     test_winner( ["B"], PureCondorcetVote.new(vote_array).result )
16   end
17
18   def test_ssd
19     vote_array = Array.new
20     5.times {vote_array << "ACBED".split("")}
21     5.times {vote_array << "ADECB".split("")}
22     8.times {vote_array << "BEDAC".split("")}
23     3.times {vote_array << "CABED".split("")}
24     7.times {vote_array << "CAEBD".split("")}
25     2.times {vote_array << "CBADE".split("")}
26     7.times {vote_array << "DCEBA".split("")}
27     8.times {vote_array << "EBADC".split("")}
28
29     test_winner( "E", CloneproofSSDVote.new(vote_array).result )
30   end
31
32   def test_ssd2
33     vote_array = Array.new
34     5.times {vote_array << "ACBD".split("")}
35     2.times {vote_array << "ACDB".split("")}
36     3.times {vote_array << "ADCB".split("")}
37     4.times {vote_array << "BACD".split("")}
38     3.times {vote_array << "CBDA".split("")}
39     3.times {vote_array << "CDBA".split("")}
40     1.times {vote_array << "DACB".split("")}
41     5.times {vote_array << "DBAC".split("")}
42     4.times {vote_array << "DCBA".split("")}
43
44     test_winner( "D", CloneproofSSDVote.new(vote_array).result )
45   end
46
47   def test_ssd3
48     vote_array = Array.new
49     3.times {vote_array << "ABCD".split("")}
50     2.times {vote_array << "DABC".split("")}
51     2.times {vote_array << "DBCA".split("")}
52     2.times {vote_array << "CBDA".split("")}
53
54     test_winner("B", CloneproofSSDVote.new(vote_array).result )
55   end
56 end

Benjamin Mako Hill || Want to submit a patch?