Repository: kmyk/online-judge-tools
Pull request #378 (2019-03-09 13:02:11)

 #375: rename two methods to get_name()
-  `AtCoderProblem.get_task_name()` を `Problem.get_name()` を作って置き換え
-  `AtCoderContest.get_contest_name()` を `AtCoderContest.get_name()` で置き換え


Patch:
diff --git a/onlinejudge/service/atcoder.py b/onlinejudge/service/atcoder.py
index 266de83..5d090ae 100644
--- a/onlinejudge/service/atcoder.py
+++ b/onlinejudge/service/atcoder.py
@@ -253,17 +253,8 @@ class AtCoderContest(object):
         assert m
         self._penalty = datetime.timedelta(minutes=int(m.group(2)))
 
-    def get_contest_name(self, lang: Optional[str] = None, session: Optional[requests.Session] = None) -> str:
-        if lang is None:
-            if self._contest_name_en is not None:
-                return self._contest_name_en
-            elif self._contest_name_ja is not None:
-                return self._contest_name_ja
-            else:
-                self._load_details(lang='en', session=session)
-                assert self._contest_name_en is not None
-                return self._contest_name_en
-        elif lang == 'en':
+    def get_name(self, lang: str = 'en', session: Optional[requests.Session] = None) -> str:
+        if lang == 'en':
             if self._contest_name_en is None:
                 self._load_details(lang='en', session=session)
             assert self._contest_name_en is not None
@@ -606,7 +597,7 @@ class AtCoderProblem(onlinejudge.type.Problem):
             assert self._score_checked
         return self._score
 
-    get_task_name = utils.getter_with_load_details('_task_name', type=str)  # type: Callable[..., str]
+    get_name = utils.getter_with_load_details('_task_name', type=str)  # type: Callable[..., str]
     get_time_limit_msec = utils.getter_with_load_details('_time_limit_msec', type=int)  # type: Callable[..., int]
     get_memory_limit_byte = utils.getter_with_load_details('_memory_limit_byte', type=int)  # type: Callable[..., int]
     get_alphabet = utils.getter_with_load_details('_alphabet', type=str)  # type: Callable[..., str]
diff --git a/onlinejudge/type.py b/onlinejudge/type.py
index fc6f517..1c8d285 100644
--- a/onlinejudge/type.py
+++ b/onlinejudge/type.py
@@ -91,6 +91,16 @@ class Problem(object):
     def get_service(self) -> Service:
         raise NotImplementedError
 
+    def get_name(self) -> str:
+        """
+        example:
+
+        -   `器物損壊！高橋君`
+        -   `AtCoDeerくんと変なじゃんけん / AtCoDeer and Rock-Paper`
+        -   `Xor Sum`
+        """
+        raise NotImplementedError
+
     def get_input_format(self, session: Optional[requests.Session] = None) -> Optional[str]:
         raise NotImplementedError
 


Test patch:
diff --git a/tests/service_atcoder.py b/tests/service_atcoder.py
index 7237cbf..0028428 100644
--- a/tests/service_atcoder.py
+++ b/tests/service_atcoder.py
@@ -22,7 +22,7 @@ class AtCoderSerivceTest(unittest.TestCase):
         self.assertEqual(contest.get_start_time().year, 2014)
         self.assertEqual(contest.get_start_time().month, 3)
         self.assertEqual(contest.get_start_time().day, 2)
-        self.assertEqual(contest.get_contest_name(), '東京大学プログラミングコンテスト2013')
+        self.assertEqual(contest.get_name(), '東京大学プログラミングコンテスト2013')
         self.assertEqual(contest.get_duration().total_seconds(), 5 * 60 * 60)
         self.assertEqual(contest.get_rated_range(), 'All')
 
@@ -35,8 +35,8 @@ class AtCoderContestTest(unittest.TestCase):
 
     def test_load_details(self):
         contest = AtCoderContest.from_url('https://atcoder.jp/contests/keyence2019')
-        self.assertEqual(contest.get_contest_name(lang='en'), 'KEYENCE Programming Contest 2019')
-        self.assertEqual(contest.get_contest_name(lang='ja'), 'キーエンス プログラミング コンテスト 2019')
+        self.assertEqual(contest.get_name(lang='en'), 'KEYENCE Programming Contest 2019')
+        self.assertEqual(contest.get_name(lang='ja'), 'キーエンス プログラミング コンテスト 2019')
         self.assertEqual(contest.get_start_time().year, 2019)
         self.assertEqual(contest.get_start_time().month, 1)
         self.assertEqual(contest.get_start_time().day, 13)
@@ -46,8 +46,8 @@ class AtCoderContestTest(unittest.TestCase):
         self.assertEqual(contest.get_penalty().total_seconds(), 5 * 60)
 
         contest = AtCoderContest.from_url('https://atcoder.jp/contests/dp')
-        self.assertEqual(contest.get_contest_name(lang='ja'), 'Educational DP Contest / DP まとめコンテスト')
-        self.assertEqual(contest.get_contest_name(lang='en'), 'Educational DP Contest')
+        self.assertEqual(contest.get_name(lang='ja'), 'Educational DP Contest / DP まとめコンテスト')
+        self.assertEqual(contest.get_name(lang='en'), 'Educational DP Contest')
         self.assertEqual(contest.get_start_time().year, 2019)
         self.assertEqual(contest.get_start_time().month, 1)
         self.assertEqual(contest.get_start_time().day, 6)
@@ -61,7 +61,7 @@ class AtCoderContestTest(unittest.TestCase):
         problems = contest.list_problems()
         self.assertEqual(len(problems), 7)
         self.assertEqual(problems[0].get_alphabet(), 'A')
-        self.assertEqual(problems[0].get_task_name(), 'Two Abbreviations')
+        self.assertEqual(problems[0].get_name(), 'Two Abbreviations')
         self.assertEqual(problems[0].get_time_limit_msec(), 2000)
         self.assertEqual(problems[0].get_memory_limit_byte(), 1024 * 1000 * 1000)
         self.assertEqual(problems[5].get_alphabet(), 'F')
@@ -89,7 +89,7 @@ class AtCoderProblemTest(unittest.TestCase):
     def test_load_details(self):
         problem = AtCoderProblem.from_url('https://atcoder.jp/contests/abc118/tasks/abc118_a')
         self.assertEqual(problem.get_alphabet(), 'A')
-        self.assertEqual(problem.get_task_name(), 'B +/- A')
+        self.assertEqual(problem.get_name(), 'B +/- A')
         self.assertEqual(problem.get_time_limit_msec(), 2000)
         self.assertEqual(problem.get_memory_limit_byte(), 1024 * 1000 * 1000)
         self.assertEqual(problem.get_score(), 100)