From 5be08646ba868af6fb4240cba2de6350642b0df1 Mon Sep 17 00:00:00 2001 From: virusdefender Date: Wed, 26 Oct 2016 22:51:31 +0800 Subject: [PATCH] fix test case meta info usage --- judge_client.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/judge_client.py b/judge_client.py index 835972d..cc8bd0e 100644 --- a/judge_client.py +++ b/judge_client.py @@ -53,12 +53,15 @@ class JudgeClient(object): except ValueError: raise JudgeClientError("Bad test case config") + def _get_test_case_file_info(self, test_case_file_id): + return self._test_case_info["test_cases"][test_case_file_id] + def _compare_output(self, test_case_file_id): user_output_file = os.path.join(self._submission_dir, str(test_case_file_id) + ".out") with open(user_output_file, "r") as f: content = f.read() output_md5 = hashlib.md5(content.strip()).hexdigest() - result = output_md5 == self._test_case_info["test_cases"][str(test_case_file_id)]["striped_output_md5"] + result = output_md5 == self._get_test_case_file_info(test_case_file_id)["striped_output_md5"] return output_md5, result def _spj(self, in_file_path, user_out_file_path): @@ -90,8 +93,8 @@ class JudgeClient(object): return SPJ_ERROR def _judge_one(self, test_case_file_id): - in_file = os.path.join(self._test_case_dir, str(test_case_file_id) + ".in").encode("utf-8") - user_out_file = os.path.join(self._submission_dir, str(test_case_file_id) + ".out").encode("utf-8") + in_file = os.path.join(self._test_case_dir, self._get_test_case_file_info(test_case_file_id)["input_name"]).encode("utf-8") + user_output_file = os.path.join(self._submission_dir, test_case_file_id + ".out").encode("utf-8") command = self._run_config["command"].format(exe_path=self._exe_path, exe_dir=os.path.dirname(self._exe_path), max_memory=self._max_memory / 1024).split(" ") @@ -105,8 +108,8 @@ class JudgeClient(object): max_process_number=_judger.UNLIMITED, exe_path=command[0].encode("utf-8"), input_path=in_file, - output_path=user_out_file, - error_path=user_out_file, + output_path=user_output_file, + error_path=user_output_file, args=[item.encode("utf-8") for item in command[1::]], env=env, log_path=JUDGER_RUN_LOG_PATH, @@ -123,7 +126,7 @@ class JudgeClient(object): if not self._spj_config or not self._spj_version: raise JudgeClientError("spj_config or spj_version not set") - spj_result = self._spj(in_file_path=in_file, user_out_file_path=user_out_file) + spj_result = self._spj(in_file_path=in_file, user_out_file_path=user_output_file) if spj_result == SPJ_WA: run_result["result"] = _judger.RESULT_WRONG_ANSWER @@ -148,8 +151,8 @@ class JudgeClient(object): def run(self): tmp_result = [] result = [] - for _ in range(self._test_case_info["test_case_number"]): - tmp_result.append(self._pool.apply_async(_run, (self, _ + 1))) + for test_case_file_id, _ in self._test_case_info["test_cases"].iteritems(): + tmp_result.append(self._pool.apply_async(_run, (self, test_case_file_id))) self._pool.close() self._pool.join() for item in tmp_result: