leet shape code

This commit is contained in:
elleven11 2023-04-04 00:27:20 -04:00
parent 963d1842b0
commit 5fd6ff89c6
3 changed files with 20 additions and 5 deletions

View File

@ -1,11 +1,18 @@
from .py_executor import PyExecutor
from .rs_executor import RsExecutor
from .py_executor import PyExecutor, PyLeetExecutor
from .rs_executor import RsExecutor, RsLeetExecutor
from .executor_types import Executor
def executor_factory(lang: str) -> Executor:
def executor_factory(lang: str, is_leet: bool = False) -> Executor:
if lang == "py" or lang == "python":
return PyExecutor()
if is_leet:
return PyLeetExecutor()
else:
return PyExecutor()
elif lang == "rs" or lang == "rust":
return RsExecutor()
if is_leet:
return RsLeetExecutor()
else:
return RsExecutor()
else:
raise ValueError(f"Invalid language for executor: {lang}")

View File

@ -76,6 +76,10 @@ check({name})
except Exception:
return False
class PyLeetExecutor(PyExecutor):
def evaluate(self, name: str, func: str, test: str, timeout: int = 5) -> bool:
raise NotImplementedError
def get_call_str(assert_statement: str) -> str:
call_str = ast.parse(assert_statement).body[0].test.left # type: ignore
return astunparse.unparse(call_str).strip()

View File

@ -207,6 +207,10 @@ class RsExecutor(Executor):
print("Passed eval", flush=True)
return len(errs) == 0
class RsLeetExecutor(RsExecutor):
def evaluate(self, name: str, func: str, test: str, timeout: int = 5) -> bool:
raise NotImplementedError("Not implemented for Rust")
assert_no_panic = r"""
macro_rules! assert_eq_nopanic {