Skip to content

Commit

Permalink
added CompilerVersionId parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Evinek committed Aug 30, 2018
1 parent 91c6b4c commit 8079037
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 19 deletions.
2 changes: 1 addition & 1 deletion client-commons
22 changes: 15 additions & 7 deletions src/Api/CompilersClientV4.php
Expand Up @@ -108,12 +108,13 @@ public function getCompilers()
* @param int $priority priority of the submission, default: normal priority (eg. 5 for range 1-9) (optional)
* @param int $timeLimit time limit, default: 5 (optional)
* @param int $memoryLimit memory limit, default: no limit (optional)
* @param int $compilerVersionId compiler version, default: default for api V4 (optional)
* @throws SphereEngineResponseException
* @return array
*/
public function createSubmission($source, $compilerId, $input="", $priority=null, $timeLimit=null, $memoryLimit=null)
public function createSubmission($source, $compilerId, $input="", $priority=null, $timeLimit=null, $memoryLimit=null, $compilerVersionId=null)
{
return $this->_createSubmission($source, $compilerId, $input, $priority, [], $timeLimit, $memoryLimit);
return $this->_createSubmission($source, $compilerId, $input, $priority, [], $timeLimit, $memoryLimit, $compilerVersionId);
}

/**
Expand All @@ -125,12 +126,13 @@ public function createSubmission($source, $compilerId, $input="", $priority=null
* @param int $priority priority of the submission, default: normal priority (eg. 5 for range 1-9) (optional)
* @param int $timeLimit time limit, default: 5 (optional)
* @param int $memoryLimit memory limit, default: no limit (optional)
* @param int $compilerVersionId compiler version, default: default for api V4 (optional)
* @throws SphereEngineResponseException
* @return array
*/
public function createSubmissionMultiFiles($files, $compilerId, $input="", $priority=null, $timeLimit=null, $memoryLimit=null)
public function createSubmissionMultiFiles($files, $compilerId, $input="", $priority=null, $timeLimit=null, $memoryLimit=null, $compilerVersionId=null)
{
return $this->_createSubmission("", $compilerId, $input, $priority, $files, $timeLimit, $memoryLimit);
return $this->_createSubmission("", $compilerId, $input, $priority, $files, $timeLimit, $memoryLimit, $compilerVersionId);
}

/**
Expand All @@ -142,12 +144,13 @@ public function createSubmissionMultiFiles($files, $compilerId, $input="", $prio
* @param int $priority priority of the submission, default: normal priority (eg. 5 for range 1-9) (optional)
* @param int $timeLimit time limit, default: 5 (optional)
* @param int $memoryLimit memory limit, default: no limit (optional)
* @param int $compilerVersionId compiler version, default: default for api V4 (optional)
* @throws SphereEngineResponseException
* @return array
*/
public function createSubmissionWithTarSource($tarSource, $compilerId, $input="", $priority=null, $timeLimit=null, $memoryLimit=null)
public function createSubmissionWithTarSource($tarSource, $compilerId, $input="", $priority=null, $timeLimit=null, $memoryLimit=null, $compilerVersionId=null)
{
return $this->_createSubmission($tarSource, $compilerId, $input, $priority, [], $timeLimit, $memoryLimit);
return $this->_createSubmission($tarSource, $compilerId, $input, $priority, [], $timeLimit, $memoryLimit, $compilerVersionId);
}

/**
Expand All @@ -160,10 +163,11 @@ public function createSubmissionWithTarSource($tarSource, $compilerId, $input=""
* @param string[] $files files [fileName=>fileContent], default: empty (optional)
* @param int $timeLimit time limit, default: 5 (optional)
* @param int $memoryLimit memory limit, default: no limit (optional)
* @param int $compilerVersionId compiler version, default: default for api V4 (optional)
* @throws SphereEngineResponseException
* @return array
*/
private function _createSubmission($source, $compilerId, $input="", $priority=null, $files=[], $timeLimit=null, $memoryLimit=null)
private function _createSubmission($source, $compilerId, $input="", $priority=null, $files=[], $timeLimit=null, $memoryLimit=null, $compilerVersionId=null)
{
$postParams = [
'source' => $source,
Expand Down Expand Up @@ -197,6 +201,10 @@ private function _createSubmission($source, $compilerId, $input="", $priority=nu
$postParams['memoryLimit'] = intval($memoryLimit);
}

if (isset($compilerVersionId)) {
$postParams['compilerVersionId'] = intval($compilerVersionId);
}

$response = $this->apiClient->callApi('/submissions', 'POST', null, null, $postParams, $filesData, null);

if ( ! in_array('id', array_keys($response))) {
Expand Down
2 changes: 2 additions & 0 deletions src/Api/Mock/CompilersApiClientV4.php
Expand Up @@ -107,12 +107,14 @@ public function mockSubmissionsMethod($method, $urlParams, $queryParams, $postDa
if($files === null) $files = [];
$timeLimit = $this->getParam($postData, 'timeLimit', true);
$memoryLimit = $this->getParam($postData, 'memoryLimit', true);
$compilerVersionId = $this->getParam($postData, 'compilerVersionId', true);

$path = 'compilers/createSubmission/'. $sourceCode . '_' . $compiler . '_' . $input;
$path .= '_' . intval($priority);
$path .= '_' . implode(',', array_keys($files));
$path .= '_' . intval($timeLimit);
$path .= '_' . intval($memoryLimit);
$path .= '_' . intval($compilerVersionId);

return $this->getMockData($path);
} else {
Expand Down
8 changes: 6 additions & 2 deletions src/Api/Mock/ProblemsApiClientV4.php
Expand Up @@ -240,8 +240,9 @@ public function mockJudgesMethod($method, $urlParams, $queryParams, $postData, $
$compilerId = $this->getParam($postData, 'compilerId');
$type = $this->getParam($postData, 'typeId');
$name = $this->getParam($postData, 'name');
$compilerVersionId = $this->getParam($postData, 'compilerVersionId', true);

$path = 'problems/createJudge/'. $source . '_' . $compilerId . '_' . $type . '_' . $name;
$path = 'problems/createJudge/'. $source . '_' . $compilerId . '_' . $type . '_' . $name . '_' . intval($compilerVersionId);
return $this->getMockData($path);
} else {
throw new \Exception("Method of this type is not supported by mock");
Expand All @@ -260,8 +261,9 @@ public function mockJudgeMethod($method, $urlParams, $queryParams, $postData, $f
$source = $this->getParam($postData, 'source', true);
$compilerId = $this->getParam($postData, 'compilerId', true);
$name = $this->getParam($postData, 'name', true);
$compilerVersionId = $this->getParam($postData, 'compilerVersionId', true);

$path = 'problems/updateJudge/'. $id . '_' . $source . '_' . $compilerId . '_' . $name;
$path = 'problems/updateJudge/'. $id . '_' . $source . '_' . $compilerId . '_' . $name . '_' . intval($compilerVersionId);
return $this->getMockData($path);
} else {
throw new \Exception("Method of this type is not supported by mock");
Expand Down Expand Up @@ -314,6 +316,7 @@ public function mockSubmissionsMethod($method, $urlParams, $queryParams, $postDa
if($files === null) $files = [];
$tests = $this->getParam($postData, 'tests', true);
if($tests === null) $tests = [];
$compilerVersionId = $this->getParam($postData, 'compilerVersionId', true);

$path = 'problems/createSubmission/';
$path .= $problemId;
Expand All @@ -322,6 +325,7 @@ public function mockSubmissionsMethod($method, $urlParams, $queryParams, $postDa
$path .= '_' . ($private ? 1 : 0);
$path .= '_' . implode(',', array_keys($files));
$path .= '_' . implode(',', array_keys($tests));
$path .= '_' . intval($compilerVersionId);

return $this->getMockData($path);
} else {
Expand Down
32 changes: 23 additions & 9 deletions src/Api/ProblemsClientV4.php
Expand Up @@ -139,7 +139,7 @@ public function getJudges($limit=10, $offset=0, $typeId=0)
* @throws SphereEngineConnectionException
* @return mixed API response
*/
public function createJudge($source, $compilerId, $typeId=0, $name="", $shared = false)
public function createJudge($source, $compilerId, $typeId=0, $name="", $shared=false, $compilerVersionId=null)
{
if ($source == '') {
throw new SphereEngineResponseException("empty source", 400);
Expand All @@ -152,6 +152,11 @@ public function createJudge($source, $compilerId, $typeId=0, $name="", $shared =
'name' => $name,
'shared' => $shared ? true : false,
];

if (isset($compilerVersionId)) {
$postParams['compilerVersionId'] = intval($compilerVersionId);
}

$response = $this->apiClient->callApi('/judges', 'POST', null, null, $postParams, null, null);

if ( ! in_array('id', array_keys($response))) {
Expand Down Expand Up @@ -219,7 +224,7 @@ public function getJudgeFile($id, $filename)
* @throws SphereEngineConnectionException
* @return mixed API response
*/
public function updateJudge($id, $source=null, $compilerId=null, $name=null, $shared=null)
public function updateJudge($id, $source=null, $compilerId=null, $name=null, $shared=null, $compilerVersionId=null)
{
if (isset($source) && $source == '') {
throw new SphereEngineResponseException("empty source", 400);
Expand All @@ -233,6 +238,7 @@ public function updateJudge($id, $source=null, $compilerId=null, $name=null, $sh
if (isset($compilerId)) $postParams['compilerId'] = $compilerId;
if (isset($name)) $postParams['name'] = $name;
if (isset($shared)) $postParams['shared'] = $shared ? true : false;
if (isset($compilerVersionId)) $postParams['compilerVersionId'] = intval($compilerVersionId);

$response = $this->apiClient->callApi('/judges/{id}', 'PUT', $urlParams, null, $postParams, null, null);

Expand Down Expand Up @@ -572,17 +578,18 @@ public function getProblemTestcaseFile($problemId, $number, $filename)
* @param int $compilerId Compiler ID (required)
* @param int $priority priority of the submission, default: normal priority (eg. 5 for range 1-9) (optional)
* @param int[] $tests tests to run, default: empty (optional)
* @param int $compilerVersionId compiler version, default: default for api V4 (optional)
* @throws SphereEngineResponseException
* @throws SphereEngineConnectionException
* @return mixed API response
*/
public function createSubmission($problemId, $source, $compilerId, $priority=null, $tests=[])
public function createSubmission($problemId, $source, $compilerId, $priority=null, $tests=[], $compilerVersionId=null)
{
if ($source == "") {
throw new SphereEngineResponseException("empty source", 400);
}

return $this->_createSubmission($problemId, $source, $compilerId, $priority, [], $tests);
return $this->_createSubmission($problemId, $source, $compilerId, $priority, [], $tests, $compilerVersionId);
}

/**
Expand All @@ -593,18 +600,19 @@ public function createSubmission($problemId, $source, $compilerId, $priority=nul
* @param int $compilerId Compiler ID (required)
* @param int $priority priority of the submission, default: normal priority (eg. 5 for range 1-9) (optional)
* @param int[] $tests tests to run, default: empty (optional)
* @param int $compilerVersionId compiler version, default: default for api V4 (optional)
* @throws SphereEngineResponseException
* @throws SphereEngineConnectionException
* @return mixed API response
*/
public function createSubmissionMultiFiles($problemId, $files, $compilerId, $priority=null, $tests=[])
public function createSubmissionMultiFiles($problemId, $files, $compilerId, $priority=null, $tests=[], $compilerVersionId=null)
{

if(is_array($files) === false || empty($files)) {
throw new SphereEngineResponseException("empty source", 400);
}

return $this->_createSubmission($problemId, '', $compilerId, $priority, $files, $tests);
return $this->_createSubmission($problemId, '', $compilerId, $priority, $files, $tests, $compilerVersionId);
}

/**
Expand All @@ -615,18 +623,19 @@ public function createSubmissionMultiFiles($problemId, $files, $compilerId, $pri
* @param int $compilerId Compiler ID (required)
* @param int $priority priority of the submission, default: normal priority (eg. 5 for range 1-9) (optional)
* @param int[] $tests tests to run, default: empty (optional)
* @param int $compilerVersionId compiler version, default: default for api V4 (optional)
* @throws SphereEngineResponseException
* @throws SphereEngineConnectionException
* @return mixed API response
*/
public function createSubmissionWithTarSource($problemId, $tarSource, $compilerId, $priority=null, $tests=[])
public function createSubmissionWithTarSource($problemId, $tarSource, $compilerId, $priority=null, $tests=[], $compilerVersionId=null)
{

if ($tarSource == "") {
throw new SphereEngineResponseException("empty source", 400);
}

return $this->_createSubmission($problemId, $tarSource, $compilerId, $priority, [], $tests);
return $this->_createSubmission($problemId, $tarSource, $compilerId, $priority, [], $tests, $compilerVersionId);
}

/**
Expand All @@ -638,11 +647,12 @@ public function createSubmissionWithTarSource($problemId, $tarSource, $compilerI
* @param int $priority priority of the submission, default: normal priority (eg. 5 for range 1-9) (optional)
* @param string[] $files files [fileName=>fileContent], default: empty (optional)
* @param int[] $tests tests to run, default: empty (optional)
* @param int $compilerVersionId compiler version, default: default for api V4 (optional)
* @throws SphereEngineResponseException
* @throws SphereEngineConnectionException
* @return mixed API response
*/
private function _createSubmission($problemId, $source, $compilerId, $priority=null, $files=[], $tests=[])
private function _createSubmission($problemId, $source, $compilerId, $priority=null, $files=[], $tests=[], $compilerVersionId=null)
{
$postParams = [
'problemId' => $problemId,
Expand Down Expand Up @@ -672,6 +682,10 @@ private function _createSubmission($problemId, $source, $compilerId, $priority=n
$postParams['tests'] = implode(',', $tests);
}

if (isset($compilerVersionId)) {
$postParams['compilerVersionId'] = intval($compilerVersionId);
}

$response = $this->apiClient->callApi('/submissions', 'POST', null, null, $postParams, $filesData, null);

if ( ! in_array('id', array_keys($response))) {
Expand Down
13 changes: 13 additions & 0 deletions tests/CompilersClientV4ExceptionsNewTest.php
Expand Up @@ -176,6 +176,19 @@ public function testCreateSubmissionMethodWrongCompiler()
//$this->assertEquals("WRONG_LANG_ID", self::$client->createSubmission("unit_test", $wrong_compiler_id)['error']);
}

/**
* @requires PHPUnit 5
*/
public function testCreateSubmissionMethodWrongCompilerVersion()
{
$wrongCompilerVersionId = 9999;

$this->expectException(SphereEngineResponseException::class);
$this->expectExceptionCode(400);
self::$client->createSubmission('unit_test', 1, "", null, null, null, $wrongCompilerVersionId);
//$this->assertEquals("WRONG_LANG_ID", self::$client->createSubmission("unit_test", $wrong_compiler_id)['error']);
}

/**
* @requires PHPUnit 5
*/
Expand Down
12 changes: 12 additions & 0 deletions tests/CompilersClientV4ExceptionsOldTest.php
Expand Up @@ -170,6 +170,18 @@ public function testCreateSubmissionMethodWrongCompiler()
$this->assertEquals(404, $e->getCode());
}
}

public function testCreateSubmissionMethodWrongCompilerVersion()
{
$wrongCompilerVersionId = 9999;

try {
self::$client->createSubmission('unit_test', 1, "", null, null, null, $wrongCompilerVersionId);
$this->assertTrue(false);
} catch (SphereEngineResponseException $e) {
$this->assertEquals(400, $e->getCode());
}
}

public function testCreateSubmissionMethodInvalidResponse()
{
Expand Down
61 changes: 61 additions & 0 deletions tests/ProblemsClientV4ExceptionsNewTest.php
Expand Up @@ -502,6 +502,18 @@ public function testCreateJudgeMethodNonexistingCompiler()
self::$client->createJudge('nonempty_source', $nonexistingCompiler, 'testcase', '');
}

/**
* @requires PHPUnit 5
*/
public function testCreateJudgeMethodNonexistingCompilerVersion()
{
$nonexistingCompilerVersion = 9999;

$this->expectException(SphereEngineResponseException::class);
$this->expectExceptionCode(400);
self::$client->createJudge('nonempty_source', 1, 'testcase', '', false, $nonexistingCompilerVersion);
}

/**
* @requires PHPUnit 5
*/
Expand Down Expand Up @@ -548,6 +560,19 @@ public function testUpdateJudgeMethodNonexistingCompiler()
self::$client->updateJudge($judge_id, 'nonempty_source', $nonexistingCompiler, '');
}

/**
* @requires PHPUnit 5
*/
public function testUpdateJudgeMethodNonexistingCompilerVersion()
{
$judge_id = 100;
$nonexistingCompilerVersion = 9999;

$this->expectException(SphereEngineResponseException::class);
$this->expectExceptionCode(400);
self::$client->updateJudge($judge_id, 'nonempty_source', 1, '', false, $nonexistingCompilerVersion);
}

/**
* @requires PHPUnit 5
*/
Expand Down Expand Up @@ -660,6 +685,18 @@ public function testCreateSubmissionMethodNonexistingCompiler()
$this->expectExceptionCode(404);
self::$client->createSubmission('TEST', 'nonempty_source', $nonexistingCompiler);
}

/**
* @requires PHPUnit 5
*/
public function testCreateSubmissionMethodNonexistingCompilerVersion()
{
$nonexistingCompilerVersion = 9999;

$this->expectException(SphereEngineResponseException::class);
$this->expectExceptionCode(400);
self::$client->createSubmission('TEST', 'nonempty_source', 1, null, [], $nonexistingCompilerVersion);
}

/**
* @requires PHPUnit 5
Expand Down Expand Up @@ -702,6 +739,18 @@ public function testCreateSubmissionMultiFilesMethodNonexistingCompiler()
self::$client->createSubmissionMultiFiles('TEST', ['nonempty_source' => ''], $nonexistingCompiler);
}

/**
* @requires PHPUnit 5
*/
public function testCreateSubmissionMultiFilesMethodNonexistingCompilerVersion()
{
$nonexistingCompilerVersion = 9999;

$this->expectException(SphereEngineResponseException::class);
$this->expectExceptionCode(400);
self::$client->createSubmissionMultiFiles('TEST', ['nonempty_source' => ''], 1, null, [], $nonexistingCompilerVersion);
}

/**
* @requires PHPUnit 5
*/
Expand Down Expand Up @@ -743,6 +792,18 @@ public function testCreateSubmissionWithTarSourceMethodNonexistingCompiler()
self::$client->createSubmissionWithTarSource('TEST', 'nonempty_source', $nonexistingCompiler);
}

/**
* @requires PHPUnit 5
*/
public function testCreateSubmissionWithTarSourceMethodNonexistingCompilerVersion()
{
$nonexistingCompilerVersion = 9999;

$this->expectException(SphereEngineResponseException::class);
$this->expectExceptionCode(400);
self::$client->createSubmissionWithTarSource('TEST', 'nonempty_source', 1, null, [], $nonexistingCompilerVersion);
}

/**
* @requires PHPUnit 5
*/
Expand Down

0 comments on commit 8079037

Please sign in to comment.