summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2020-05-14 17:40:39 +0200
committeremkael <emkael@tlen.pl>2020-05-14 17:40:39 +0200
commitce7a6f9efd2e9a4f2121a48b4e1b771e2f0b6ba8 (patch)
tree1365ee90aeff68eec5a8da67a77689b5f79bf012
parentaabc345b5a9479ae8bc01ef63ca5eed95a368e61 (diff)
Test code refactor + BridgeNET test cases
-rw-r--r--test/ApiTest.php35
-rw-r--r--test/bridgenet.txt26
2 files changed, 53 insertions, 8 deletions
diff --git a/test/ApiTest.php b/test/ApiTest.php
index 158c9dc..0a8290c 100644
--- a/test/ApiTest.php
+++ b/test/ApiTest.php
@@ -4,10 +4,7 @@ use PHPUnit\Framework\TestCase;
class ApiTest extends TestCase {
- /**
- * @dataProvider generatedDataProvider
- */
- public function testRandomResults($input, $expected) {
+ private function _doTest($input, $expected) {
require_once(dirname(__FILE__) . '/../http/api-inc.php');
if (is_string($expected)) {
$this->expectException(ParametersException::class);
@@ -21,15 +18,29 @@ class ApiTest extends TestCase {
/**
* @dataProvider generatedDataProvider
*/
+ public function testRandomResults($input, $expected) {
+ $this->_doTest($input, $expected);
+ }
+
+ /**
+ * @dataProvider generatedDataProvider
+ */
public function testBoardCounts($input, $expected) {
$input['boards'] = strval($input['over39_boards'] ? rand(40, 60) : rand(1, 39));
unset($input['over39_boards']);
- $this->testRandomResults($input, $expected);
+ $this->_doTest($input, $expected);
}
- public function generatedDataProvider() {
- $contents = file(dirname(__FILE__) . '/tests.txt');
- $count = count($contents) / 2;
+ /**
+ * @dataProvider bridgenetDataProvider
+ */
+ public function testBridgenet($input, $expected) {
+ $this->_doTest($input, $expected);
+ }
+
+ private function _fileDataProvider($file) {
+ $contents = file(dirname(__FILE__) . '/' . $file);
+ $count = count($contents);
for ($i = 0; $i < $count; $i += 2) {
$input = [];
parse_str(http_build_query(json_decode($contents[$i], TRUE)), $input);
@@ -37,6 +48,14 @@ class ApiTest extends TestCase {
}
}
+ public function generatedDataProvider() {
+ yield from $this->_fileDataProvider('tests.txt');
+ }
+
+ public function bridgenetDataProvider() {
+ yield from $this->_fileDataProvider('bridgenet.txt');
+ }
+
}
?>
diff --git a/test/bridgenet.txt b/test/bridgenet.txt
new file mode 100644
index 0000000..58c92bc
--- /dev/null
+++ b/test/bridgenet.txt
@@ -0,0 +1,26 @@
+{"tournament_rank": 102, "contestants": 35, "over39_boards": 0, "title_sum": 400, "type": 2}
+"Missing parameter: boards"
+{"tournament_rank": 102, "contestants": 35, "boards": -1, "title_sum": 400, "type": 2}
+"Parameter: boards has incorrect value (-1)"
+{"tournament_rank": 102, "contestants": 35, "boards": 100, "title_sum": 400, "type": 4}
+"Parameter: type has incorrect value (4) for BridgeNET tournament"
+{"tournament_rank": 102, "contestants": 35, "boards": 27, "title_sum": 100, "type": 2}
+{"sum": 74, "points": {"1": 5, "2": 5, "3": 4, "4": 4, "5": 3, "6": 3, "7": 2, "8": 1, "9": 1, "10": 1, "11": 1, "12": 1, "13": 1, "14": 1, "15": 1, "16": 1, "17": 1, "18": 1}}
+{"tournament_rank": 102, "contestants": 35, "boards": 47, "title_sum": 100, "type": 2}
+{"sum": 74, "points": {"1": 5, "2": 5, "3": 4, "4": 4, "5": 3, "6": 3, "7": 2, "8": 1, "9": 1, "10": 1, "11": 1, "12": 1, "13": 1, "14": 1, "15": 1, "16": 1, "17": 1, "18": 1}}
+{"tournament_rank": 102, "contestants": 35, "boards": 0, "title_sum": 100, "type": 2}
+{"sum": 0, "points": {}}
+{"tournament_rank": 102, "contestants": 35, "boards": 1, "title_sum": 100, "type": 2}
+{"sum": 36, "points": {"1": 1, "2": 1, "3": 1, "4": 1, "5": 1, "6": 1, "7": 1, "8": 1, "9": 1, "10": 1, "11": 1, "12": 1, "13": 1, "14": 1, "15": 1, "16": 1, "17": 1, "18": 1}}
+{"tournament_rank": 102, "contestants": 35, "boards": 20, "title_sum": 100, "type": 2}
+{"sum": 62, "points": {"1": 4, "2": 4, "3": 3, "4": 3, "5": 2, "6": 2, "7": 2, "8": 1, "9": 1, "10": 1, "11": 1, "12": 1, "13": 1, "14": 1, "15": 1, "16": 1, "17": 1, "18": 1}}
+{"tournament_rank": 102, "contestants": 20, "boards": 27, "title_sum": 50, "type": 1}
+{"sum": 19, "points": {"1": 4, "2": 4, "3": 3, "4": 2, "5": 1, "6": 1, "7": 1, "8": 1, "9": 1, "10": 1}}
+{"tournament_rank": 102, "contestants": 20, "boards": 47, "title_sum": 50, "type": 1}
+{"sum": 19, "points": {"1": 4, "2": 4, "3": 3, "4": 2, "5": 1, "6": 1, "7": 1, "8": 1, "9": 1, "10": 1}}
+{"tournament_rank": 102, "contestants": 20, "boards": 0, "title_sum": 50, "type": 1}
+{"sum": 0, "points": {}}
+{"tournament_rank": 102, "contestants": 20, "boards": 1, "title_sum": 50, "type": 1}
+{"sum": 10, "points": {"1": 1, "2": 1, "3": 1, "4": 1, "5": 1, "6": 1, "7": 1, "8": 1, "9": 1, "10": 1}}
+{"tournament_rank": 102, "contestants": 20, "boards": 20, "title_sum": 50, "type": 1}
+{"sum": 16, "points": {"1": 3, "2": 3, "3": 2, "4": 2, "5": 1, "6": 1, "7": 1, "8": 1, "9": 1, "10": 1}}