(self, old_solution_file)
| 201 | |
| 202 | |
| 203 | def fix_testcases(self, old_solution_file): |
| 204 | prompts, overlong_prompts = self.dataset.get_all_prompts() |
| 205 | |
| 206 | data = json.load(open(old_solution_file, "r")) |
| 207 | |
| 208 | old_solutions = data["prompt2groundtruth"] |
| 209 | prompt2ios = data["prompt2io"] |
| 210 | |
| 211 | for index, prompt in enumerate(prompts + overlong_prompts): |
| 212 | if len(self.dataset.prompt2testcase[prompt]) == 0: |
| 213 | continue |
| 214 | elif len(self.dataset.prompt2groundtruth[prompt]) > 0: |
| 215 | continue |
| 216 | elif prompt not in self.dataset.prompt2groundtruth: |
| 217 | continue |
| 218 | elif prompt not in old_solutions: |
| 219 | continue |
| 220 | |
| 221 | print(f"Instance # {index}") |
| 222 | |
| 223 | candidates = [] |
| 224 | candidate_gts = [] |
| 225 | for i, gts in enumerate(old_solutions[prompt]): |
| 226 | print("Verifying instance #{} solution #{} ".format(index, i), end = '\r', file = sys.stderr) |
| 227 | gt, io = gts |
| 228 | try: |
| 229 | stat, results = self.execute_code(gt, io, self.dataset.prompt2testcase[prompt], check = False) |
| 230 | except Exception as e: |
| 231 | print(e) |
| 232 | continue |
| 233 | if check_success(results) and len(results) == len(self.dataset.prompt2testcase[prompt]): |
| 234 | candidates.append(results) |
| 235 | candidate_gts.append(gts) |
| 236 | |
| 237 | |
| 238 | equal_groups = [] |
| 239 | for i, c1 in enumerate(candidates): |
| 240 | print(i, end = '\r', file = sys.stderr) |
| 241 | if len(equal_groups) == 0: |
| 242 | equal_groups.append([i]) |
| 243 | continue |
| 244 | equal = False |
| 245 | for group in equal_groups: |
| 246 | if is_all_equal(candidates[group[0]], c1): |
| 247 | equal = True |
| 248 | group.append(i) |
| 249 | break |
| 250 | if not equal: |
| 251 | equal_groups.append([i]) |
| 252 | scores = [len(group) for group in equal_groups] |
| 253 | |
| 254 | if len(scores) == 0: |
| 255 | continue |
| 256 | |
| 257 | max_score = max(scores) |
| 258 | if max_score > len(candidates) * 0.8: |
| 259 | candidate = candidates[equal_groups[scores.index(max_score)][0]] |
| 260 | else: |
nothing calls this directly
no test coverage detected