From 5d79047d6c30431af56aea87b34d9d8b3482b370 Mon Sep 17 00:00:00 2001 From: Theodore Brown Date: Wed, 5 Apr 2023 07:26:24 -0500 Subject: [PATCH] Fix error when a tie occurs --- php/StvElection.php | 4 + test/cases/rm_election_83_before_finish.html | 729 +++++++++++++++++++ test/php/WikiParserTest.php | 49 ++ 3 files changed, 782 insertions(+) create mode 100644 test/cases/rm_election_83_before_finish.html diff --git a/php/StvElection.php b/php/StvElection.php index 49dd238..5cac206 100644 --- a/php/StvElection.php +++ b/php/StvElection.php @@ -192,6 +192,10 @@ public function runElection(): array } } + if (count($baseTally) === 0) { + break; // there was a tie + } + $round = new ElectionRound($roundNum, $ballots, $baseTally, $allElected, $allEliminated, $this); $pastRounds[] = $round; $elected = $round->elected; diff --git a/test/cases/rm_election_83_before_finish.html b/test/cases/rm_election_83_before_finish.html new file mode 100644 index 0000000..2999b42 --- /dev/null +++ b/test/cases/rm_election_83_before_finish.html @@ -0,0 +1,729 @@ + + + + + + + PHP: todo:php83 + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+
+ + +
+ + + + +
+ +
+ + +
+ + + +
+ +
todo:php83
+ +
+ + +

PHP 8.3 Preparation Tasks

+
+
    +
  • Elect managers
    +
  • +
  • Triage GitHub issues for PHP 8.3
    +
  • +
  • Triage GitHub pull requests
    +
  • +
  • Push appropriate RFC at appropriate time
    +
  • +
+ +
+ +

Timetable

+
+ +

+Based upon a target GA in late November. Individual releases may be added or removed to accommodate development progress. +

+
    +
  • Tag on Tuesday, release on Thursday
    +
  • +
  • 6 months pre-release phase
    +
  • +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Date Release
Jun 08 2023 Alpha 1
Jun 22 2023 Alpha 2
Jul 06 2023 Alpha 3
Jul 18 2023 Feature freeze
Jul 20 2023 Beta 1
Aug 03 2023 Beta 2
Aug 17 2023 Beta 3
Aug 31 2023 RC 1
Sep 14 2023 RC 2
Sep 28 2023 RC 3
Oct 12 2023 RC 4
Oct 26 2023 RC 5
Nov 09 2023 RC 6
Nov 23 2023 GA
+ +
+ +

Release Managers

+
+
    +
  • Veteran: Pierrick Charron
    +
  • +
  • Rookie: TBA
    +
  • +
  • Rookie: TBA
    +
  • +
+ +
+ +

Volunteers

+
+ +

+This list only contains individuals who have formally and publicly volunteered via the internals mailing list. +

+ +

+Veteran volunteer(s): +

+ + +

+Rookie candidates listed in the order in which they formally volunteered: +

+ + +
+ +

Voting

+
+ +

+There are three candidates for two available seats. While it might not be likely that all preferences are necessary, you are encouraged to use all votes. If you vote for the same person twice, this will not help that person's chances, it will only throw away one of your votes and deprioritize the remaining ones, so please cast unique votes. +

+ +

+Voting using STV (Single Transferrable Vote) started on Apr 01, 2023. Voting will be open until Apr 16, 2023 12:00:00 UTC. Tie breaking will be at the discretion of the prior branch RMs. +

+ +
+ +

1st Preference

+
+ +

+Select your first preference for 8.3 Release Manager here. +

+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ PHP 8.3 RM 1st Preference
Real nameE MannC BuckleyJ Zelenka
+ beberlei (beberlei)   
+ derick (derick)   
+ evvc (evvc)   
+ girgias (girgias)   
+ heiglandreas (heiglandreas)   
+ ilutov (ilutov)   
+ kalle (kalle)   
+ mauricio (mauricio)   
+ mbeccati (mbeccati)   
+ mike (mike)   
+ pierrick (pierrick)   
+ pollita (pollita)   
+ remi (remi)   
+ sebastian (sebastian)   
+ sergey (sergey)   
+ svpernova09 (svpernova09)   
+ theodorejb (theodorejb)   
+ timwolla (timwolla)   
+ trowski (trowski)   
+ weierophinney (weierophinney)   
Count:3017
+ +
+ + + + + +
+ +

2nd Preference

+
+ +

+Select your second preference for 8.3 Release Manager here. +

+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ PHP 8.3 RM 2nd Preference
Real nameE MannC BuckleyJ Zelenka
+ beberlei (beberlei)   
+ derick (derick)   
+ evvc (evvc)   
+ girgias (girgias)   
+ heiglandreas (heiglandreas)   
+ ilutov (ilutov)   
+ kalle (kalle)   
+ mauricio (mauricio)   
+ mbeccati (mbeccati)   
+ mike (mike)   
+ pierrick (pierrick)   
+ pollita (pollita)   
+ remi (remi)   
+ sergey (sergey)   
+ svpernova09 (svpernova09)   
+ theodorejb (theodorejb)   
+ timwolla (timwolla)   
+ trowski (trowski)   
+ weierophinney (weierophinney)   
Count:5113
+ +
+ + + + + +
+ +

3rd Preference

+
+ +

+Select your third preference for 8.3 Release Manager here. +

+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ PHP 8.3 RM 3rd Preference
Real nameE MannC BuckleyJ Zelenka
+ beberlei (beberlei)   
+ derick (derick)   
+ evvc (evvc)   
+ girgias (girgias)   
+ heiglandreas (heiglandreas)   
+ ilutov (ilutov)   
+ kalle (kalle)   
+ mauricio (mauricio)   
+ mbeccati (mbeccati)   
+ mike (mike)   
+ pierrick (pierrick)   
+ pollita (pollita)   
+ remi (remi)   
+ sergey (sergey)   
+ svpernova09 (svpernova09)   
+ theodorejb (theodorejb)   
+ timwolla (timwolla)   
+ trowski (trowski)   
+ weierophinney (weierophinney)   
Count:1180
+ +
+ + + + + +
+ + +
+ +
todo/php83.txt · Last modified: 2023/03/31 20:07 by sergey
+ +
+ +
+ + + +
+ +
+ +
+
+
+ +
+ + + +
+
+ + +
+ + diff --git a/test/php/WikiParserTest.php b/test/php/WikiParserTest.php index 792b6bc..df21e16 100644 --- a/test/php/WikiParserTest.php +++ b/test/php/WikiParserTest.php @@ -75,6 +75,55 @@ public function testRmElection(): void ], $thirdRound->tally); } + public function testRmElection83WithTie(): void + { + $html = WikiParser::getHtml('test/cases/rm_election_83_before_finish.html'); + $election = WikiParser::getStvElection($html, false); + + $this->assertFalse($election->isClosed); + $this->assertCount(3, $election->candidates); + $this->assertCount(20, $election->validBallots); + $this->assertSame(7, $election->quota); + + $rounds = $election->runElection(); + $this->assertCount(2, $rounds); + + // round 1 + $firstRound = $rounds[0]; + $this->assertEmpty($firstRound->getTransfers()); + $this->assertEmpty($firstRound->eliminated); + + $firstElected = $firstRound->elected[0]; + $this->assertSame('J Zelenka', $firstElected->name); + $this->assertSame(10, $firstElected->surplus); + + $this->assertSame([ + 'E Mann' => 3, + 'C Buckley' => 0, + 'J Zelenka' => 17, + ], $firstRound->tally); + + $this->assertEquals([ + new CandidateCount('C Buckley', 6, 'floor((11 / 16) * 10)'), + new CandidateCount('E Mann', 3, 'floor((5 / 16) * 10)'), + ], $firstElected->transfers); + + // round 2 + $secondRound = $rounds[1]; + $this->assertEmpty($secondRound->getTransfers()); + $this->assertEmpty($secondRound->elected); + + $this->assertEquals([ + new CandidateCount('E Mann', 6), + new CandidateCount('C Buckley', 6), + ], $secondRound->eliminated); + + $this->assertSame([ + 'E Mann' => 6, + 'C Buckley' => 6, + ], $secondRound->tally); + } + public function testShorterAttributeSyntax(): void { $html = WikiParser::getHtml('test/cases/shorter_attribute_syntax.html');