# An Intelligent Method for C++ Test Case Synthesis Based on a Q-Learning Agent
## 2 Materials and Methods
### Test Case Synthesis Algorithm
\begin{table}
\begin{tabular}{c c c c c c c} \hline \hline
**Configuration** & \begin{tabular}{c} **Original TS** \\ **Branch** \\ **Coverage (\%)** \\ \end{tabular} & \begin{tabular}{c} **Synthesized TS** \\ **Branch** \\ **Coverage (\%)** \\ \end{tabular} & \begin{tabular}{c} **Original TS** \\ **Instructions** \\ **Coverage (\%)** \\ \end{tabular} & \
\begin{tabular}{c} **Synthesized TS** \\ **Instructions** \\ **Count** \\ \end{tabular} &
\begin{tabular}{c} **Compression** \\ **Coefficient** \\ \end{tabular} \\ \hline RAND & & & BitmapPlusPlus & & & \\ QLEG2 & 27 & 25.41 \(\pm\) 2.69 & 71 & 51.83 \(\pm\) 2.86 & 0.27 \\ QLB2 & & 27.66 \(\pm\) 2.49 & 52.49 \(\pm\) 2.20 & 0.26 \\  & & Hjson & & \\ RAND & & 24.6 \(\pm\) 8.50 & 213.92 \(\pm\) 101.43 & 0.83 \\ QLEG2 & 33.9 & 33.03 \(\pm\) 1.39 & 1259 & 405.40 \(\pm\) 13.09 & 0.68 \\ QLB2 & & 34.07 \(\pm\) 1.07 & 419.36 \(\pm\) 7.33 & 0.67 \\ \hline \hline \end{tabular}
\end{table} 
Table 8: Efficiency comparison of the test case synthesis policies for the BitmapPlusPlus and Hjson libraries in terms of branch coverage, average instruction count, and compression coefficient. The original test suites are used as a baseline. All synthesized instruction counts represent mean values across 150 independently generated test cases per configuration. of redundancy in the original TCs. For Hjson, despite having a larger API surface, the agent encountered a narrower state space due to high structural similarity among the original TCs, which limited the entropy of available sequences. Overall, we conclude that the size of the Q-table after training depends not only on the number of public functions in the library, but also on the variability of training TCs. Libraries with complex and extensive public interfaces create larger exploration spaces and require more memory, whereas libraries with lower combinatorial complexity allow the agent to stabilize more quickly. Although Hjson provided a larger number of original TCs, the lower entropy of API calls led to fewer unique states in the Q-table, despite a significantly longer training time. The observed stability in synthesizing sequences across both libraries confirms the model's ability to transfer knowledge between different TCs within the same API. The pretraining strategy before each new training episode allowed the agent to adapt to a new environment, which is particularly beneficial in time-constrained training settings. Among the tested configurations, QLB2 demonstrates the most adequate performance, achieving the highest mean branch coverage for both libraries also maintaining a competitive compression coefficient. QLEG2 shows near-adequate results, reaching slightly lower coverage with comparable compression, suggesting it is a viable alternative when deterministic behavior is preferred. In contrast, the RAND baseline policy is inadequate, with significantly lower coverage indicating that random synthesis does not produce efficient test cases. The analysis of instruction counts, and coverage metrics demonstrates that synthesized TCs using QLB2 and QLEG2 policies consistently maintain or improve branch coverage while significantly reducing instruction count. For the Hjson library, both policies achieved coverage values comparable to the original TS with a nearly 2-3 factor compression (compression coefficient 0.67-0.68). For BitmapPlusPlus, the QLB2 policy matched the original 27% branch coverage with a compression coefficient of 0.26, confirming the ability of the approach to construct compact and effective TCs. However, the compression effect was less pronounced for certain configurations (e.g., QLEG2 on BitmapPlusPlus), where the reduced TC length did not lead to coverage improvement. This suggests that while the method is effective in optimizing longer and more redundant test cases, its benefit for already concise TCs is naturally bounded. These results underline the efficiency of policy-guided synthesis.