Can LLMs Generate Reliable Test Case Generators? A Study on Competition-Level Programming Problems

Yuhan Cao, Zian Chen, Kun Quan, Ziliang Zhang, Yu Wang, Xiaoning Dong, Yeqi Feng, Guanzhong He, Jingcheng Huang, Jianhao Li, Yixuan Tan, Jiafu Tang, Yilin Tang, Junlei Wu, Qianyu Xiao, Can Zheng, Shouchen Zhou, Yuxiang Zhu, Yiming Huang, Tian Xie, Tianxing HearXiv 2025 · DOI

Abstract

While Large Language Models (LLMs) have demonstrated remarkable proficiency in code generation, their capacity for code verification and adversarial testing remains a critical bottleneck. This study introduces TCGBench, a novel benchmark designed to evaluate LLMs' ability to author Python scripts that generate test cases capable of exposing bugs in human-written programs. Our evaluation reveals a substantial "reasoning gap": even state-of-the-art reasoning models like OpenAI’s o3-mini struggle to identify the subtle edge cases that human competitive programmers pinpoint intuitively.

Introduction

The prevailing standard for evaluating LLMs in programming is their ability to pass predefined unit tests. However, in software engineering and competitive programming, the primary challenge often lies in identifying the "hack case"—the specific input that triggers a failure in an otherwise plausible solution. While LLMs are frequently evaluated as solvers, this paper investigates their potential as adversarial testers. We ask: Can LLMs generate targeted test case generators that specifically trigger logical flaws, time limit exceedances (TLE), or runtime errors (RE)?

Methodology and TCGBench

The authors formalize adversarial testing into two distinct tasks:

  1. Valid Test Case Generation: Writing a script that produces inputs adhering to problem constraints (e.g., $N \le 10^5$).
  2. Targeted Test Case Generation: Identifying a bug in a provided C++ program and writing a generator to produce an input that causes it to fail.

TCGBench comprises 208 problems from the National Olympiad in Informatics for adolescents (NOIP) and a Canonical Problem Set covering standard algorithms. The benchmark includes over a thousand human-written programs, categorized into correct "standard solvers" and "erroneous programs."

Performance Analysis

Evaluation is conducted using the valid@k and success@k metrics. A generator is deemed successful if it produces an input where the buggy program's output deviates from the standard solver or results in a crash.

Success@k scores across various models for targeted test case generation.

The results highlight a significant disparity between valid and targeted generation. While models are adept at following constraints—with o1 achieving a valid@10 of 0.970—their ability to find bugs is markedly lower. On the NOIP dataset, human experts achieve a success rate of 0.901, whereas o3-mini reaches only 0.627 at success@1.

The Impact of Human Guidance

A key finding is that LLMs often hallucinate during debugging, misidentifying the cause of errors. However, providing a "Target Instruction"—a human-written hint pinpointing the bug—significantly enhances performance.

Comparison of Success@k with and without human-provided target instructions.

As shown in the figure above, instructions bridge the reasoning gap, suggesting that the bottleneck is not the model's coding ability, but its semantic reasoning regarding buggy code. This implies that while models can write the necessary scripts, they struggle to independently deduce what needs to be tested.

Conclusion

TCGBench demonstrates that while LLMs are becoming capable coders, they are not yet reliable adversarial testers. The "reasoning gap" between models and human experts remains wide in the context of bug discovery. Future work must address the scarcity of high-quality erroneous code data and explore whether models can autonomously generate effective debugging instructions through reinforcement learning to close this gap.

Summary updated

BibTeX
@misc{cao2025can,
  author = {Yuhan Cao and Zian Chen and Kun Quan and Ziliang Zhang and Yu Wang and Xiaoning Dong and Yeqi Feng and Guanzhong He and Jingcheng Huang and Jianhao Li and Yixuan Tan and Jiafu Tang and Yilin Tang and Junlei Wu and Qianyu Xiao and Can Zheng and Shouchen Zhou and Yuxiang Zhu and Yiming Huang and Tian Xie and Tianxing He},
  title = {{Can LLMs Generate Reliable Test Case Generators? A Study on Competition-Level Programming Problems}},
  year = {2025},
  eprint = {2506.06821},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2506.06821},
}
Figure