X-Git-Url: https://projects.mako.cc/source/rubyvote/blobdiff_plain/1da0a60f448820070d47333a7316364e009f203e..c9649b477b0e94c4f7f36e6d42225e0d6a113f57:/test/irv_test.rb diff --git a/test/irv_test.rb b/test/irv_test.rb index 49aa540..2974296 100644 --- a/test/irv_test.rb +++ b/test/irv_test.rb @@ -6,6 +6,12 @@ require 'rubyvote/irv' class TestRunoffVote < Test::Unit::TestCase + 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("")} @@ -50,7 +56,74 @@ class TestRunoffVote < Test::Unit::TestCase assert_equal( "C", InstantRunoffVote.new(vote_array).result.winners[0] ) end + + def test_irv4 + # this was causing selectricity to crash + + raw_vote_array = ["GFECADBIH", "ABCDEFGHI", "IGHBADFCE", + "FABCDEGHI", "ABCDEFGHI", "ABCDEFGHI", + "ABCDEFGHI", "ABCDEFGHI", "ABCDEFGHI", + "EHBICDAGF", "ECGDFBIAH", "BDHIGFECA", + "ECDBFIHAG", "FEDBCAHIG", "CDABHIEFG", + "FCBDIHAEG", "AIHFBECGD", "BACHDEFIG", + "CDEFIBHAG", "BDICAFEGH", "ABCDEFGHI", + "CBIHDFAEG", "ABCDEFGHI", "CDFIBAGEH", + "ECDBIFHGA", "BDACEHFIG", "CFDIHABEG", + "ADCFGBIHE", "CDHIBEAGF", "ABCFDHIEG", + "ABCDEFGHI", "DCFHIBAGE", "CDFEABHIG", + "DFHIBEAGC", "EDCBFIGAH", "BAECDFHGI", + "BAHCEDFGI", "HBCDIAFEG", "ABCDEFGHI", + "ABCDEFGHI", "EDCBIGAHF", "EIBDCGAFH", + "HIACGDFBE", "DEACBIFGH", "CIDEFABGH", + "ABHDIECGF", "ECIDBFGHA", "CEDFBHIGA", + "ABHCEIDFG", "CFDBEIHGA", "ICEDBGFAH", + "EDCIFBAGH", "ECFDBAHGI", "EBCADFIGH", + "EFBHAGICD", "CDBIEFAHG", "ABCDEFGHI", + "FCDBEIHGA", "AIEBDCFHG", "CDFEBIGAH", + "CABDEFGHI", "DCEIBFGHA", "EADCIBHFG", + "DBCAHIGEF", "EDFBCIAHG", "EDCBIHAGF", + "CFIAEDGHB", "CDEIHABGF", "CEBHIDAFG", + "BCFEDIHAG", "CDIHBFGEA", "CFEDIGBAH", + "IHFEADCBG", "EBDCIGAHF", "BCEDFIAGH", + "ABHEGICDF", "CABFHDIEG", "HEABDCFGI", + "CDEBFAIHG", "CDBFIHAGE", "ABGFEDHCI", + "IBHDCAEFG", "EBDICHAFG", "ABCDEFGHI", + "EFBHAICGD", "CBDFHAIEG", "CDBAEIHGF", + "ABCDEFGHI", "BECDHIFGA", "DAGCIHFBE", + "BIECDGAHF", "ABCDEFGHI", "ACDEBHIFG", + "AEBCIDHFG", "ABCDEFGHI", "ABCDEFGHI", + "ABCDEFGHI", "ABCDEFGHI", "ABCDEFGHI", + "ABCDEFGHI", "ECFDIHBAG", "BIDCHEAGF", + "BCEDFIGHA", "CBDAFEGHI", "ABCDEFGHI", + "FACEGDHBI", "ABCDEFGHI", "FDIBCGHAE", + "EBIHADCFG", "EDBIHAGCF", "AHDICBFEG", + "DCBIHAGFE", "CABFIDEHG", "IFCBHADEG", + "EDCFHIBAG", "DCABEFGHI", "FCBDIGHEA", + "ABCDEFGHI", "HBACIDEFG", "ABCDEFGHI", + "ABCDEFGHI", "EADCBIHGF", "BDCIHAGFE", + "ABCDEFGHI", "ABCDEFGHI", "ABCDEFGHI", + "ABCDEFGHI", "ABCDEFGHI", "ICDGAHBEF", + "EGBCFIHDA", "DFGACHIEB", "BCAGDFHIE", + "DBGHCEAFI", "IGHEBCADF", "FEDIHBCAG", + "HAICBGEFD", "EBFDAICGH", "ECGAHFIBD", + "GEFICAHDB", "ACEHGIBDF", "EGIFBHCAD", + "GHFEDCIBA", "DGAEHFICB", "HGDICBAFE", + "HEACGDBFI", "IAGDFHCEB", "EGIACHBDF", + "CBFGDIEAH", "CGAIBDEFH", "AHEDIGCBF", + "BAEFHIDCG", "BIDGAFCHE", "CHBAEDFIG", + "IBGCFADEH", "GHACDEFIB", "CFDBEAHIG", + "GDEFAICHB"] + vote_array = raw_vote_array.collect {|v| v.split("")} + print InstantRunoffVote.new(vote_array).result.winners, "\n" + assert_equal(true, InstantRunoffVote.new(vote_array).result.winner?) + 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("")}