Skip to content

Commit

Permalink
#318: add tests and fix a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kmyk committed Feb 18, 2019
1 parent f4736d8 commit 79a26ff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion onlinejudge/service/atcoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def from_url(cls, s: str, problem_id: Optional[str] = None) -> Optional['AtCoder
# example: https://beta.atcoder.jp/contests/abc073/submissions/1592381
m = re.match(r'^/contests/([\w\-_]+)/submissions/(\d+)$', utils.normpath(result.path))
if result.scheme in ('', 'http', 'https') \
and result.netloc == ('atcoder.jp', 'beta.atcoder.jp') \
and result.netloc in ('atcoder.jp', 'beta.atcoder.jp') \
and m:
contest_id = m.group(1)
try:
Expand Down
16 changes: 16 additions & 0 deletions tests/service_atcoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,21 @@ def test_list_problems(self):
self.assertEqual(problems[6].problem_id, 'agc028_f2')


class AtCoderProblemTest(unittest.TestCase):
def test_from_url(self):
self.assertEqual(AtCoderProblem.from_url('https://kupc2014.contest.atcoder.jp/tasks/kupc2014_d').contest_id, 'kupc2014')
self.assertEqual(AtCoderProblem.from_url('https://kupc2014.contest.atcoder.jp/tasks/kupc2014_d').problem_id, 'kupc2014_d')
self.assertEqual(AtCoderProblem.from_url('https://atcoder.jp/contests/agc030/tasks/agc030_c').contest_id, 'agc030')
self.assertEqual(AtCoderProblem.from_url('https://atcoder.jp/contests/agc030/tasks/agc030_c').problem_id, 'agc030_c')


class AtCoderSubmissionTest(unittest.TestCase):
def test_from_url(self):
self.assertEqual(AtCoderSubmission.from_url('https://atcoder.jp/contests/kupc2012/submissions/2097011').contest_id, 'kupc2012')
self.assertEqual(AtCoderSubmission.from_url('https://atcoder.jp/contests/kupc2012/submissions/2097011').submission_id, 2097011)
self.assertEqual(AtCoderSubmission.from_url('https://qupc2014.contest.atcoder.jp/submissions/1444440').contest_id, 'qupc2014')
self.assertEqual(AtCoderSubmission.from_url('https://qupc2014.contest.atcoder.jp/submissions/1444440').submission_id, 1444440)


if __name__ == '__main__':
unittest.main()

0 comments on commit 79a26ff

Please sign in to comment.