File size: 2,011 Bytes
6fffc74 e233c57 1a3765a 6fffc74 e233c57 6fffc74 af13d6f 6fffc74 1a3765a 6fffc74 1a3765a 6fffc74 1a3765a 6fffc74 1a3765a 6fffc74 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
from typing import Any, Dict
from flows import logging
from flows.utils.general_helpers import validate_parameters
from .src.evaluation import testing_utils_codeforces
from .CodeTesting import CodeTesting
log = logging.get_logger(__name__)
class CF_CodeTesting(CodeTesting):
REQUIRED_KEYS_CONFIG = []
REQUIRED_KEYS_CONSTRUCTOR = []
def __init__(self, **kwargs):
super().__init__(**kwargs)
@classmethod
def _validate_parameters(cls, kwargs):
validate_parameters(cls, kwargs)
if "public_tests_key" not in kwargs["flow_config"] and "hidden_tests_key" not in kwargs["flow_config"]:
raise ValueError("At least one of 'public_tests_key' "
"and 'hidden_tests_key' must be specified in the config.")
def _get_test_data(self, input_data: Dict):
"""This function retrieves (or generates) input-output pairs that will be used to test the implementation."""
test_data = {"public_tests_io": None, "hidden_tests_io": None}
if "public_tests_key" in self.flow_config:
test_data["public_tests_io"] = input_data[self.flow_config["public_tests_key"]]
if "hidden_tests_key" in self.flow_config:
test_data["hidden_tests_io"] = input_data[self.flow_config["hidden_tests_key"]]
return test_data
def _run_tests(self, input_data: Dict, test_data: Dict) -> Dict[str, Any]:
testing_results = testing_utils_codeforces.evaluate_solution_for_problem(
candidate_solution=input_data["code"],
**test_data
)
if "public_tests_results" in testing_results:
for test_output in testing_results["public_tests_results"]:
test_output["input"] = "\n".join(test_output["input"])
if "hidden_tests_results" in testing_results:
for test_output in testing_results["hidden_tests_results"]:
test_output["input"] = "\n".join(test_output["input"])
return testing_results
|