Skip to content

Commit

Permalink
Merge pull request #447 from kmyk/issue/446
Browse files Browse the repository at this point in the history
#446: fix a bug with time limits which are less than 1 sec
  • Loading branch information
fukatani authored Jun 14, 2019
2 parents 94f4f7b + 8871814 commit e101db9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
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 @@ -89,6 +89,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 @@ -139,6 +148,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

0 comments on commit e101db9

Please sign in to comment.