arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2502.10802cs.SEcs.AI
收藏

CoCoEvo:通过程序与测试用例的协同进化增强代码生成

CoCoEvo: Co-Evolution of Programs and Test Cases to Enhance Code Generation

School of Computer Science and Engineering, Beihang University(北京航空航天大学计算机科学与工程学院);Qingdao Research Institute, Beihang University(北京航空航天大学青岛研究所);Hangzhou Innovation Institute, Beihang University(北京航空航天大学杭州创新研究院);Zhongguancun Laboratory(中关村实验室)

Kefan Li, Yuan Yuan, Hongyue Yu, Tingyu Guo, Shijie Cao

AI总结:

本文提出 CoCoEvo 框架,让程序与测试用例基于自然语言描述协同进化,并结合交叉率调度和多目标测试选择,在无预定义测试场景下提升代码生成与测试性能。

摘要:

大语言模型(LLM)在自动化代码生成中已展现出卓越性能。然而,现有方法通常严重依赖预定义测试用例,而在此类用例不可用的场景中,这些方法便不再实用。尽管先前工作探索了程序与测试用例之间的过滤技术,却忽视了对测试用例的精化。为解决这一局限,我们提出 CoCoEvo,这是一种新颖的基于 LLM 的协同进化框架,可同时进化程序和测试用例。CoCoEvo 通过直接根据自然语言问题描述和函数头生成程序与测试用例,消除了对预定义测试用例的依赖。该框架采用专门的进化算子,包括用于程序进化的基于 LLM 的交叉和变异算子,以及用于测试用例进化的额外测试用例生成算子。此外,我们提出了若干优化策略,例如用于平衡探索与收敛的交叉率调度器,以及用于测试用例选择的多目标优化方法。在多个最先进 LLM 上的实验结果表明,CoCoEvo 优于现有方法,在自动化代码生成和测试中取得了最先进性能。这些结果凸显了协同进化技术在推动自动化编程领域发展方面的潜力。

英文摘要:

Large Language Models (LLMs) have shown remarkable performance in automated code generation. However, existing approaches often rely heavily on pre-defined test cases, which become impractical in scenarios where such cases are unavailable. While prior works explore filtering techniques between programs and test cases, they overlook the refinement of test cases. To address this limitation, we introduce CoCoEvo, a novel LLM-based co-evolution framework that simultaneously evolves programs and test cases. CoCoEvo eliminates the dependency on pre-defined test cases by generating both programs and test cases directly from natural language problem descriptions and function headers. The framework employs specialized evolutionary operators, including LLM-based crossover and mutation operators for program evolution, along with an additional test case generation operator for test case evolution. Additionally, we propose optimization strategies such as a crossover rate scheduler to balance exploration and convergence, and a multi-objective optimization method for test case selection. Experimental results on multiple state-of-the-art LLMs demonstrate that CoCoEvo surpasses existing methods, achieving state-of-the-art performance in automated code generation and testing. These results underscore the potential of co-evolutionary techniques in advancing the field of automated programming.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑