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');
 }
 /**
  * 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']);
 }
 /**
  * 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']);
 }
Beispiel #5
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"]);
 }
 /**
  * Tests apiRankByProblemsSolved for a specific user
  */
 public function testUserRankByProblemsSolved()
 {
     // Create a user and sumbit a run with him
     $contestant = UserFactory::createUser();
     $problemData = ProblemsFactory::createProblem();
     $runData = RunsFactory::createRunToProblem($problemData, $contestant);
     RunsFactory::gradeRun($runData);
     // Call API
     $response = UserController::apiRankByProblemsSolved(new Request(array('username' => $contestant->getUsername())));
     $this->assertEquals($response['name'], $contestant->getName());
     $this->assertEquals($response['problems_solved'], 1);
 }
 /**
  * Test apiBestScore for submits in a problem for other user
  */
 public function testBestScoreInProblemOtherUser()
 {
     // Create problem
     $problemData = ProblemsFactory::createProblem();
     // Create contestant
     $contestant = UserFactory::createUser();
     // Create user who will use the API
     $user = UserFactory::createUser();
     // Create 2 runs, 100 and 50.
     $runData = RunsFactory::createRunToProblem($problemData, $contestant);
     $runDataPA = RunsFactory::createRunToProblem($problemData, $contestant);
     RunsFactory::gradeRun($runData);
     RunsFactory::gradeRun($runDataPA, 0.5, 'PA');
     // Call API
     $response = ProblemController::apiBestScore(new Request(array('auth_token' => $this->login($user), 'problem_alias' => $problemData['request']['alias'], 'username' => $contestant->getUsername())));
     $this->assertEquals(100.0, $response['score']);
 }
 /**
  * Test apiBestScore for submits in a problem for other user
  */
 public function testBestScoreInProblemOtherUser()
 {
     // Create problem
     $problemData = ProblemsFactory::createProblem();
     // Create contestant
     $contestant = UserFactory::createUser();
     // Create user who will use the API
     $user = UserFactory::createUser();
     // Create 2 runs, 100 and 50.
     $runData = RunsFactory::createRunToProblem($problemData, $contestant);
     $runDataPA = RunsFactory::createRunToProblem($problemData, $contestant);
     RunsFactory::gradeRun($runData);
     RunsFactory::gradeRun($runDataPA, 0.5, "PA");
     // Call API
     $response = ProblemController::apiBestScore(new Request(array("auth_token" => $this->login($user), "problem_alias" => $problemData["request"]["alias"], "username" => $contestant->getUsername())));
     $this->assertEquals(100.0, $response["score"]);
 }
 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));
 }
 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]');
 }
Beispiel #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"]);
 }
 /**
  * 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']);
 }
Beispiel #13
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 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']);
 }
Beispiel #15
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);
     }
 }
Beispiel #16
0
 /**
  * Test 'page', 'order_by' and 'mode' parametes of the apiList() method, and search by title.
  */
 public function testProblemListPager()
 {
     // Create a user and some problems with submissions for the tests.
     $contestant = UserFactory::createUser();
     for ($i = 0; $i < 6; $i++) {
         $problemData[$i] = ProblemsFactory::createProblem(null, null, 1);
         $runs = $i / 2;
         for ($r = 0; $r < $runs; $r++) {
             $runData = RunsFactory::createRunToProblem($problemData[$i], $contestant);
             $points = rand(0, 100);
             $verdict = 'WA';
             if ($points > 0) {
                 $verdict = $points == 100 ? 'AC' : 'PA';
             }
             RunsFactory::gradeRun($runData, $points / 100, $verdict);
         }
     }
     $request = new Request();
     $request['auth_token'] = $this->login($contestant);
     $response = ProblemController::apiList($request);
     // Test search by title
     $titles = array();
     foreach ($response['results'] as $problem) {
         array_push($titles, $problem['title']);
     }
     foreach ($titles as $title) {
         $request['query'] = $title;
         $response = ProblemController::apiList($request);
         $this->assertTrue(count($response['results']) == 1);
         $this->assertTrue($title === $response['results'][0]['title']);
     }
     $request['query'] = null;
     $response = ProblemController::apiList($request);
     $total = $response['total'];
     $pages = intval(($total + PROBLEMS_PER_PAGE - 1) / PROBLEMS_PER_PAGE);
     // The following tests will try the different scenarios that can occur
     // with the additions of the three features to apiList(), that is, paging,
     // order by column and order mode: Call apiList() with and without
     // pagination, for each allowed ordering and each possible order mode.
     $modes = array('asc', 'desc');
     $columns = array('title', 'submissions', 'accepted', 'ratio', 'points', 'score');
     $counter = 0;
     for ($paging = 0; $paging <= 1; $paging++) {
         foreach ($columns as $col) {
             foreach ($modes as $mode) {
                 $first = null;
                 $last = null;
                 $request['mode'] = $mode;
                 $request['order_by'] = $col;
                 if ($paging == 1) {
                     // Clear offset and rowcount if set.
                     if (isset($request['offset'])) {
                         unset($request['offset']);
                     }
                     if (isset($request['rowcount'])) {
                         unset($request['rowcount']);
                     }
                     $request['page'] = 1;
                     $response = ProblemController::apiList($request);
                     $first = $response['results'];
                     $request['page'] = $pages;
                     $response = ProblemController::apiList($request);
                     $last = $response['results'];
                     // Test number of problems per page
                     $this->assertEquals(PROBLEMS_PER_PAGE, count($first));
                 } else {
                     $request['page'] = null;
                     $response = ProblemController::apiList($request);
                     $first = $response['results'];
                     $last = $first;
                 }
                 $i = 0;
                 $j = count($last) - 1;
                 if ($col === 'title') {
                     $comp = strcmp($first[$i]['title'], $last[$j]['title']);
                     if ($mode === 'asc') {
                         $this->assertTrue($comp <= 0);
                     } else {
                         $this->assertTrue($comp >= 0);
                     }
                 } else {
                     if ($mode === 'asc') {
                         $this->assertTrue($first[$i][$col] <= $last[$j][$col]);
                     } else {
                         $this->assertTrue($first[$i][$col] >= $last[$j][$col]);
                     }
                 }
             }
         }
     }
 }
Beispiel #17
0
 /**
  * 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"]);
 }
Beispiel #18
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"]));
 }
Beispiel #19
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']);
 }
 /**
  * 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']);
 }
 /**
  * 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);
     }
 }