How Many Code and Test Cases Are Enough? Evaluating Test Cases Generation from a Binary-Matrix Perspective

Xianzhen Luo, JinYang Huang, Wenzhen Zheng, Qingfu Zhu, Mingzheng Xu, Yiheng Xu, YuanTao Fan, Wanxiang Che

TL;DR

This paper introduces a linear algebra-based framework to evaluate how well Large Language Models (LLMs) generate test cases. By identifying a "diagnostic basis" of unique error patterns and filtering out redundant bugs using a novel WrongSelect algorithm, the authors created TC-Bench. This compact benchmark reveals that current state-of-the-art models still struggle to catch complex, non-trivial code faults, topping out at only ~60% effectiveness.

The Challenge of Evaluating Test Case Generation

As LLMs become central to software engineering, we increasingly rely on them to generate test cases. However, evaluating the quality of these generated tests is surprisingly difficult.

Existing benchmarks typically measure a "HackRate" (or exclusion ratio)—how many "wrong" code samples a generated test suite can successfully catch. The problem is that these benchmarks often use massive, unstructured collections of wrong codes. Many of these codes contain the same trivial bugs (like a simple typo), leading to score inflation. A model might look highly capable by catching 95% of bugs, but it’s actually just catching the same easy mistake repeatedly while missing rare, critical logic errors. Furthermore, running thousands of redundant tests is computationally expensive.

Comparison of traditional evaluation vs. the proposed WrongSelect framework

To resolve this, the authors ask two fundamental questions:

  1. What is the smallest set of wrong codes needed to represent the entire "error space" of a problem?
  2. What is the minimum number of test cases required to distinguish them?

A Binary-Matrix Perspective

The researchers propose a novel perspective: treating the relationship between code and tests as a Binary Code-Test Matrix.

  • The Matrix: They build a matrix $M$ where each row is a "wrong code" (WC) and each column is a "golden test case." An entry is 1 if the code fails the test (Wrong Answer/WA) and 0 if it passes (Accepted/AC).
  • Matrix Rank: In linear algebra, the rank of a matrix represents the number of linearly independent rows or columns. Here, the rank $R$ tells us the number of unique, independent error patterns. This rank also provides a theoretical upper bound on how many test cases are actually needed to cover the solution space.

The WrongSelect Algorithm

Finding the absolute best "basis" (the most diverse set of codes that span the error space) is an NP-hard problem. To tackle this, the authors developed WrongSelect, an efficient approximation algorithm.

The TC-Bench data pipeline featuring pre-filtering and random-restart local search

As illustrated in the pipeline above, the algorithm operates in two main steps:

  1. Pre-filtering: It removes trivial noise, such as codes that fail every single test or tests that are too easy to hack.
  2. Random-Restart Local Search: It selects a subset of codes that minimizes Jaccard similarity (overlap) between them, ensuring maximum internal diversity.

TC-Bench: A Compact and Rigorous Dataset

Applying their framework to millions of competitive programming submissions from prestigious contests (like USACO, NOI, and ICPC), the authors constructed TC-Bench.

  • Scale and Efficiency: The benchmark contains 877 problems and 9,347 "core" wrong codes. This represents less than 2% of the original submission pool, yet it covers the same comprehensive error space.
  • Validation: By comparing TC-Bench against existing datasets, the authors demonstrated that their "basis" approach successfully prevents the score inflation seen in traditional evaluations.

Key Insights and Results

  • Rank as a Budget: The rank of a problem's error space acts as a natural "budget" for test cases. Adding more tests beyond this rank offers diminishing returns, as they likely just re-validate known failures rather than uncovering new ones.
  • Diversity Over Quantity: A small, diverse "diagnostic basis" is a much more rigorous yardstick than a large, redundant dataset. On unfiltered datasets, models achieve near 100% scores; on TC-Bench, those same scores drop to ~50%, exposing an inability to catch nuanced logic errors.
  • The Performance Ceiling: Even the most advanced models combined with the best generation methods only achieve a ~60% HackRate on TC-Bench. This highlights a significant "intelligence gap" in current LLMs' ability to perform deep algorithmic reasoning.
  • Methodology Trumps Model Size: The choice of generation method has a much larger impact on performance than simply scaling up the size of the underlying LLM. Furthermore, top-tier open-source models are now highly competitive with leading closed-source models in test case generation tasks.

Limitations and Future Work

The current study and benchmark focus primarily on C++, which is standard for competitive programming but doesn't represent the entire software landscape. Additionally, LLMs still struggle to generate valid inputs for problems requiring highly specific, constrained data structures (e.g., specific graph types) and often fail to account for physical constraints like memory and runtime. Future work could involve "resource-aware" generation and expanding this binary-matrix perspective to real-world software repositories and different programming paradigms.

Summary updated

BibTeX
@inproceedings{luo2026how,
  author = {Xianzhen Luo and JinYang Huang and Wenzhen Zheng and Qingfu Zhu and Mingzheng Xu and Yiheng Xu and YuanTao Fan and Wanxiang Che},
  title = {{How Many Code and Test Cases Are Enough? Evaluating Test Cases Generation from a Binary-Matrix Perspective}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=RomWar2kVN},
}
Figure