Page MenuHomePhabricator
Paste P17058

testDeclareEliminated_STVTallierTest.patch
ActivePublic

Authored by dom_walden on Aug 22 2021, 11:52 AM.
Tags
None
Referenced Files
F34615568: testDeclareEliminated_STVTallierTest.patch
Aug 22 2021, 11:52 AM
Subscribers
None
diff --git a/tests/phpunit/unit/STVTallierTest.php b/tests/phpunit/unit/STVTallierTest.php
index 6730e5a..0822a5e 100644
--- a/tests/phpunit/unit/STVTallierTest.php
+++ b/tests/phpunit/unit/STVTallierTest.php
@@ -100,6 +100,99 @@ class STVTallierTest extends MediaWikiUnitTestCase {
];
}
+ public static function testDeclareEliminatedProvider() {
+ return [
+ [
+ // Example from 12_9_4828_204236991
+ [
+ 1 => ['total' => 482],
+ 2 => ['total' => 205.00000000000304],
+ 3 => ['total' => 205],
+ ],
+ 0,
+ [],
+ [3],
+ ],
+ [
+ // Example from 12_9_4828_204236991
+ [
+ 1 => ['total' => 482],
+ 2 => ['total' => 205.00000000000304],
+ 3 => ['total' => 205],
+ ],
+ 1,
+ [],
+ [],
+ ],
+ [
+ // Example from 12_9_5000_1830523430
+ [
+ 1 => ['total' => 500.000001],
+ 2 => ['total' => 248.0],
+ 3 => ['total' => 248],
+ ],
+ 0,
+ [],
+ [2, 3],
+ ],
+ [
+ // Example from 12_9_5000_1830523430
+ [
+ 1 => ['total' => 500.000001],
+ 2 => ['total' => 248.0],
+ 3 => ['total' => 248],
+ ],
+ 1,
+ [],
+ [2, 3],
+ ],
+ [
+ // Example from 12_9_5000_1830523430
+ [
+ 1 => ['total' => 500.000001],
+ 2 => ['total' => 248],
+ 3 => ['total' => 248.0],
+ ],
+ 0,
+ [],
+ [2, 3],
+ ],
+ [
+ // Example from 12_9_5000_1830523430
+ [
+ 1 => ['total' => 500.000001],
+ 2 => ['total' => 248],
+ 3 => ['total' => 248.0],
+ ],
+ 1,
+ [],
+ [2, 3],
+ ],
+ [
+ // Example from 12_9_4808_1919647607
+ [
+ 1 => ['total' => 480],
+ 2 => ['total' => 200.00000000000699],
+ 3 => ['total' => 200],
+ ],
+ 0,
+ [],
+ [3],
+ ],
+ [
+ // Example from 12_9_4808_1919647607
+ [
+ 1 => ['total' => 480],
+ 2 => ['total' => 200.00000000000699],
+ 3 => ['total' => 200],
+ ],
+ 1,
+ [],
+ [],
+ ],
+ ];
+ }
+
public function testFactory() {
$this->assertInstanceOf( STVTallier::class, $this->tallier );
}
@@ -148,4 +241,13 @@ class STVTallierTest extends MediaWikiUnitTestCase {
$expectedRounds = count( $expected[ 'rounds'] );
$this->assertCount( $expectedRounds, $this->tallier->resultsLog['rounds'] );
}
+
+ /**
+ * @dataProvider testDeclareEliminatedProvider
+ * @covers \MediaWiki\Extensions\SecurePoll\Talliers\STVTallier::declareEliminated
+ */
+ public function testDeclareEliminated( $ranking, $surplus, $eliminated, $expected ) {
+ $actual = TestingAccessWrapper::newFromObject( $this->tallier )->declareEliminated( $ranking, $surplus, $eliminated );
+ $this->assertSame( $expected, $actual );
+ }
}