Added list of changes submitted by Jeff Rose <jeff@rosejn.net>.
[rubyvote] / test / runoff_test.rb
diff --git a/test/runoff_test.rb b/test/runoff_test.rb
new file mode 100644 (file)
index 0000000..d153dd6
--- /dev/null
@@ -0,0 +1,54 @@
+#!/usr/bin/ruby
+
+require 'test/unit'
+require 'election_test_helper'
+
+class TestRunoffVote < Test::Unit::TestCase
+  include ElectionTestHelper
+
+  def test_runoff
+    vote_array = Array.new
+    142.times {vote_array << "ABCD".split("")}
+    26.times {vote_array << "BCDA".split("")}
+    15.times {vote_array << "CDBA".split("")}
+    17.times {vote_array << "DCBA".split("")}
+
+    test_winner( "A", InstantRunoffVote.new(vote_array).result )
+  end
+
+  def test_runoff2
+    vote_array = Array.new
+    42.times {vote_array << "ABCD".split("")}
+    26.times {vote_array << "BCDA".split("")}
+    15.times {vote_array << "CDBA".split("")}
+    17.times {vote_array << "DCBA".split("")}
+
+    test_winner( "D", InstantRunoffVote.new(vote_array).result )
+  end
+
+  def test_runoff3
+    vote_array = Array.new
+    42.times {vote_array << "ABCD".split("")}
+    26.times {vote_array << "ACBD".split("")}
+    15.times {vote_array << "BACD".split("")}
+    32.times {vote_array << "BCAD".split("")}
+    14.times {vote_array << "CABD".split("")}
+    49.times {vote_array << "CBAD".split("")}
+    17.times {vote_array << "ABDC".split("")}
+    23.times {vote_array << "BADC".split("")}
+    37.times {vote_array << "BCDA".split("")}
+    11.times {vote_array << "CADB".split("")}
+    16.times {vote_array << "CBDA".split("")}
+    54.times {vote_array << "ADBC".split("")}
+    36.times {vote_array << "BDCA".split("")}
+    42.times {vote_array << "CDAB".split("")}
+    13.times {vote_array << "CDBA".split("")}
+    51.times {vote_array << "DABC".split("")}
+    33.times {vote_array << "DBCA".split("")}
+    39.times {vote_array << "DCAB".split("")}
+    12.times {vote_array << "DCBA".split("")}
+
+    test_winner( "C", InstantRunoffVote.new(vote_array).result )
+  end
+end
+

Benjamin Mako Hill || Want to submit a patch?