Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#446: fix a bug with time limits which are less than 1 sec #447

Merged
merged 1 commit into from
Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions onlinejudge/service/atcoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,12 @@ def _AtCoderProblemContentPartial_from_row(tr: bs4.Tag):
assert problem is not None
alphabet = tds[0].text
name = tds[1].text
time_limit_msec = int(float(utils.remove_suffix(tds[2].text, ' sec')) * 1000)
if tds[2].text.endswith(' msec'):
time_limit_msec = int(utils.remove_suffix(tds[2].text, ' msec'))
elif tds[2].text.endswith(' sec'):
time_limit_msec = int(float(utils.remove_suffix(tds[2].text, ' sec')) * 1000)
else:
assert False
memory_limit_byte = int(float(utils.remove_suffix(tds[3].text, ' MB')) * 1000 * 1000) # TODO: confirm this is MB truly, not MiB
if len(tds) == 5:
assert tds[4].text.strip() in ('', 'Submit', '提出')
Expand Down Expand Up @@ -471,7 +476,12 @@ def _AtCoderProblemContent_parse_partial(soup: bs4.BeautifulSoup, problem: 'AtCo
break
else:
assert False
time_limit_msec = int(float(utils.remove_suffix(utils.remove_prefix(time_limit, time_limit_prefix), ' sec')) * 1000)
if time_limit.endswith(' msec'):
time_limit_msec = int(utils.remove_suffix(utils.remove_prefix(time_limit, time_limit_prefix), ' msec'))
elif time_limit.endswith(' sec'):
time_limit_msec = int(float(utils.remove_suffix(utils.remove_prefix(time_limit, time_limit_prefix), ' sec')) * 1000)
else:
assert False

for memory_limit_prefix in ('メモリ制限: ', 'Memory Limit: '):
if memory_limit.startswith(memory_limit_prefix):
Expand Down
13 changes: 13 additions & 0 deletions tests/service_atcoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ def test_list_problems_with_float_values(self):
self.assertEqual(problems[1].get_time_limit_msec(), 5252)
self.assertEqual(problems[1].get_memory_limit_byte(), int(525.252 * 1000 * 1000))

def test_list_problems_time_limit_is_less_than_msec(self):
contest = AtCoderContest.from_url('https://atcoder.jp/contests/joi2019ho')
problems = contest.list_problems()
self.assertEqual(problems[0].get_time_limit_msec(), 1000)
self.assertEqual(problems[1].get_time_limit_msec(), 1000)
self.assertEqual(problems[2].get_time_limit_msec(), 500)
self.assertEqual(problems[3].get_time_limit_msec(), 1000)
self.assertEqual(problems[4].get_time_limit_msec(), 2000)

def test_iterate_submissions(self):
contest = AtCoderContest.from_url('https://atcoder.jp/contests/code-festival-2014-exhibition-open')
submissions = list(contest.iterate_submissions())
Expand Down Expand Up @@ -135,6 +144,10 @@ def test_get_score_latex(self):

self.assertIsNone(AtCoderProblem.from_url('https://atcoder.jp/contests/wupc2019/tasks/wupc2019_a').get_score())

def test_get_time_limit_is_less_than_msec(self):
self.assertEqual(AtCoderProblem.from_url('https://atcoder.jp/contests/joi2019ho/tasks/joi2019ho_c').get_time_limit_msec(), 500)
self.assertEqual(AtCoderProblem.from_url('https://atcoder.jp/contests/joi2019ho/tasks/joi2019ho_d').get_time_limit_msec(), 1000)

def test_iterate_submissions(self):
problem = AtCoderProblem.from_url('https://atcoder.jp/contests/abc119/tasks/abc119_c')
submissions = problem.iterate_submissions()
Expand Down