summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2020-05-22 00:38:52 +0200
committeremkael <emkael@tlen.pl>2020-05-22 00:38:52 +0200
commitb17af1816fcc0b5803fcba813350ce6eb1381c79 (patch)
tree93f869c13032ede37cd97441e93f917518241e69 /test
parentec2fa285592acc41dd44cf97a2cacca71f8c8b9e (diff)
Tests for consistent rounding when "stretching" points to the last place instaead of 50%
Diffstat (limited to 'test')
-rw-r--r--test/DoublePointsTest.php45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/DoublePointsTest.php b/test/DoublePointsTest.php
new file mode 100644
index 0000000..a98a5b4
--- /dev/null
+++ b/test/DoublePointsTest.php
@@ -0,0 +1,45 @@
+<?php
+
+use PHPUnit\Framework\TestCase;
+
+require_once(dirname(__FILE__) . '/../http/api-inc.php');
+
+class DoublePointsTest extends TestCase {
+
+
+ /**
+ * @dataProvider dataGenerator
+ */
+ public function testPointStretch($points, $players) {
+ $params = [
+ 'type' => 2,
+ 'contestants' => $players,
+ 'manual' => [
+ 'min_points' => $points
+ ]
+ ];
+ $doubleContestants = $params;
+ $doubleContestants['contestants'] *= 2;
+ $doubleContestantsResults = run($doubleContestants);
+ $doubleContestantsResults['points'] = array_slice(
+ $doubleContestantsResults['points'], 0, $players, TRUE);
+ $doubleContestantsResults['sum'] = array_sum($doubleContestantsResults['points']) * 2;
+ $stretchFunction = $params;
+ $stretchFunction['manual']['points_cutoffs'] = [
+ [0.04, 0.9], [0.4, 0.2], [1.0, 0.0]
+ ];
+ $stretchFunctionResults = run($stretchFunction);
+ $this->assertEquals($stretchFunctionResults, $doubleContestantsResults);
+ }
+
+ public function dataGenerator() {
+ for ($maxPoints = 10; $maxPoints <= 250; $maxPoints += 5) {
+ for ($players = 10; $players < $maxPoints; $players += 1) {
+ yield [$maxPoints, $players];
+ }
+ }
+ }
+
+}
+
+?>