-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from TitanSnow/TitanSnow
little improvements and bugs fixing
- Loading branch information
Showing
14 changed files
with
475 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,5 @@ python: | |
- "3.6" | ||
- "pypy" | ||
- "pypy3" | ||
script: python unit_test.py | ||
|
||
install: pip install tox-travis | ||
script: tox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import hashlib | ||
from .graderregistry import CYaRonGraders | ||
from .mismatch import HashMismatch | ||
|
||
@CYaRonGraders.grader("FullText") | ||
def fulltext(content, std): | ||
content_hash = hashlib.sha256(content.encode('utf-8')).hexdigest() | ||
std_hash = hashlib.sha256(std.encode('utf-8')).hexdigest() | ||
return (True, None) if content_hash == std_hash else (False, "Hash mismatch: read %s, expected %s" % (content_hash, std_hash)) | ||
return (True, None) if content_hash == std_hash else (False, HashMismatch(content, std, content_hash, std_hash)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
class Mismatch(ValueError): | ||
"""exception for content mismatch""" | ||
def __init__(self, content, std, *args): | ||
""" | ||
content -> content got | ||
std -> content expected | ||
""" | ||
super(Mismatch, self).__init__(content, std, *args) | ||
self.content = content | ||
self.std = std | ||
|
||
class HashMismatch(Mismatch): | ||
"""exception for hash mismatch""" | ||
def __init__(self, content, std, content_hash, std_hash): | ||
""" | ||
content -> content got | ||
std -> content expected | ||
content_hash -> hash of content | ||
std_hash -> hash of std | ||
""" | ||
super(HashMismatch, self).__init__(content, std, content_hash, std_hash) | ||
self.content_hash = content_hash | ||
self.std_hash = std_hash | ||
|
||
def __str__(self): | ||
return "Hash mismatch: read %s, expected %s" % (self.content_hash, self.std_hash) | ||
|
||
class TextMismatch(Mismatch): | ||
"""exception for text mismatch""" | ||
def __init__(self, content, std, err_msg, lineno=None, colno=None, content_token=None, std_token=None): | ||
""" | ||
content -> content got | ||
std -> content expected | ||
err_msg -> error message template like "wrong on line {} col {} read {} expected {}" | ||
lineno -> line number | ||
colno -> column number | ||
content_token -> the token of content mismatch | ||
std_token -> the token of std | ||
""" | ||
super(TextMismatch, self).__init__(content, std, err_msg, lineno, colno, content_token, std_token) | ||
self.err_msg = err_msg.format(lineno, colno, content_token, std_token) | ||
self.lineno = lineno | ||
self.colno = colno | ||
self.content_token = content_token | ||
self.std_token = std_token | ||
|
||
def __str__(self): | ||
return self.err_msg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
from ..utils import * | ||
from .graderregistry import CYaRonGraders | ||
from .mismatch import TextMismatch | ||
|
||
|
||
@CYaRonGraders.grader("NOIPStyle") | ||
def noipstyle(content, std): | ||
content_lines = strtolines(content.replace('\r\n', '\n')) | ||
std_lines = strtolines(std.replace('\r\n', '\n')) | ||
if len(content_lines) != len(std_lines): | ||
return False, 'Too many or too few lines.' | ||
return False, TextMismatch(content, std, 'Too many or too few lines.') | ||
|
||
for i in range(len(content_lines)): | ||
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, 'On line %d column %d, read %s, expected %s.' | ||
% (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, 'Too short on line %d.' % i | ||
return False, TextMismatch(content, std, 'Too short on line {}.', i) | ||
if len(std_lines[i]) < len(content_lines[i]): | ||
return False, 'Too long on line %d.' % i | ||
return False, TextMismatch(content, std, 'Too long on line {}.', i) | ||
|
||
return True, None | ||
return True, None |
Oops, something went wrong.