o Verify that all tests in test.rb are present in test/*_test.rb files,
authorJoe Slag <joe@slagwerks.com>
Tue, 13 Mar 2007 13:35:38 +0000 (13:35 +0000)
committerJoe Slag <joe@slagwerks.com>
Tue, 13 Mar 2007 13:35:38 +0000 (13:35 +0000)
  remove test.rb

o Convert tests to run silent when successful, remove
  test/election_test_helper.rb

git-svn-id: svn://rubyforge.org/var/svn/rubyvote/trunk@15 1440c7f4-e209-0410-9a04-881b5eb134a8

test.rb [deleted file]
test/condorcet_test.rb
test/election_test.rb
test/election_test_helper.rb [deleted file]
test/irv_test.rb
test/positional_test.rb
test/range_test.rb

diff --git a/test.rb b/test.rb
deleted file mode 100755 (executable)
index 3c73ffa..0000000
--- a/test.rb
+++ /dev/null
@@ -1,164 +0,0 @@
-#!/usr/bin/ruby -I./lib
-
-# election library -- a ruby library for elections
-# copyright © 2005 MIT Media Lab and Benjamin Mako Hill
-
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301, USA.
-
-require 'test/unit'
-require 'lib/rubyvote'
-
-class TestRubyvote < Test::Unit::TestCase
-
-  def test_condorcet
-    vote_array = Array.new
-    3.times {vote_array << "ABC".split("")}
-    3.times {vote_array << "CBA".split("")}
-    2.times {vote_array << "BAC".split("")}
-
-    assert_equal 'B', PureCondorcetVote.new(vote_array).result.winners[0][0]
-  end
-
-  def test_ssd_1
-    vote_array = Array.new
-    5.times {vote_array << "ACBED".split("")}
-    5.times {vote_array << "ADECB".split("")}
-    8.times {vote_array << "BEDAC".split("")}
-    3.times {vote_array << "CABED".split("")}
-    7.times {vote_array << "CAEBD".split("")}
-    2.times {vote_array << "CBADE".split("")}
-    7.times {vote_array << "DCEBA".split("")}
-    8.times {vote_array << "EBADC".split("")}
-
-    assert_equal 'E', CloneproofSSDVote.new(vote_array).result.winners[0]
-  end
-
-  def test_ssd_2
-    vote_array = Array.new
-    5.times {vote_array << "ACBD".split("")}
-    2.times {vote_array << "ACDB".split("")}
-    3.times {vote_array << "ADCB".split("")}
-    4.times {vote_array << "BACD".split("")}
-    3.times {vote_array << "CBDA".split("")}
-    3.times {vote_array << "CDBA".split("")}
-    1.times {vote_array << "DACB".split("")}
-    5.times {vote_array << "DBAC".split("")}
-    4.times {vote_array << "DCBA".split("")}
-
-    assert_equal 'D', CloneproofSSDVote.new(vote_array).result.winners[0]
-  end
-
-  def test_ssd_3
-    vote_array = Array.new
-    3.times {vote_array << "ABCD".split("")}
-    2.times {vote_array << "DABC".split("")}
-    2.times {vote_array << "DBCA".split("")}
-    2.times {vote_array << "CBDA".split("")}
-
-    assert_equal 'B', CloneproofSSDVote.new(vote_array).result.winners[0]
-  end
-
-  def test_borda
-    vote_array = Array.new
-    3.times {vote_array << "ABC".split("")}
-    3.times {vote_array << "CBA".split("")}
-    2.times {vote_array << "BAC".split("")}
-
-    assert_equal 'B', BordaVote.new(vote_array).result.winners[0]
-  end
-
-  def test_plurality
-    vote_array = "ABCABCABCCCBBAAABABABCCCCCCCCCCCCCA".split("")
-
-    assert_equal 'C', PluralityVote.new(vote_array).result.winners[0]
-  end
-
-  def test_approval
-    vote_array = Array.new
-    10.times {vote_array << "AB".split("")}
-    10.times {vote_array << "CB".split("")}
-    11.times {vote_array << "AC".split("")}
-    5.times {vote_array << "A".split("")}
-
-    assert_equal 'A', ApprovalVote.new(vote_array).result.winners[0] 
-  end
-
-  def test_irv_1
-    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("")}
-
-    assert_equal 'A', InstantRunoffVote.new(vote_array).result.winners[0]
-  end
-
-  def test_irv_2
-    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("")}
-
-    assert_equal 'D', InstantRunoffVote.new(vote_array).result.winners[0]
-  end
-
-  def test_irv_3
-    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("")}
-
-    assert_equal 'C', InstantRunoffVote.new(vote_array).result.winners[0]
-  end
-
-  def test_irvlogic
-    vote_array = Array.new
-    42.times {vote_array << "ABCD".split("")}
-    26.times {vote_array << "BCDA".split("")}
-    15.times {vote_array << "CDBA".split("")}
-    15.times {vote_array << "DCBA".split("")}
-
-    assert_equal 'B', InstantRunoffLogicVote.new(vote_array).result
-  end
-
-  def test_range1
-    vote_array = Array.new
-    42.times {vote_array << {:A => 10, :B => 5, :C => 2, :D => 1}}
-    26.times {vote_array << {:A => 1, :B => 10, :C => 5, :D => 2}}
-    15.times {vote_array << {:A => 1, :B => 2, :C => 10, :D => 5}}
-    17.times {vote_array << {:A => 1, :B => 2, :C => 5, :D => 10}}
-
-    assert_equal 'B', RangeVote.new(vote_array).result
-  end
-
-end
index 7b49bc66eda4f79f3cb6d2e623e88f145280b488..7ae4a70c2e9e43e2b3a6e5b8b1f0501052c583df 100644 (file)
@@ -1,10 +1,10 @@
-#!/usr/bin/ruby
+#!/usr/bin/ruby -Ilib
 
 require 'test/unit'
-require 'election_test_helper'
+require 'rubyvote/election'
+require 'rubyvote/condorcet'
 
 class TestCondorcetVote < Test::Unit::TestCase
-  include ElectionTestHelper
 
   def test_condorcet
     vote_array = Array.new
@@ -12,7 +12,7 @@ class TestCondorcetVote < Test::Unit::TestCase
     3.times {vote_array << "CBA".split("")}
     2.times {vote_array << "BAC".split("")}
 
-    test_winner( ["B"], PureCondorcetVote.new(vote_array).result )
+    assert_equal ["B"], PureCondorcetVote.new(vote_array).result.winners[0]
   end
 
   def test_ssd
@@ -26,7 +26,7 @@ class TestCondorcetVote < Test::Unit::TestCase
     7.times {vote_array << "DCEBA".split("")}
     8.times {vote_array << "EBADC".split("")}
 
-    test_winner( "E", CloneproofSSDVote.new(vote_array).result )
+    assert_equal "E", CloneproofSSDVote.new(vote_array).result.winners[0]
   end
 
   def test_ssd2
@@ -41,7 +41,7 @@ class TestCondorcetVote < Test::Unit::TestCase
     5.times {vote_array << "DBAC".split("")}
     4.times {vote_array << "DCBA".split("")}
 
-    test_winner( "D", CloneproofSSDVote.new(vote_array).result )
+    assert_equal "D", CloneproofSSDVote.new(vote_array).result.winners[0] 
   end
 
   def test_ssd3
@@ -51,6 +51,6 @@ class TestCondorcetVote < Test::Unit::TestCase
     2.times {vote_array << "DBCA".split("")}
     2.times {vote_array << "CBDA".split("")}
 
-    test_winner("B", CloneproofSSDVote.new(vote_array).result )
+    assert_equal "B", CloneproofSSDVote.new(vote_array).result.winners[0]
   end
 end
index b182e2d7619d63b46c277990b4f02694de151a67..e8a9c452f1cb7c8f1f2993d66591e32f61692ab4 100644 (file)
@@ -1,15 +1,14 @@
-#!/usr/bin/ruby
+#!/usr/bin/ruby -Ilib
 
 require 'test/unit'
-require 'election_test_helper'
+require 'rubyvote/election'
 
 class TestElectionVote < Test::Unit::TestCase
-  include ElectionTestHelper
 
   def test_plurality
     vote_array = "ABCABCABCCCBBAAABABABCCCCCCCCCCCCCA".split("")
 
-    test_winner( "C", PluralityVote.new(vote_array).result )
+    assert_equal( "C", PluralityVote.new(vote_array).result.winners[0] )
   end
 
 
@@ -20,7 +19,7 @@ class TestElectionVote < Test::Unit::TestCase
     11.times {vote_array << "AC".split("")}
     5.times {vote_array << "A".split("")}
 
-    test_winner( "A", ApprovalVote.new(vote_array).result )
+    assert_equal( "A", ApprovalVote.new(vote_array).result.winners[0] )
   end
 end
 
diff --git a/test/election_test_helper.rb b/test/election_test_helper.rb
deleted file mode 100644 (file)
index abc37cd..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-$:.unshift(File.dirname(__FILE__) + "/../lib/")
-
-require 'rubyvote'
-
-module ElectionTestHelper
-  def test_winner(expected, result) 
-    puts "\nUsing the #{result.class.to_s.gsub(/Result/,'')} voting method..."
-
-    if result.winner?
-      if expected.is_a?(Array) && expected.length > 1 # Array is passed to test for a tie!
-        msg = "There is a tie: %s" % result.winners.join(", ")
-
-        assert_equal(expected.length, result.winners.length, 
-                     "Not the correct number of winners!")
-        assert(expected.all?{|c| result.winners.include?(c)}, 
-               "Tie winners do not match expected!")
-      else 
-        msg = "There is a single winner: #{result.winners[0]}"
-        assert_equal(expected, result.winners[0], msg) 
-      end
-
-    else
-      msg = "There is no winner"
-      assert_nil(expected, msg)
-    end
-
-    puts msg
-  end
-end
index 920380672f5eb4d1d2fc7d562d0ba8454f9e93c1..49aa540e02a958bb1220ef22f47987e7d227b64d 100644 (file)
@@ -1,10 +1,10 @@
-#!/usr/bin/ruby
+#!/usr/bin/ruby -Ilib
 
 require 'test/unit'
-require 'election_test_helper'
+require 'rubyvote/election'
+require 'rubyvote/irv'
 
 class TestRunoffVote < Test::Unit::TestCase
-  include ElectionTestHelper
 
   def test_irv
     vote_array = Array.new
@@ -13,7 +13,7 @@ class TestRunoffVote < Test::Unit::TestCase
     15.times {vote_array << "CDBA".split("")}
     17.times {vote_array << "DCBA".split("")}
 
-    test_winner( "A", InstantRunoffVote.new(vote_array).result )
+    assert_equal( "A", InstantRunoffVote.new(vote_array).result.winners[0] )
   end
 
   def test_irv2
@@ -23,7 +23,7 @@ class TestRunoffVote < Test::Unit::TestCase
     15.times {vote_array << "CDBA".split("")}
     17.times {vote_array << "DCBA".split("")}
 
-    test_winner( "D", InstantRunoffVote.new(vote_array).result )
+    assert_equal( "D", InstantRunoffVote.new(vote_array).result.winners[0] )
   end
 
   def test_irv3
@@ -48,7 +48,7 @@ class TestRunoffVote < Test::Unit::TestCase
     39.times {vote_array << "DCAB".split("")}
     12.times {vote_array << "DCBA".split("")}
 
-    test_winner( "C", InstantRunoffVote.new(vote_array).result )
+    assert_equal( "C", InstantRunoffVote.new(vote_array).result.winners[0] )
   end
 
   def test_irv_logic1
@@ -58,7 +58,7 @@ class TestRunoffVote < Test::Unit::TestCase
     15.times {vote_array << "CDBA".split("")}
     15.times {vote_array << "DCBA".split("")}
 
-    test_winner( "B", InstantRunoffLogicVote.new(vote_array).result )
+    assert_equal( "B", InstantRunoffLogicVote.new(vote_array).result.winners[0] )
   end
   ###TODO: test all the other variants
 end
index 3f1fcfb147c7be50136dc4e34aace90883286d6d..a43709d60c298103847f48403e9b5794f8510d20 100644 (file)
@@ -1,10 +1,10 @@
-#!/usr/bin/ruby
+#!/usr/bin/ruby -Ilib
 
 require 'test/unit'
-require 'election_test_helper'
+require 'rubyvote/election'
+require 'rubyvote/positional'
 
 class TestPositionalVote < Test::Unit::TestCase
-  include ElectionTestHelper
 
   def test_borda
     vote_array = Array.new
@@ -12,7 +12,7 @@ class TestPositionalVote < Test::Unit::TestCase
     3.times {vote_array << "CBA".split("")}
     2.times {vote_array << "BAC".split("")}
 
-    test_winner( "B", BordaVote.new(vote_array).result )
+    assert_equal( "B", BordaVote.new(vote_array).result.winners[0] )
   end
 end
 
index 953df78385b7f3de890e5b88fa59efa7854a3dfe..26d8600e3b1d2650ed75ffa6418225d189d25d41 100644 (file)
@@ -1,10 +1,10 @@
-#!/usr/bin/ruby
+#!/usr/bin/ruby -Ilib
 
 require 'test/unit'
-require 'election_test_helper'
+require 'rubyvote/election'
+require 'rubyvote/range'
 
 class TestRangeVote < Test::Unit::TestCase
-  include ElectionTestHelper
 
   def test_range
     vote_array = []
@@ -13,7 +13,7 @@ class TestRangeVote < Test::Unit::TestCase
     15.times {vote_array << {'A' => 1, 'B' => 2, 'C' => 10, 'D' => 5}}
     17.times {vote_array << {'A' => 1, 'B' => 2, 'C' => 5, 'D' => 10}}
 
-    test_winner('B', RangeVote.new(vote_array).result )
+    assert_equal('B', RangeVote.new(vote_array).result.winners[0] )
   end
 
   def test_tie
@@ -21,12 +21,12 @@ class TestRangeVote < Test::Unit::TestCase
     10.times {vote_array << {'A' => 5, 'B' => 2}}
     10.times {vote_array << {'A' => 2, 'B' => 5}}
 
-    test_winner(['A','B'], RangeVote.new(vote_array).result )
+    assert_equal(['A','B'], RangeVote.new(vote_array).result.winners )
   end
 
   def test_no_win
     vote_array = []
 
-    test_winner(nil, RangeVote.new(vote_array).result )
+    assert_equal(nil, RangeVote.new(vote_array).result.winners[0] )
   end
 end

Benjamin Mako Hill || Want to submit a patch?