X-Git-Url: https://projects.mako.cc/source/rubyvote/blobdiff_plain/60344b51d7e6c505492183b79b96b76216c95072..39441f5a3033c1eb4a5e0d4beeed2cc17a3e20cd:/test/irv_test.rb?ds=sidebyside diff --git a/test/irv_test.rb b/test/irv_test.rb index 640824c..d3a57a7 100644 --- a/test/irv_test.rb +++ b/test/irv_test.rb @@ -1,11 +1,17 @@ -#!/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_empty + vote_array = Array.new + assert_nil InstantRunoffVote.new(vote_array).result.winners[0] + assert_equal(false, InstantRunoffVote.new(vote_array).result.winner?) + end + def test_irv vote_array = Array.new 142.times {vote_array << "ABCD".split("")} @@ -13,7 +19,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 +29,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,9 +54,15 @@ 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_logic_empty + vote_array = Array.new + assert_nil InstantRunoffLogicVote.new(vote_array).result.winners[0] + assert_equal(false, InstantRunoffLogicVote.new(vote_array).result.winner?) + end + def test_irv_logic1 vote_array = Array.new 42.times {vote_array << "ABCD".split("")} @@ -58,7 +70,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