Skip to content

Commit

Permalink
Merge pull request #39 from Himself65/master
Browse files Browse the repository at this point in the history
修复对拍器比较异常问题
  • Loading branch information
Toto Lin authored Jun 13, 2018
2 parents cd3dfb9 + d649b3e commit 4eefc6c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
9 changes: 8 additions & 1 deletion cyaron/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def __init__(self, name, mismatch):
self.name = name
self.mismatch = mismatch

def __str__(self):
return 'In program: \'{}\'. {}'.format(self.name,self.mismatch)


class Compare:
@staticmethod
Expand Down Expand Up @@ -111,7 +114,10 @@ def program(cls, *programs, **kwargs):

if std_program is not None:
def get_std():
return make_unicode(subprocess.check_output(std_program, shell=(not list_like(std_program)), stdin=input.input_file, universal_newlines=True))
with open(os.dup(input.input_file.fileno()), 'r', newline='\n') as input_file:
content = make_unicode(subprocess.check_output(std_program, shell=(not list_like(std_program)), stdin=input.input_file, universal_newlines=True))
input_file.seek(0)
return content
if job_pool is not None:
std = job_pool.submit(get_std).result()
else:
Expand All @@ -135,6 +141,7 @@ def do(program_name):
content = make_unicode(subprocess.check_output(program_name, shell=(not list_like(program_name)), stdin=input_file, universal_newlines=True))
else:
content = make_unicode(subprocess.check_output(program_name, shell=(not list_like(program_name)), stdin=input_file, universal_newlines=True, timeout=timeout))
input_file.seek(0)
cls.__compare_two(program_name, content, std, grader)

if job_pool is not None:
Expand Down
16 changes: 12 additions & 4 deletions cyaron/graders/noipstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ def noipstyle(content, std):
if std_lines[i] != content_lines[i]:
for j in range(min(len(std_lines[i]), len(content_lines[i]))):
if std_lines[i][j] != content_lines[i][j]:
return (False, TextMismatch(content, std, 'On line {} column {}, read {}, expected {}.',
i + 1, j + 1, content_lines[i][j:j + 5], std_lines[i][j:j + 5]))
return (False,
TextMismatch(
content, std,
'On line {} column {}, read {}, expected {}.',
i + 1, j + 1, content_lines[i][j:j + 5],
std_lines[i][j:j + 5]))
if len(std_lines[i]) > len(content_lines[i]):
return False, TextMismatch(content, std, 'Too short on line {}.', i)
return False, TextMismatch(
content, std, 'Too short on line {}.', i + 1, j + 1,
content_lines[i][j:j + 5], std_lines[i][j:j + 5])
if len(std_lines[i]) < len(content_lines[i]):
return False, TextMismatch(content, std, 'Too long on line {}.', i)
return False, TextMismatch(
content, std, 'Too long on line {}.', i + 1, j + 1,
content_lines[i][j:j + 5], std_lines[i][j:j + 5])

return True, None

0 comments on commit 4eefc6c

Please sign in to comment.