Skip to content

Commit

Permalink
Can use files as testcases now
Browse files Browse the repository at this point in the history
  • Loading branch information
sunner committed Jul 6, 2010
1 parent 8cf77d2 commit fd3471a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 23 deletions.
34 changes: 22 additions & 12 deletions assignment.class.php
Expand Up @@ -307,18 +307,25 @@ function after_add_update($assignment) {
/**
* Get tests data for current assignment.
*
* @param object $cm Course module
* @return array tests An array of tests objects
* @return array tests An array of tests objects. All testcase files are read into memory
*/
function get_tests($cm=null) {
if (isset($cm->instance))
$instanceid = $cm->instance;
else if (isset($this->cm->instance))
$instanceid = $this->cm->instance;
else
return null;

return get_records('assignment_oj_tests', 'assignment', $instanceid, 'id ASC');
function get_tests() {
global $CFG;

$records = get_records('assignment_oj_tests', 'assignment', $this->assignment->id, 'id ASC');
$tests = array();

foreach ($records as $record) {
if ($record->usefile) {
if (! $record->input = file_get_contents("$CFG->dataroot/{$this->assignment->course}/$record->inputfile"))
continue; //Skip case whose file(s) can't be read
if (! $record->output = file_get_contents("$CFG->dataroot/{$this->assignment->course}/$record->outputfile"))
continue; //Skip case whose file(s) can't be read
}
$tests[] = $record;
}

return $tests;
}

/**
Expand Down Expand Up @@ -1192,7 +1199,7 @@ function daemon()

set_config('assignment_oj_daemon_pid' , $pid);

// Run forever until being killed
// Run forever until be killed or plugin was upgraded
while(!empty($CFG->assignment_oj_daemon_pid)){
global $db;

Expand All @@ -1204,6 +1211,9 @@ function daemon()

//Check interval is 5 seconds
sleep(5);

//renew the config value which could be modified by other processes
$CFG->assignment_oj_daemon_pid = get_config(NULL, 'assignment_oj_daemon_pid');
}
}

Expand Down
3 changes: 3 additions & 0 deletions db/upgrade.php
Expand Up @@ -125,6 +125,9 @@ function xmldb_assignment_type_onlinejudge_upgrade($oldversion=0) {

}

// Tell the daemon to exit
set_config('assignment_oj_daemon_pid' , '0');

return $result;
}

Expand Down
14 changes: 9 additions & 5 deletions lang/en_utf8/assignment_onlinejudge.php
@@ -1,11 +1,7 @@
<?php
$string['rejudge'] = 'Rejudge';
$string['rejudgeall'] = 'Rejudge all';
$string['rejudgeallnotice'] = 'Are you sure to rejude all submissions in $a?';
$string['rejudgefailed'] = 'Can not submitted rejudge request.';
$string['rejudgesuccess'] = 'Rejudge request has been submitted successfully.';
$string['addtestcases'] = 'Add $a more testcase(s)';
$string['assignmentlangs'] = 'Programming language';
$string['badtestcasefile'] = 'This file does not exist or can not be read';
$string['cannotruncompiler'] = 'Can not execute the script of compiler';
$string['case'] = 'Case $a:';
$string['compileonly'] = 'Compile only';
Expand All @@ -32,6 +28,7 @@
$string['infotle'] = 'The program has been running for a too long time.';
$string['infowa'] = 'Double check your code. Don\'t output any typo or unrequired character.';
$string['input'] = 'Input';
$string['inputfile'] = 'Input file';
$string['judgetime'] = 'Judge time';
$string['langc'] = 'C';
$string['langc_warn2err'] = 'C (Warnings as Errors)';
Expand Down Expand Up @@ -89,7 +86,13 @@
$string['maxmemusage'] = 'Maximum memory usage';
$string['memlimit'] = 'Maximum memory usage';
$string['output'] = 'Output';
$string['outputfile'] = 'Output file';
$string['ratiope'] = 'Ratio for presentation error';
$string['rejudge'] = 'Rejudge';
$string['rejudgeall'] = 'Rejudge all';
$string['rejudgeallnotice'] = 'Are you sure to rejude all submissions in $a?';
$string['rejudgefailed'] = 'Can not submitted rejudge request.';
$string['rejudgesuccess'] = 'Rejudge request has been submitted successfully.';
$string['runtimeout'] = 'Runtime output';
$string['statusac'] = '<font color=red>Accepted</font>';
$string['statusat'] = 'Abnormal Termination';
Expand All @@ -107,4 +110,5 @@
$string['statuswa'] = 'Wrong answer';
$string['testcases'] = 'Test Cases';
$string['typeonlinejudge'] = 'Online Judge';
$string['usefile'] = 'Testcase from files';
?>
14 changes: 9 additions & 5 deletions lang/zh_cn_utf8/assignment_onlinejudge.php
@@ -1,11 +1,7 @@
<?php
$string['rejudge'] = '重新评测';
$string['rejudgeall'] = '全部重新评测';
$string['rejudgeallnotice'] = '您确定要重新评测“{$a}”中所有已交的作业吗?';
$string['rejudgefailed'] = '无法提交重新评测请求。';
$string['rejudgesuccess'] = '重新评测请求已经成功提交。';
$string['addtestcases'] = '增加 $a 组测试用例';
$string['assignmentlangs'] = '编程语言';
$string['badtestcasefile'] = '此文件不存在,或不可读';
$string['cannotruncompiler'] = '无法执行编译器脚本';
$string['case'] = '用例{$a}:';
$string['compileonly'] = '只编译';
Expand All @@ -32,6 +28,7 @@
$string['infotle'] = '此程序运行得太久了。';
$string['infowa'] = '请仔细检查您的代码。不要在输出中有手误或任何未要求的字符';
$string['input'] = '输入';
$string['inputfile'] = '输入文件';
$string['judgetime'] = '评测时间';
$string['langc_warn2err'] = 'C (警告视为错误)';
$string['langcpp_warn2err'] = 'C++ (警告视为错误)';
Expand All @@ -41,7 +38,13 @@
$string['maxmemusage'] = '最大内存用量';
$string['memlimit'] = '内存最多可用';
$string['output'] = '输出';
$string['outputfile'] = '输出文件';
$string['ratiope'] = '格式错误得分比例';
$string['rejudge'] = '重新评测';
$string['rejudgeall'] = '全部重新评测';
$string['rejudgeallnotice'] = '您确定要重新评测“{$a}”中所有已交的作业吗?';
$string['rejudgefailed'] = '无法提交重新评测请求。';
$string['rejudgesuccess'] = '重新评测请求已经成功提交。';
$string['statusat'] = '非正常结束';
$string['statusce'] = '编译错误';
$string['statuscompileok'] = '编译通过';
Expand All @@ -57,4 +60,5 @@
$string['statuswa'] = '错误答案';
$string['testcases'] = '测试用例';
$string['typeonlinejudge'] = '在线评测';
$string['usefile'] = '测试用例来自文件';
?>
2 changes: 1 addition & 1 deletion version.php
Expand Up @@ -5,7 +5,7 @@
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////

$plugin->version = 2010070400;
$plugin->version = 2010070600;
$plugin->requires = 2007010100; // Requires this Moodle version

?>

0 comments on commit fd3471a

Please sign in to comment.