Accept Merge Request #66 : (virusdefender-dev -> dev)

Merge Request: 部分 bug 修复;单元测试的问题修复
Created By: @virusdefender
Accepted By: @virusdefender
URL: https://coding.net/u/virusdefender/p/qduoj/git/merge/66
This commit is contained in:
virusdefender
2015-08-10 22:58:15 +08:00
17 changed files with 383 additions and 208 deletions

View File

@@ -0,0 +1,12 @@
#include <stdio.h>
int main()
{
int a = 0;
int i = 0;
for(i = 0; i < 9999999999;i++)
{
a += i;
}
printf("%d", a);
return 0;
}

View File

@@ -0,0 +1,6 @@
#include <stdio.h>
#include <unistd.h>
int main()
{
}

8
judge/tests/c/success.c Normal file
View File

@@ -0,0 +1,8 @@
# include <stdio.h>
int main()
{
int a, b;
scanf("%d %d", &a, &b);
printf("%d", a + b);
return 0;
}

View File

@@ -42,4 +42,6 @@ urlpatterns = [
url(r'^api/admin/problem/$', ProblemAdminAPIView.as_view(), name="problem_admin_api"),
url(r'^api/admin/test_case_upload/$', TestCaseUploadAPIView.as_view(), name="test_case_upload_api"),
url(r'^api/admin/tag/$', ProblemTagAdminAPIView.as_view(), name="problem_tag_admin_api"),
url(r'^problem/(?P<problem_id>\d+)/my_solutions/', "problem.views.problem_my_solutions_list_page", name="problem_my_solutions_page"),
url(r'^my_solution/(?P<solution_id>\d+)/$', "problem.views.my_solution", name="my_solution_page"),
]

View File

@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('problem', '0002_remove_problemtag_description'),
]
operations = [
migrations.RenameField(
model_name='problem',
old_name='sample',
new_name='samples',
),
]

View File

@@ -6,7 +6,6 @@ from account.models import User
class ProblemTag(models.Model):
name = models.CharField(max_length=30)
# description = models.CharField(max_length=50)
class Meta:
db_table = "problem_tag"
@@ -18,7 +17,7 @@ class AbstractProblem(models.Model):
# 问题描述 HTML 格式
description = models.TextField()
# 样例输入 可能会存储 json 格式的数据
sample = models.TextField(blank=True)
samples = models.TextField(blank=True)
# 测试用例id 这个id 可以用来拼接得到测试用例的文件存储位置
test_case_id = models.CharField(max_length=40)
# 提示

View File

@@ -14,7 +14,6 @@ class ProblemSampleSerializer(serializers.ListField):
class JSONField(serializers.Field):
def to_representation(self, value):
print value, type(value)
return json.loads(value)
@@ -22,18 +21,18 @@ class CreateProblemSerializer(serializers.Serializer):
title = serializers.CharField(max_length=50)
description = serializers.CharField(max_length=10000)
# [{"input": "1 1", "output": "2"}]
sample = ProblemSampleSerializer()
samples = ProblemSampleSerializer()
test_case_id = serializers.CharField(max_length=40)
source = serializers.CharField(max_length=30, required=False, default=None)
time_limit = serializers.IntegerField()
memory_limit = serializers.IntegerField()
difficulty = serializers.IntegerField()
tags = serializers.ListField(child=serializers.IntegerField())
tags = serializers.ListField(child=serializers.CharField(max_length=10))
hint = serializers.CharField(max_length=3000, required=False, default=None)
class ProblemSerializer(serializers.ModelSerializer):
sample = JSONField()
samples = JSONField()
class UserSerializer(serializers.ModelSerializer):
class Meta:
@@ -56,7 +55,7 @@ class EditProblemSerializer(serializers.Serializer):
memory_limit = serializers.IntegerField()
difficulty = serializers.IntegerField()
tags = serializers.ListField(child=serializers.IntegerField())
sample = ProblemSampleSerializer()
samples = ProblemSampleSerializer()
hint = serializers.CharField(max_length=10000)
visible = serializers.BooleanField()

View File

@@ -29,12 +29,12 @@ class ProblemAdminTest(APITestCase):
def test_success_problem(self):
self.client.login(username="test", password="testaa")
ProblemTag.objects.create(name="tag1", description="destag1")
ProblemTag.objects.create(name="tag1")
data = {"title": "title1",
"description": "des1",
"test_case_id": "1",
"source": "source1",
"sample": [{"input": "1 1", "output": "2"}],
"samples": [{"input": "1 1", "output": "2"}],
"time_limit": "100",
"memory_limit": "1000",
"difficulty": "1",
@@ -52,13 +52,13 @@ class ProblemAdminTest(APITestCase):
def test_problem_does_not_exist(self):
self.client.login(username="test", password="testaa")
ProblemTag.objects.create(name="tag1", description="destag1")
ProblemTag.objects.create(name="tag1")
tags = ProblemTag.objects.filter(id__in=[1])
problem = Problem.objects.create(title="title1",
description="des1",
test_case_id="1",
source="source1",
sample=[{"input": "1 1", "output": "2"}],
samples=[{"input": "1 1", "output": "2"}],
time_limit=100,
memory_limit=1000,
difficulty=1,
@@ -70,7 +70,7 @@ class ProblemAdminTest(APITestCase):
"description": "des1",
"test_case_id": "1",
"source": "source1",
"sample": [{"input": "1 1", "output": "2"}],
"samples": [{"input": "1 1", "output": "2"}],
"time_limit": "100",
"memory_limit": "1000",
"difficulty": "1",
@@ -82,14 +82,14 @@ class ProblemAdminTest(APITestCase):
def test_success_edit_problem(self):
self.client.login(username="test", password="testaa")
self.client.login(username="test", password="testaa")
ProblemTag.objects.create(name="tag1", description="destag1")
ProblemTag.objects.create(name="tag2", description="destag2")
ProblemTag.objects.create(name="tag1")
ProblemTag.objects.create(name="tag2")
tags = ProblemTag.objects.filter(id__in=[1])
problem0 = Problem.objects.create(title="title1",
description="des1",
test_case_id="1",
source="source1",
sample=[{"input": "1 1", "output": "2"}],
samples=[{"input": "1 1", "output": "2"}],
time_limit=100,
memory_limit=1000,
difficulty=1,
@@ -101,7 +101,7 @@ class ProblemAdminTest(APITestCase):
"description": "des1",
"test_case_id": "1",
"source": "source1",
"sample": [{"input": "1 1", "output": "2"}],
"samples": [{"input": "1 1", "output": "2"}],
"time_limit": "100",
"memory_limit": "1000",
"difficulty": "1",

View File

@@ -34,6 +34,7 @@ class ProblemTagAdminAPIView(APIView):
return error_response(serializer)
def get(self, request):
return success_response(ProblemTagSerializer(ProblemTag.objects.all(), many=True).data)
keyword = request.GET.get("keyword", None)
if not keyword:
return error_response(u"参数错误")
@@ -44,8 +45,20 @@ class ProblemTagAdminAPIView(APIView):
def problem_page(request, problem_id):
# todo
return render(request, "oj/problem/problem.html")
try:
problem = Problem.objects.get(id=problem_id)
except Problem.DoesNotExist:
return render(request, "utils/error.html", {"error": u"题目不存在"})
return render(request, "oj/problem/problem.html", {"problem": problem, "samples": json.loads(problem.samples)})
def problem_my_solutions_list_page(request, problem_id):
return render(request, "oj/problem/my_solutions_list.html")
def my_solution(request, solution_id):
return render(request, "oj/problem/my_solution.html")
class ProblemAdminAPIView(APIView):
@@ -63,15 +76,19 @@ class ProblemAdminAPIView(APIView):
description=data["description"],
test_case_id=data["test_case_id"],
source=data["source"],
sample=json.dumps(data["sample"]),
samples=json.dumps(data["samples"]),
time_limit=data["time_limit"],
memory_limit=data["memory_limit"],
difficulty=data["difficulty"],
created_by=request.user,
hint=data["hint"])
tags = ProblemTag.objects.filter(id__in=data["tags"])
problem.tags.add(*tags)
for tag in data["tags"]:
try:
tag = ProblemTag.objects.get(name=tag)
except ProblemTag.DoesNotExist:
tag = ProblemTag.objects.create(name=tag)
problem.tags.add(tag)
return success_response(ProblemSerializer(problem).data)
else:
return serializer_invalid_response(serializer)
@@ -98,7 +115,7 @@ class ProblemAdminAPIView(APIView):
problem.time_limit = data["time_limit"]
problem.memory_limit = data["memory_limit"]
problem.difficulty = data["difficulty"]
problem.sample = json.dumps(data["sample"])
problem.samples = json.dumps(data["samples"])
problem.hint = data["hint"]
problem.visible = data["visible"]

View File

@@ -5,6 +5,7 @@
@import url("simditor/simditor.css");
@import url("webuploader/webuploader.css");
@import url("datetime_picker/bootstrap-datetimepicker.css");
@import url("tagEditor/jquery.tag-editor.css");
#loading-gif{
width: 40px;

View File

@@ -64,18 +64,15 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "csrf", "tagEdito
})
.on("success.form.fv", function (e) {
e.preventDefault();
if (vm.test_case_id == '')
{
if (vm.test_case_id == '') {
bs_alert("你还没有上传测试数据!");
return;
}
if (vm.description == '')
{
if (vm.description == '') {
bs_alert("题目描述不能为空!");
return;
}
if (vm.hint == '')
{
if (vm.hint == '') {
bs_alert("提示不能为空!");
return;
}
@@ -88,33 +85,30 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "csrf", "tagEdito
test_case_id: vm.test_case_id,
hint: vm.hint,
source: vm.source,
tags: [],
tags: $("#tags").tagEditor("getTags")[0].tags,
difficulty: vm.difficulty
};
if (vm.samples.length == 0)
{
if (vm.samples.length == 0) {
bs_alert("请至少添加一组样例!");
return;
}
var tags = $("#tags").tagEditor("getTags")[0].tags;
if (tags.length == 0)
{
if (tags.length == 0) {
bs_alert("请至少添加一个标签,这将有利于用户发现你的题目!");
return;
}
for (key in vm.samples.length) {
ajaxData.samples.push({input: vm.samples[key].input, output: vm.samples[key].output});
for (var i = 0; i < vm.samples.$model.length; i++) {
ajaxData.samples.push({input: vm.samples.$model[i].input, output: vm.samples.$model[i].output});
}
for (key in tags) {
ajaxData.tags.push(tags[key].tag);
}
console.log(ajaxData);
$.ajax({
beforeSend: csrfHeader,
url: "/api/admin/problem/",
dataType: "json",
data:ajaxData,
data: JSON.stringify(ajaxData),
method: "post",
contentType: "application/json",
success: function (data) {
if (!data.code) {
bs_alert("successful!");
@@ -188,8 +182,8 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "csrf", "tagEdito
if (!data.code) {
tagList = data.data;
completeList = [];
for (key in tagList) {
completeList.push(tagList[key].name);
for (var i = 0; i < tagList.length; i++) {
completeList.push(tagList[i].name);
}
$("#tags").tagEditor({
autocomplete: {

View File

@@ -22,10 +22,12 @@ require(["jquery", "code_mirror"], function ($, code_mirror) {
setTimeout(
function () {
$("#a").animate({opacity: '1'})
}
,
3);
}, 3);
});
$("#show-more-btn").click(function(){
$(".hide").attr("class", "problem-section");
$("#show-more-btn").hide();
})
});

View File

@@ -12,7 +12,7 @@ var require = {
validation: "utils/validation",
code_mirror: "utils/code_mirror",
bs_alert: "utils/bs_alert",
submit_code: "app/oj/problem/submit_code",
problem: "app/oj/problem/problem",
contest: "app/admin/contest/contest",
csrf: "utils/csrf",
admin: "app/admin/admin",

View File

@@ -1,23 +1,17 @@
<div ms-controller="add_problem" class="col-md-9">
<form id="add-problem-form">
<div class="col-md-12">
<div class="form-group col-md-6">
<div class="form-group col-md-12">
<label>题目标题</label>
<input type="text" name="title" class="form-control" ms-duplex="title">
</div>
<div class="form-group col-md-6">
<label>来源</label>
<input type="text" name="source" class="form-control" ms-duplex="source">
</div>
<div class="form-group">
<div class="form-group col-md-12">
<label>题目描述</label>
<textarea id="problemDescription" placeholder="这里输入内容" autofocus ms-duplex="description"></textarea>
<small ms-visible="description==''" style="color:red">请填写题目描述</small>
</div>
<div class="form-group">
<label>提示</label>
<textarea id="hint" placeholder="这里输入内容" ms-duplex="hint"></textarea>
</div>
<div class="col-md-3">
<div class="form-group"><label>时间限制(ms)</label>
@@ -54,7 +48,7 @@
<span class="panel-title">样例{{$index + 1}}</span>
<a href="javascript:void(0)" class="btn btn-primary btn-sm"
ms-click="toggle_sample(sample)">
{{getBtnContent(sample)}}
{{ getBtnContent(sample)}}
</a>
<a href="javascript:void(0)" class="btn btn-danger btn-sm"
ms-click="del_sample(sample)">
@@ -81,10 +75,19 @@
<div class="col-md-12"><br>
<label>测试数据</label><br>
<small class="text-info">请将所有测试用例打包在一个文件中上传所有文件要在压缩包的根目录且输入输出文件名要以从1开始连续数字标识要对应例如<br>
1.in 1.out 2.in 2.out</small>
1.in 1.out 2.in 2.out
</small>
<table class="table table-striped" ms-visible="uploadSuccess">
<tr><td>编号</td><td>输入文件名</td><td>输出文件名</td></tr>
<tr ms-repeat="testCaseList"><td>{{$index}}</td><td>{{el.input}}</td><td>{{el.output}}</td></tr>
<tr>
<td>编号</td>
<td>输入文件名</td>
<td>输出文件名</td>
</tr>
<tr ms-repeat="testCaseList">
<td>{{$index + 1}}</td>
<td>{{ el.input }}</td>
<td>{{ el.output }}</td>
</tr>
</table>
</div>
<div class="col-md-12">
@@ -92,7 +95,15 @@
<div id="testCaseFile">选择文件</div>
</div>
</div>
<div class="form-group col-md-12">
<label>提示</label>
<textarea id="hint" placeholder="这里输入内容" ms-duplex="hint"></textarea>
</div>
<div class="form-group col-md-12">
<label>来源</label>
<input type="text" name="source" class="form-control" ms-duplex="source">
</div>
<div class="col-md-12">
<input type="submit" class="btn btn-success btn-lg" value="发布题目" id="submitBtn">
</div>
@@ -100,4 +111,3 @@
</div>
<script src="/static/js/app/admin/problem/add_problem.js"></script>
<link href="/static/css/tagEditor/jquery.tag-editor.css" rel="stylesheet">

View File

@@ -0,0 +1,31 @@
{% extends 'oj_base.html' %}
{% block body %}
<div class="container main">
<ul class="nav nav-tabs nav-tabs-google">
<li role="presentation">
<a href="problem.html">题目</a></li>
<li role="presentation" class="active"><a href="my_solutions_list.html">我的提交</a></li>
<li role="presentation"><a href="#">讨论</a></li>
</ul>
<h2 class="text-center">Battle Over Cities - Hard Version</h2>
<p class="text-muted text-center">cpu: 1000ms 内存: 256M</p>
<div class="panel panel-default">
<div class="panel-body">
<h4>运行结果:<span class="text-success">Accepted</span></h4>
<p>cpu: 1000ms 内存: 256M 语言:python</p>
</div>
</div>
<div id="code-field">
<textarea id="code-editor">
#include &lt;stdio.h&gt;
int main()
{
printf(&quot;Hello world&quot;);
return 0;
}</textarea>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,53 @@
{% extends 'oj_base.html' %}
{% block body %}
<div class="container main">
<ul class="nav nav-tabs nav-tabs-google">
<li role="presentation">
<a href="/problem/1/">题目</a></li>
<li role="presentation" class="active"><a href="my_solutions_list.html">我的提交</a></li>
</ul>
<h2 class="text-center">Battle Over Cities - Hard Version</h2>
<p class="text-muted text-center">cpu: 1000ms 内存: 256M</p>
<table class="table table-bordered">
<thead>
<tr class=""success>
<th>#</th>
<th>提交时间</th>
<th>结果</th>
<th>运行时间</th>
<th>运行内存</th>
<th>语言</th>
</tr>
</thead>
<tbody>
<tr class="warning">
<th scope="row">1</th>
<td>1</td>
<td>Error Format</td>
<td>3</td>
<td>3</td>
<td>3</td>
</tr>
<tr class="danger">
<th scope="row">2</th>
<td>Wrong</td>
<td>Wrong Answer</td>
<td>@fat</td>
<td>3</td>
<td>3</td>
</tr>
<tr class="success">
<th scope="row">3</th>
<td>Larry</td>
<td>Accepted</td>
<td>@twitter</td>
<td>3</td>
<td>3</td>
</tr>
</tbody>
</table>
</div>
{% endblock %}

View File

@@ -1,22 +1,21 @@
{% extends 'oj_base.html' %}
{% block body %}
<div class="container main">
<div class="container main">
<ul class="nav nav-tabs nav-tabs-google">
<li role="presentation" class="active">
<a href="problem.html">题目</a></li>
<li role="presentation"><a href="my_solutions_list.html">我的提交</a></li>
<li role="presentation"><a href="/problem/1/my_solutions/">我的提交</a></li>
</ul>
<h2 class="text-center">Battle Over Cities - Hard Version</h2>
<h2 class="text-center">{{ problem.title }}</h2>
<p class="text-muted text-center">cpu: 1000ms 内存: 256M</p>
<p class="text-muted text-center">发布时间: {{ problem.create_time }} CPU: {{ problem.time_limit }}ms 内存: {{ problem.memory_limit }}M</p>
<div>
<div class="problem-section">
<label class="problem-label">描述</label>
<p class="problem-detail"> n的阶乘定义为n!=1*2*3*……*n 如3!=6
n!通常最后会有很多0如5!=120 最后有一个0现在统计n!去除末尾的0后最后k位是多少</p>
<p class="problem-detail">{{ problem.description|safe }}</p>
</div>
<div class="problem-section">
<label class="problem-label">输入</label>
@@ -28,21 +27,43 @@
<p class="problem-detail">第一行包括两个数n,k</p>
</div>
{% for item in samples %}
<div class="problem-section">
<label class="problem-label">样例输入</label>
<pre title="双击可以复制哦~">
1 2 3 4 5 6 7
1 2 3 4 5 6 7</pre>
</div>
<div class="problem-section">
<label class="problem-label">样例输出</label>
<label class="problem-label">样例输入1</label>
<pre>
1 2 3 4 5 6 7</pre>
{{ item.input }}</pre>
</div>
<div class="problem-section">
<label class="problem-label">样例输出1</label>
<pre>
{{ item.output }}</pre>
</div>
{% endfor %}
<div>
<button type="button" id="show-more-btn" class="btn btn-info btn-sm">查看隐藏信息</button>
</div>
{% if problem.hind %}
<div class="problem-section hide">
<label class="problem-label">提示</label>
<p class="problem-detail">{{ problem.hint|safe }}</p>
</div>
{% endif %}
<div class="problem-section hide">
<label class="problem-label">标签</label>
<p class="problem-detail">
{% for tag in problem.tags.all %}
<span class="label label-success">{{ tag.name }}</span>
{% endfor %}
</p>
</div>
<div>
<label>选择语言</label>
<div>
<label class="radio-inline">
<input type="radio" name="inlineRadioOptions" value="c" checked> c (gcc 4.8)
@@ -55,6 +76,7 @@
</label>
</div>
</div>
<div id="code-field">
<label class="problem-label">提交代码</label>
<textarea id="code-editor"></textarea>
@@ -86,8 +108,8 @@
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block js_block %}
<script src="/static/js/app/oj/problem/submit_code.js"></script>
<script src="/static/js/app/oj/problem/problem.js"></script>
{% endblock %}