Skip to content

Commit

Permalink
テストケースに好きな名前を付けれるように & 入力のみのケースも許可
Browse files Browse the repository at this point in the history
  • Loading branch information
kmyk committed Sep 30, 2015
1 parent 437ecb0 commit e147df8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 32 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -128,7 +128,9 @@ OnlineJudgeHelperは幾つかのブログで紹介されました。

## 5. TODO

- 受け入れるテストケースの名前を柔軟にする
- サンプル取得、提出、コンパイル、テスト実行、全て分けるべき
- 特にコンパイルは不要/勝手にやられると不便
- テスト実行も同じである必要は特にない
- カレントディレクトリからいい感じにcontest\_idやproblem\_idを推測させたい
- 大本のリポジトリにプルリク投げる
- ライセンスが不明な状態を解消する
Expand Down
2 changes: 0 additions & 2 deletions completion/_oj
Expand Up @@ -26,8 +26,6 @@ _arguments -s -S \
"-c[Build and check the solution]" \
"--submit[Submit the solution]" \
"-s[Submit the solution]" \
"--add-test-case-template[Add a test case template file]" \
"-a[Add a test case template file]" \
"--download[Only download the test cases]" \
"-d[Only download the test cases]" \
"--poj[PKU JudgeOnline (default)]" \
Expand Down
7 changes: 1 addition & 6 deletions oj.py
Expand Up @@ -27,9 +27,6 @@ def main():
command.add_argument("-s", "--submit", action="store_const",
const="submit", dest="command",
help="Submit the solution")
command.add_argument("-a", "--add-test-case-template", action="store_const",
const="add_test_case", dest="command",
help="Add a test case template file")
command.add_argument('-d', '--download', action="store_const",
const='download', dest="command",
help="Only download the test cases")
Expand Down Expand Up @@ -165,9 +162,7 @@ def main():
if not os.path.exists(options.testcase_directory):
os.makedirs(options.testcase_directory)

if options.command == "add_test_case":
online_judge.add_test_case_template()
elif options.command == "submit":
if options.command == "submit":
online_judge.submit()
elif options.command == "create_solution_template_file":
online_judge.create_solution_template_file()
Expand Down
35 changes: 12 additions & 23 deletions onlinejudge.py
@@ -1,12 +1,14 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import cookielib
import glob
import json
import os
import os.path
import re
import shutil
import subprocess
import sys
import time
import urllib
import urllib2
Expand Down Expand Up @@ -153,20 +155,17 @@ def check(self):

validator = self.get_validator()

accept = 0
wa = 0
total = 0
no_input_files = True

for index in range(100):
input_file_path = self.get_input_file_path(index)
output_file_path = self.get_output_file_path(index)

if not os.path.exists(input_file_path):
break
for input_file_path in glob.iglob(os.path.join(self.options.testcase_directory, '*.in.txt')):
case_name = input_file_path.rsplit('.in.txt', 1)[0]
output_file_path = case_name + '.out.txt'

no_input_files = False

print(clr.GREEN + ('----- Case #%d -----' % index) + clr.RESET)
print(clr.GREEN + '----- Case {} -----'.format(case_name) + clr.RESET)

execution_time = solution.execute(input_file_path, 'out.txt')

Expand All @@ -176,31 +175,21 @@ def check(self):
if os.path.exists(output_file_path):
result = validator.validate(output_file_path, 'out.txt')
if result:
accept += 1
print(clr.BLUE + ('ok (%f sec)' % execution_time) + clr.RESET)
else:
print(clr.RED + ('WA (%f sec)' % execution_time) + clr.RESET)
wa += 1
else:
subprocess.Popen(['cp', 'out.txt', output_file_path]).wait()
sys.stdout.write(open('out.txt').read())
print(clr.GREEN + ('executed (%f sec)' % execution_time) + clr.RESET)
total += 1

if no_input_files:
print(clr.GREEN + 'No input files...' + clr.RESET)
elif accept == total:
elif wa == 0:
print(clr.BLUE + 'OK ({} cases) (max {} sec)'.format(total, max_time) + clr.RESET)
else:
print(clr.RED + 'WrongAnswer ({} WAs in {} cases) (max {} sec)'.format(total - accept, total, max_time) + clr.RESET)

def add_test_case_template(self):
for index in range(100):
input_filepath = self.get_input_file_path(index)
output_filepath = self.get_output_file_path(index)
if os.path.isfile(input_filepath):
continue
open(input_filepath, 'w').close()
open(output_filepath, 'w').close()
print("Test case template file " + str(index) + " is created.")
return
print(clr.RED + 'WrongAnswer ({} WAs in {} cases) (max {} sec)'.format(wa, total, max_time) + clr.RESET)

def submit(self):
raise NotImplementedError
Expand Down

0 comments on commit e147df8

Please sign in to comment.