|
1 | 1 | import unittest |
2 | | -from typing import Union |
| 2 | +from typing import Union, Dict, Optional, List |
3 | 3 |
|
4 | | -from lchelper.parser import parse_problem |
| 4 | +import lchelper.codegen |
5 | 5 | from lchelper.common import FunctionSignature, Example, ProblemSignature, Interaction, \ |
6 | 6 | InteractiveProblemSignature, Problem |
7 | 7 |
|
8 | 8 |
|
| 9 | +class EndToEndTest(unittest.TestCase): |
| 10 | + def _test_problem_set(self, url: str, site: str = "leetcode", ignore_problems: Optional[List[int]] = None): |
| 11 | + available_users = [user for user in lchelper.get_users() if user.site == site] |
| 12 | + assert len(available_users) > 0, f"User cookie from site \"{site}\" required for end-to-end tests" |
| 13 | + user = available_users[0] |
| 14 | + problems = lchelper.get_problems(url, site, lchelper.get_cookie_path(user.username, user.site)) |
| 15 | + codegen: Dict[str, lchelper.codegen.CodeGen] = { |
| 16 | + lang: codegen_klass() |
| 17 | + for lang, codegen_klass in lchelper.LANGUAGES.items() |
| 18 | + } |
| 19 | + |
| 20 | + ignore_problems = ignore_problems or [] |
| 21 | + for idx, problem in enumerate(problems): |
| 22 | + if idx in ignore_problems: |
| 23 | + continue |
| 24 | + problem_signature = lchelper.parse_problem(problem, site) |
| 25 | + for lang, gen in codegen.items(): |
| 26 | + _, _ = gen.generate_code(problem, problem_signature) |
| 27 | + |
| 28 | + def test_contests(self): |
| 29 | + contests = [ |
| 30 | + ("weekly-contest-183", []), |
| 31 | + ("weekly-contest-182", []), |
| 32 | + ("weekly-contest-181", []), |
| 33 | + ("weekly-contest-180", []), |
| 34 | + ("weekly-contest-163", []), |
| 35 | + ("biweekly-contest-14", []), |
| 36 | + ] |
| 37 | + for contest, ignore_problems in contests: |
| 38 | + url = f"https://leetcode.com/contest/{contest}" |
| 39 | + self._test_problem_set(url, ignore_problems=ignore_problems) |
| 40 | + |
| 41 | + |
9 | 42 | class ParseTest(unittest.TestCase): |
10 | 43 | def _function_equal(self, parsed_function: FunctionSignature, function: FunctionSignature): |
11 | 44 | assert parsed_function.return_type == function.return_type |
12 | 45 | assert parsed_function.name == function.name |
13 | 46 | assert parsed_function.arguments == function.arguments |
14 | 47 |
|
15 | 48 | def _test_parse_problem(self, problem: Problem, signature: Union[ProblemSignature, InteractiveProblemSignature]): |
16 | | - parsed_signature = parse_problem(problem) |
| 49 | + parsed_signature = lchelper.parse_problem(problem) |
17 | 50 | assert type(parsed_signature) is type(signature) |
18 | 51 | if isinstance(signature, InteractiveProblemSignature): |
19 | 52 | assert parsed_signature.class_name == signature.class_name |
@@ -141,7 +174,7 @@ def test_parse_problem_2(self): |
141 | 174 | class_name="FindElements", |
142 | 175 | functions=[ |
143 | 176 | FunctionSignature( |
144 | | - return_type="", name="FindElements", |
| 177 | + return_type="FindElements", name="FindElements", |
145 | 178 | arguments=[("TreeNode*", "root")]), |
146 | 179 | FunctionSignature( |
147 | 180 | return_type="bool", name="find", |
|
0 commit comments