예제 #1
0
 /**
  * Contestant submits runs and admin is able to get them
  */
 public function testGetRunsForContest()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant
     $contestant = UserFactory::createUser();
     // Create a run
     $runData = RunsFactory::createRun($problemData, $contestData, $contestant);
     // Grade the run
     RunsFactory::gradeRun($runData);
     // Create request
     $r = new Request();
     $r['contest_alias'] = $contestData['request']['alias'];
     $r['auth_token'] = $this->login($contestData['director']);
     // Call API
     $response = ContestController::apiRuns($r);
     // Assert
     $this->assertEquals(1, count($response['runs']));
     $this->assertEquals($runData['response']['guid'], $response['runs'][0]['guid']);
     $this->assertEquals($contestant->username, $response['runs'][0]['username']);
     $this->assertEquals('J1', $response['runs'][0]['judged_by']);
 }
 public function testUpdateProblemTitleAndContents()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant
     $contestant = UserFactory::createUser();
     // Create a run
     $runData[0] = RunsFactory::createRun($problemData, $contestData, $contestant);
     $runData[1] = RunsFactory::createRun($problemData, $contestData, $contestant);
     // Grade the run
     RunsFactory::gradeRun($runData[0]);
     RunsFactory::gradeRun($runData[1]);
     // Get File Uploader Mock and tell Omegaup API to use it
     FileHandler::SetFileUploader($this->createFileUploaderMock());
     // Update Problem calls grader to rejudge, we need to detour grader calls
     // We will submit 2 runs to the problem, a call to grader to rejudge them
     $this->detourGraderCalls($this->exactly(1));
     // Prepare request
     $r = new Request();
     $r['title'] = 'new title';
     $r['time_limit'] = 12345;
     $r['problem_alias'] = $problemData['request']['alias'];
     $r['stack_limit'] = 12345;
     $r['message'] = 'Changed some properties';
     // Set file upload context
     $_FILES['problem_contents']['tmp_name'] = OMEGAUP_RESOURCES_ROOT . 'triangulos.zip';
     // Log in as contest director
     $r['auth_token'] = $this->login($problemData['author']);
     // Call API
     $response = ProblemController::apiUpdate($r);
     // Verify data in DB
     $problem_mask = new Problems();
     $problem_mask->setTitle($r['title']);
     $problems = ProblemsDAO::search($problem_mask);
     // Check that we only retreived 1 element
     $this->assertEquals(1, count($problems));
     // Validate rsponse
     $this->assertEquals('ok', $response['status']);
     $this->assertEquals(true, $response['rejudged']);
     $this->assertEquals('cases/1.in', $response['uploaded_files'][0]);
     // Verify problem contents were copied
     $targetpath = PROBLEMS_PATH . DIRECTORY_SEPARATOR . $r['problem_alias'] . DIRECTORY_SEPARATOR;
     $this->assertFileExists($targetpath . 'cases');
     $this->assertFileExists($targetpath . 'statements/es.html');
     $this->assertFileNotExists($targetpath . 'examples/sample.in');
     // Check update in statements
     $statement = file_get_contents($targetpath . 'statements' . DIRECTORY_SEPARATOR . 'es.html');
     $this->assertContains('perímetro', $statement);
     $this->assertEquals(12345, $problems[0]->stack_limit);
     // Call API again to add an example, should not trigger rejudge.
     $_FILES['problem_contents']['tmp_name'] = OMEGAUP_RESOURCES_ROOT . 'triangulos-examples.zip';
     $response = ProblemController::apiUpdate($r);
     $this->assertEquals('ok', $response['status']);
     $this->assertEquals(false, $response['rejudged']);
     $this->assertFileExists($targetpath . 'examples/sample.in');
 }
예제 #3
0
 /**
  * Checks that, if there's no wait time, 0 is posted in max_wait_time
  */
 public function testGetStatsNoWaitTime()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant
     $contestant = UserFactory::createUser();
     $ACRunsCount = 2;
     $ACRunsData = array();
     for ($i = 0; $i < $ACRunsCount; $i++) {
         $ACRunsData[$i] = RunsFactory::createRun($problemData, $contestData, $contestant);
         // Grade the run
         RunsFactory::gradeRun($ACRunsData[$i]);
     }
     // Create request
     $r = new Request();
     $r['contest_alias'] = $contestData['request']['alias'];
     $r['auth_token'] = $this->login($contestData['director']);
     // Call API
     $response = ContestController::apiStats($r);
     // Check number of pending runs
     $this->assertEquals($ACRunsCount, $response['total_runs']);
     $this->assertEquals(0, $response['max_wait_time']);
     $this->assertEquals(0, $response['max_wait_time_guid']);
 }
예제 #4
0
 /**
  * Contestant submits runs and admin is able to get them
  */
 public function testGetRunsForContest()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant
     $contestant = UserFactory::createUser();
     // Create a run
     $runData = RunsFactory::createRun($problemData, $contestData, $contestant);
     // Grade the run
     RunsFactory::gradeRun($runData);
     // Create request
     $r = new Request();
     $r["contest_alias"] = $contestData["request"]["alias"];
     $r["auth_token"] = $this->login($contestData["director"]);
     // Call API
     $response = ContestController::apiRuns($r);
     // Assert
     $this->assertEquals(1, count($response["runs"]));
     $this->assertEquals($runData["response"]["guid"], $response["runs"][0]["guid"]);
     $this->assertEquals($contestant->username, $response["runs"][0]["username"]);
     $this->assertEquals("J1", $response["runs"][0]["judged_by"]);
 }
 public function testCoderOfTheMonthCalc()
 {
     $user = UserFactory::createUser();
     $contest = ContestsFactory::createContest();
     $problem = ProblemsFactory::createProblem();
     ContestsFactory::addProblemToContest($problem, $contest);
     ContestsFactory::addUser($contest, $user);
     // Creating 10 AC runs for our user in the last month
     $n = 10;
     $lastMonth = intval(date('m')) - 1;
     $runCreationDate = null;
     if ($lastMonth == 0) {
         $runCreationDate = date(intval(date('Y') - 1) . '-12-01');
     } else {
         $runCreationDate = date('Y-' . $lastMonth . '-01');
     }
     for ($i = 0; $i < $n; $i++) {
         $runData = RunsFactory::createRun($problem, $contest, $user);
         RunsFactory::gradeRun($runData);
         // Force the run to be in last month
         $run = RunsDAO::getByAlias($runData['response']['guid']);
         $run->setTime($runCreationDate);
         RunsDAO::save($run);
     }
     $response = UserController::apiCoderOfTheMonth(new Request());
     $this->assertEquals($user->getUsername(), $response['userinfo']['username']);
 }
예제 #6
0
 /**
  * Creates a valid clarification
  */
 public function testCreateValidClarification()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant who will submit the clarification
     $contestant = UserFactory::createUser();
     // Call the API
     $this->detourBroadcasterCalls();
     $clarificationData = ClarificationsFactory::createClarification($problemData, $contestData, $contestant);
     // Assert status of new contest
     $this->assertArrayHasKey("clarification_id", $clarificationData['response']);
     // Verify that clarification was inserted in the database
     $clarification = ClarificationsDAO::getByPK($clarificationData['response']['clarification_id']);
     // Verify our retreived clarificatoin
     $this->assertNotNull($clarification);
     $this->assertEquals($clarificationData['request']['message'], $clarification->getMessage());
     // We need to verify that the contest and problem IDs where properly saved
     // Extractiing the contest and problem from DB to check IDs
     $problem = ProblemsDAO::getByAlias($problemData["request"]["alias"]);
     $contest = ContestsDAO::getByAlias($contestData["request"]["alias"]);
     $this->assertEquals($contest->getContestId(), $clarification->getContestId());
     $this->assertEquals($problem->getProblemId(), $clarification->getProblemId());
 }
예제 #7
0
 /**
  * Test apiBestScore for submits inside a contest
  */
 public function testBestScoreInsideContest()
 {
     // Create problem and contest
     $problemData = ProblemsFactory::createProblem();
     $contestData = ContestsFactory::createContest();
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create contestant
     $contestant = UserFactory::createUser();
     // Create 2 runs, 100 and 50.
     $runDataOutsideContest = RunsFactory::createRunToProblem($problemData, $contestant);
     $runDataInsideContest = RunsFactory::createRun($problemData, $contestData, $contestant);
     RunsFactory::gradeRun($runDataOutsideContest);
     RunsFactory::gradeRun($runDataInsideContest, 0.5, "PA");
     // Call API
     $response = ProblemController::apiBestScore(new Request(array("auth_token" => $this->login($contestant), "problem_alias" => $problemData["request"]["alias"], "contest_alias" => $contestData["request"]["alias"])));
     $this->assertEquals(50.0, $response["score"]);
 }
 public function testProblemArenaAndSubmbit()
 {
     // Create a contestant
     $contestant = UserFactory::createUser();
     // Create a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create a run
     $runData = RunsFactory::createRun($problemData, $contestData, $contestant);
     // Login
     $contestant = $this->createAdminUserAndLogin();
     // Open ADMIN
     $this->open('/arena/admin');
     // Wait for table to render with our run
     $this->waitForElementPresent('//*[@id="run_' . $runData['response']['guid'] . '"]/td[2]');
 }
예제 #9
0
 public function testRunTotals()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant
     $contestant = UserFactory::createUser();
     // Create a run
     $runData = RunsFactory::createRun($problemData, $contestData, $contestant);
     $runDataOld = RunsFactory::createRun($problemData, $contestData, $contestant);
     $run = RunsDAO::getByAlias($runDataOld['response']['guid']);
     $run->setTime(date('Y-m-d H:i:s', strtotime('-72 hours')));
     RunsDAO::save($run);
     $response = RunController::apiCounts(new Request());
     $this->assertGreaterThan(1, count($response));
 }
 /**
  * Basic test for getting the list of clarifications of a contest.
  * Create 4 clarifications in a contest with one user, then another 3 clarifications
  * with another user. 
  * Get the list for the first user, will see only his 4
  */
 public function testListPublicClarificationsForContestant()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant who will submit the clarification
     $contestant1 = UserFactory::createUser();
     // Create 4 clarifications with this contestant
     $clarificationData1 = array();
     $this->detourBroadcasterCalls($this->exactly(9));
     for ($i = 0; $i < 4; $i++) {
         $clarificationData1[$i] = ClarificationsFactory::createClarification($problemData, $contestData, $contestant1);
     }
     // Answer clarification 0 and 2
     ClarificationsFactory::answer($clarificationData1[0], $contestData);
     ClarificationsFactory::answer($clarificationData1[2], $contestData);
     // Create another contestant
     $contestant2 = UserFactory::createUser();
     // Create 3 clarifications with this contestant
     $clarificationData2 = array();
     for ($i = 0; $i < 3; $i++) {
         $clarificationData2[$i] = ClarificationsFactory::createClarification($problemData, $contestData, $contestant2);
     }
     // Prepare the request
     $r = new Request();
     $r["contest_alias"] = $contestData["request"]["alias"];
     // Log in with first user
     $r["auth_token"] = $this->login($contestant1);
     // Call API
     $response = ContestController::apiClarifications($r);
     // Check that we got all clarifications
     $this->assertEquals(count($clarificationData1), count($response["clarifications"]));
     // Check that the clarifications came in the order we expect
     // First we expect clarifications not answered
     $this->assertEquals($clarificationData1[3]["request"]["message"], $response["clarifications"][0]["message"]);
     $this->assertEquals($clarificationData1[1]["request"]["message"], $response["clarifications"][1]["message"]);
     // Then clarifications answered, newer first
     $this->assertEquals($clarificationData1[2]["request"]["message"], $response["clarifications"][2]["message"]);
     $this->assertEquals($clarificationData1[0]["request"]["message"], $response["clarifications"][3]["message"]);
 }
예제 #11
0
 /**
  * Check stats are ok for WA, AC, PA and total counts
  * Also validates the max wait time guid
  */
 public function testGetStats()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant
     $contestant = UserFactory::createUser();
     // Create some runs to be pending
     $pendingRunsCount = 5;
     $pendingRunsData = array();
     for ($i = 0; $i < $pendingRunsCount; $i++) {
         $pendingRunsData[$i] = RunsFactory::createRun($problemData, $contestData, $contestant);
     }
     $ACRunsCount = 2;
     $ACRunsData = array();
     for ($i = 0; $i < $ACRunsCount; $i++) {
         $ACRunsData[$i] = RunsFactory::createRun($problemData, $contestData, $contestant);
         // Grade the run
         RunsFactory::gradeRun($ACRunsData[$i]);
     }
     $WARunsCount = 1;
     $WARunsData = array();
     for ($i = 0; $i < $WARunsCount; $i++) {
         $WARunsData[$i] = RunsFactory::createRun($problemData, $contestData, $contestant);
         // Grade the run with WA
         RunsFactory::gradeRun($WARunsData[$i], 0, "WA");
     }
     // Create request
     $r = new Request();
     $r["problem_alias"] = $problemData["request"]["alias"];
     $r["auth_token"] = $this->login($problemData["author"]);
     // Call API
     $response = ProblemController::apiStats($r);
     // Check number of pending runs
     $this->assertEquals(count($pendingRunsData), count($response["pending_runs"]));
     $this->assertEquals(count($ACRunsData), $response["verdict_counts"]["AC"]);
     $this->assertEquals(count($WARunsData), $response["verdict_counts"]["WA"]);
     $this->assertEquals($pendingRunsCount + $ACRunsCount + $WARunsCount, $response["total_runs"]);
 }
예제 #12
0
 public function testProblemsSolved()
 {
     $user = UserFactory::createUser();
     $contest = ContestsFactory::createContest();
     $problemOne = ProblemsFactory::createProblem();
     $problemTwo = ProblemsFactory::createProblem();
     ContestsFactory::addProblemToContest($problemOne, $contest);
     ContestsFactory::addProblemToContest($problemTwo, $contest);
     ContestsFactory::addUser($contest, $user);
     $runs = array();
     $runs[0] = RunsFactory::createRun($problemOne, $contest, $user);
     $runs[1] = RunsFactory::createRun($problemTwo, $contest, $user);
     $runs[2] = RunsFactory::createRun($problemOne, $contest, $user);
     RunsFactory::gradeRun($runs[0]);
     RunsFactory::gradeRun($runs[1]);
     RunsFactory::gradeRun($runs[2]);
     $r = new Request(array("auth_token" => self::login($user)));
     $response = UserController::apiProblemsSolved($r);
     $this->assertEquals(2, count($response["problems"]));
 }
예제 #13
0
 /**
  * Update from private to public with problems added
  * 
  */
 public function testUpdatePrivateContestToPublicWithProblems()
 {
     // Get a contest
     $contestData = ContestsFactory::createContest(null, 0);
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Prepare request
     $r = new Request();
     $r["contest_alias"] = $contestData["request"]["alias"];
     // Log in with contest director
     $r["auth_token"] = $this->login($contestData["director"]);
     // Update public
     $r["public"] = 1;
     // Call API
     $response = ContestController::apiUpdate($r);
     $contestData["request"]["public"] = $r["public"];
     $this->assertContest($contestData["request"]);
 }
예제 #14
0
 /**
  * Basic test of viewing run details
  * 
  */
 public function testShowRunDetailsValid()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant
     $contestant = UserFactory::createUser();
     // Create a run
     $runData = RunsFactory::createRun($problemData, $contestData, $contestant);
     // Prepare request
     $r = new Request();
     $r["auth_token"] = $this->login($contestant);
     $r["run_alias"] = $runData["response"]["guid"];
     // Call API
     $response = RunController::apiStatus($r);
     $this->assertEquals($r["run_alias"], $response["guid"]);
     $this->assertEquals("JE", $response["verdict"]);
     $this->assertEquals("new", $response["status"]);
 }
예제 #15
0
 /**
  * Basic test of viewing run details
  *
  */
 public function testShowRunDetailsValid()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant
     $contestant = UserFactory::createUser();
     // Create a run
     $runData = RunsFactory::createRun($problemData, $contestData, $contestant);
     // Prepare request
     $r = new Request();
     $r['auth_token'] = $this->login($contestant);
     $r['run_alias'] = $runData['response']['guid'];
     // Call API
     $response = RunController::apiStatus($r);
     $this->assertEquals($r['run_alias'], $response['guid']);
     $this->assertEquals('JE', $response['verdict']);
     $this->assertEquals('new', $response['status']);
 }
 /**
  * Basic test for answer
  *
  */
 public function testUpdateAnswer()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant who will submit the clarification
     $contestant = UserFactory::createUser();
     // Create clarification
     $this->detourBroadcasterCalls($this->exactly(2));
     $clarificationData = ClarificationsFactory::createClarification($problemData, $contestData, $contestant);
     // Update answer
     $newAnswer = 'new answer';
     $response = ClarificationsFactory::answer($clarificationData, $contestData, $newAnswer);
     // Get clarification from DB
     $clarification = ClarificationsDAO::getByPK($clarificationData['response']['clarification_id']);
     // Validate that clarification stays the same
     $this->assertEquals($clarificationData['request']['message'], $clarification->getMessage());
     $this->assertEquals($clarificationData['request']['public'], $clarification->getPublic());
     // Validate our update
     $this->assertEquals($newAnswer, $clarification->getAnswer());
 }
예제 #17
0
 /**
  * Basic test of rerun
  */
 public function testRejudgeWithoutCompileError()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant
     $contestant = UserFactory::createUser();
     // Create a run
     $runData = RunsFactory::createRun($problemData, $contestData, $contestant);
     // Grade the run
     RunsFactory::gradeRun($runData);
     // Detour grader calls expecting one call
     $this->detourGraderCalls($this->once());
     // Build request
     $r = new Request();
     $r['run_alias'] = $runData['response']['guid'];
     $r['auth_token'] = $this->login($contestData['director']);
     // Call API
     $response = RunController::apiRejudge($r);
     $this->assertEquals('ok', $response['status']);
 }
 public function testPublicClarificationsCanBeViewed()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant who will submit the clarification
     $contestant = UserFactory::createUser();
     // Create our contestant who will try to view the clarification
     $contestant2 = UserFactory::createUser();
     // Create the clarification, note that contestant will create it
     $this->detourBroadcasterCalls();
     $clarificationData = ClarificationsFactory::createClarification($problemData, $contestData, $contestant);
     // Manually set the just created clarification to PUBLIC
     $clarification = ClarificationsDAO::getByPK($clarificationData['response']['clarification_id']);
     $clarification->setPublic('1');
     ClarificationsDAO::save($clarification);
     // Prepare the request object
     $r = new Request();
     $r['clarification_id'] = $clarificationData['response']['clarification_id'];
     // Log in with the author of the clarification
     $r['auth_token'] = $this->login($contestant2);
     // Call API
     $response = ClarificationController::apiDetails($r);
     // Check the data we got
     $this->assertClarification($r['clarification_id'], $response);
 }
예제 #19
0
 /**
  * User cannot send runs to a private problem, regardless of it being
  * in a contest
  *
  * @expectedException NotAllowedToSubmitException
  */
 public function testRunToPrivateProblemWhileInsideAPublicContest()
 {
     // Get a contest
     $contestData = ContestsFactory::createContest(null, 1);
     // Create public problem
     $problemData = ProblemsFactory::createProblem(null, null, 0, $contestData["director"]);
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant
     $this->contestant = UserFactory::createUser();
     // Create an empty request
     $r = new Request();
     // Log in as contest director
     $r["auth_token"] = $this->login($this->contestant);
     // Build request
     $r["contest_alias"] = "";
     // Not inside a contest
     $r["problem_alias"] = $problemData["request"]["alias"];
     $r["language"] = "c";
     $r["source"] = "#include <stdio.h>\nint main() { printf(\"3\"); return 0; }";
     //PHPUnit does not set IP address, doing it manually
     $_SERVER["REMOTE_ADDR"] = "127.0.0.1";
     // Call API
     $response = RunController::apiCreate($r);
 }
예제 #20
0
 /**
  * User cannot send runs to a private problem, regardless of it being
  * in a contest
  *
  * @expectedException NotAllowedToSubmitException
  */
 public function testRunToPrivateProblemWhileInsideAPublicContest()
 {
     // Get a contest
     $contestData = ContestsFactory::createContest(null, 1);
     // Create public problem
     $problemData = ProblemsFactory::createProblem(null, null, 0, $contestData['director']);
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant
     $this->contestant = UserFactory::createUser();
     // Create an empty request
     $r = new Request();
     // Log in as contest director
     $r['auth_token'] = $this->login($this->contestant);
     // Build request
     $r['contest_alias'] = '';
     // Not inside a contest
     $r['problem_alias'] = $problemData['request']['alias'];
     $r['language'] = 'c';
     $r['source'] = "#include <stdio.h>\nint main() { printf(\"3\"); return 0; }";
     // Call API
     $response = RunController::apiCreate($r);
 }
예제 #21
0
 /**
  * Tests contest report used in OMI
  */
 public function testContestReport()
 {
     // Get a contest
     $contestData = ContestsFactory::createContest();
     $contestDirector = $contestData["director"];
     // Get a problem
     $problemData = ProblemsFactory::createProblemWithAuthor($contestDirector);
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestants
     $contestants = array();
     array_push($contestants, UserFactory::createUser());
     array_push($contestants, UserFactory::createUser());
     array_push($contestants, UserFactory::createUser());
     $contestAdmin = UserFactory::createUser();
     ContestsFactory::addAdminUser($contestData, $contestAdmin);
     // Create runs
     $runsData = array();
     $runsData[0] = RunsFactory::createRun($problemData, $contestData, $contestants[0]);
     $runsData[1] = RunsFactory::createRun($problemData, $contestData, $contestants[0]);
     $runsData[2] = RunsFactory::createRun($problemData, $contestData, $contestants[1]);
     $runsData[3] = RunsFactory::createRun($problemData, $contestData, $contestants[2]);
     $runDataDirector = RunsFactory::createRun($problemData, $contestData, $contestDirector);
     $runDataAdmin = RunsFactory::createRun($problemData, $contestData, $contestAdmin);
     // Grade the runs
     RunsFactory::gradeRun($runsData[0], 0, "CE");
     RunsFactory::gradeRun($runsData[1]);
     RunsFactory::gradeRun($runsData[2], 0.9, "PA");
     RunsFactory::gradeRun($runsData[3], 1, "AC", 180);
     RunsFactory::gradeRun($runDataDirector, 1, "AC", 120);
     RunsFactory::gradeRun($runDataAdmin, 1, "AC", 110);
     // Create API
     $response = ContestController::apiReport(new Request(array("contest_alias" => $contestData["request"]["alias"], "auth_token" => $this->login($contestDirector))));
     $this->assertEquals($problemData["request"]["alias"], $response["problems"][0]["alias"]);
     foreach ($contestants as $contestant) {
         $found = false;
         foreach ($response["ranking"] as $rank) {
             if ($rank["username"] == $contestant->username) {
                 $found = true;
                 break;
             }
         }
         $this->assertTrue($found);
     }
 }
 /**
  * Basic tests for shareable scoreboard url
  */
 public function testScoreboardUrlNoLogin()
 {
     // Get a private contest with 0% of scoreboard show percentage
     $contestData = ContestsFactory::createContest(null, 0);
     ContestsFactory::setScoreboardPercentage($contestData, 0);
     // Create problem
     $problemData = ProblemsFactory::createProblem();
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant, will submit 1 run
     $contestant = UserFactory::createUser();
     ContestsFactory::addUser($contestData, $contestant);
     $runData = RunsFactory::createRun($problemData, $contestData, $contestant);
     RunsFactory::gradeRun($runData);
     // Get the scoreboard url by using the MyList api being the
     // contest director
     $response = ContestController::apiMyList(new Request(array('auth_token' => $this->login($contestData['director']))));
     // Look for our contest from the list and save the scoreboard tokens
     $scoreboard_url = null;
     $scoreboard_admin_url = null;
     foreach ($response['results'] as $c) {
         if ($c['alias'] === $contestData['request']['alias']) {
             $scoreboard_url = $c['scoreboard_url'];
             $scoreboard_admin_url = $c['scoreboard_url_admin'];
             break;
         }
     }
     $this->assertNotNull($scoreboard_url);
     $this->assertNotNull($scoreboard_admin_url);
     // Call scoreboard api from the user
     $scoreboardResponse = ContestController::apiScoreboard(new Request(array('contest_alias' => $contestData['request']['alias'], 'token' => $scoreboard_url)));
     $this->assertEquals('0', $scoreboardResponse['ranking'][0]['total']['points']);
     // Call scoreboard api from the user with admin token
     $scoreboardResponse = ContestController::apiScoreboard(new Request(array('contest_alias' => $contestData['request']['alias'], 'token' => $scoreboard_admin_url)));
     $this->assertEquals('100', $scoreboardResponse['ranking'][0]['total']['points']);
 }
예제 #23
0
 /**
  * apiDetails with only AC and Weights
  */
 public function testScoreboardDetailsOnlyAcAndWeight()
 {
     $groupData = GroupsFactory::createGroup();
     $scoreboardData = GroupsFactory::createGroupScoreboard($groupData);
     $contestsData = array();
     // Create contestants to submit runs
     $contestantInGroup = UserFactory::createUser();
     GroupsFactory::addUserToGroup($groupData, $contestantInGroup);
     $contestantInGroupNoAc = UserFactory::createUser();
     GroupsFactory::addUserToGroup($groupData, $contestantInGroupNoAc);
     $n = 5;
     for ($i = 0; $i < $n; $i++) {
         $contestsData[] = ContestsFactory::createContest();
         ContestsFactory::addAdminUser($contestsData[$i], $groupData['owner']);
         GroupsFactory::addContestToScoreboard($contestsData[$i], $scoreboardData, $groupData, 1, $i === 0 ? 3 : 1);
         // Create a problem to solve
         $problemData = ProblemsFactory::createProblem();
         ContestsFactory::addProblemToContest($problemData, $contestsData[$i]);
         // Submit runs
         $run1 = RunsFactory::createRun($problemData, $contestsData[$i], $contestantInGroup);
         $run2 = RunsFactory::createRun($problemData, $contestsData[$i], $contestantInGroupNoAc);
         RunsFactory::gradeRun($run1);
         RunsFactory::gradeRun($run2, 0.5, 'PA');
     }
     $response = GroupScoreboardController::apiDetails(new Request(array('auth_token' => self::login($groupData['owner']), 'group_alias' => $groupData['request']['alias'], 'scoreboard_alias' => $scoreboardData['request']['alias'])));
     $this->assertEquals($n, count($response['contests']));
     $this->assertEquals($scoreboardData['request']['alias'], $response['scoreboard']['alias']);
     // 2 users in the merged scoreboard is expected
     $this->assertEquals(2, count($response['ranking']));
     $this->assertEquals($n, count($response['ranking'][0]['contests']));
     // Only AC is expected
     $this->assertEquals(100, $response['ranking'][0]['contests'][$contestsData[1]['request']['alias']]['points']);
     $this->assertEquals(0, $response['ranking'][1]['contests'][$contestsData[1]['request']['alias']]['points']);
     // Weight x3 in the first contest for 1st user
     $this->assertEquals(300, $response['ranking'][0]['contests'][$contestsData[0]['request']['alias']]['points']);
     $this->assertEquals(700, $response['ranking'][0]['total']['points']);
 }
 /**
  * Best score is returned, problem inside a contest
  */
 public function testScoreInDetailsInsideContest()
 {
     // Create problem and contest
     $problemData = ProblemsFactory::createProblem();
     $contestData = ContestsFactory::createContest();
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create contestant
     $contestant = UserFactory::createUser();
     // Create 2 runs, 100 and 50.
     $runDataOutsideContest = RunsFactory::createRunToProblem($problemData, $contestant);
     $runDataInsideContest = RunsFactory::createRun($problemData, $contestData, $contestant);
     RunsFactory::gradeRun($runDataOutsideContest);
     RunsFactory::gradeRun($runDataInsideContest, 0.5, 'PA');
     // Call API
     $response = ProblemController::apiDetails(new Request(array('auth_token' => $this->login($contestant), 'problem_alias' => $problemData['request']['alias'], 'contest_alias' => $contestData['request']['alias'])));
     $this->assertEquals(50.0, $response['score']);
 }
 /**
  * Tests contest report used in OMI
  */
 public function testContestReport()
 {
     // Get a contest
     $contestData = ContestsFactory::createContest();
     $contestDirector = $contestData['director'];
     // Get a problem
     $problemData = ProblemsFactory::createProblemWithAuthor($contestDirector);
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestants
     $contestants = array();
     array_push($contestants, UserFactory::createUser());
     array_push($contestants, UserFactory::createUser());
     array_push($contestants, UserFactory::createUser());
     $contestAdmin = UserFactory::createUser();
     ContestsFactory::addAdminUser($contestData, $contestAdmin);
     // Create runs
     $runsData = array();
     $runsData[0] = RunsFactory::createRun($problemData, $contestData, $contestants[0]);
     $runsData[1] = RunsFactory::createRun($problemData, $contestData, $contestants[0]);
     $runsData[2] = RunsFactory::createRun($problemData, $contestData, $contestants[1]);
     $runsData[3] = RunsFactory::createRun($problemData, $contestData, $contestants[2]);
     $runDataDirector = RunsFactory::createRun($problemData, $contestData, $contestDirector);
     $runDataAdmin = RunsFactory::createRun($problemData, $contestData, $contestAdmin);
     // Grade the runs
     RunsFactory::gradeRun($runsData[0], 0, 'CE');
     RunsFactory::gradeRun($runsData[1]);
     RunsFactory::gradeRun($runsData[2], 0.9, 'PA');
     RunsFactory::gradeRun($runsData[3], 1, 'AC', 180);
     RunsFactory::gradeRun($runDataDirector, 1, 'AC', 120);
     RunsFactory::gradeRun($runDataAdmin, 1, 'AC', 110);
     // Create API
     $response = ContestController::apiReport(new Request(array('contest_alias' => $contestData['request']['alias'], 'auth_token' => $this->login($contestDirector))));
     $this->assertEquals($problemData['request']['alias'], $response['problems'][0]['alias']);
     foreach ($contestants as $contestant) {
         $found = false;
         foreach ($response['ranking'] as $rank) {
             if ($rank['username'] == $contestant->username) {
                 $found = true;
                 break;
             }
         }
         $this->assertTrue($found);
     }
 }