## 3 Learning to Prioritize Test Cases for CAD Software, PriorCadTest
### Feature Extraction  
To train a ranking model for test case prioritization, we convert each functional unit and each test case into a numeric vector. In many programming languages, a test case is a specific function that can be directly run in the testing framework, such as Java test cases in Java testing framework, JUnit [36]. This facilitates the conversion from source code to numeric vectors. In our work, both functional units and test cases are converted into a vector with the same dimensions.  
**Vector conversion**. In our approach PriorCadTest, an off-the-shelf tool, CodeZhi, is used to conduct the conversion. CodeZhi is a tool of qualifying Java source code (Project CodeZhi, [[http://cstar.whu.edu.cn/pr/codezhi/](http://cstar.whu.edu.cn/pr/codezhi/)]([http://cstar.whu.edu.cn/pr/codezhi/](http://cstar.whu.edu.cn/pr/codezhi/)), accessed on 20 May 2022).This tool can extract features at the method level for Java programs. CodeZhi tries to find representative features, which can distinguish methods well. It picked up 103 features as the metrics to profile Java methods. For example, the CodeZhi tool profiles the function _outset(double dist)_ to get a feature vector with 103 dimensions as shown in Figure 3. A piece of compilable source code is converted into a vector with 103 dimensions. Each dimension indicates a manual-defined feature. The categories of features consist of features about statements, variables, objects, methods, operators and operands, complexity, code blocks, nested blocks, jumping statement, finals and statics, assignments, and distance. For example, the number of if-conditions and the cyclomatic complexity of the source code can be viewed  
Figure 2: Overview of the approach to learning to prioritize test cases for CAD software.  
as two features in feature extraction [37]. We denote a vector of the functional unit as \(M_{i}\) (\(1\leq i\leq m\)), and \(m\) is the number of functional units. We denote a vector of the test case as \(T_{j}\) (\(1\leq j\leq n\)), and \(n\) is the number of test cases. Then, each of \(M_{1},M_{2},...,M_{m}\) and \(T_{1},T_{2},...,T_{n}\) is a feature vector with 103 dimensions.  
**Test coverage matrix**. In the CAD software, a functional unit may be covered by multiple test cases; and one test case may cover multiple functional units. We construct a test coverage matrix to show the coverage relationship between test cases and functional units. We run each test case and analyze test results to obtain a matrix \(C\) and \(C_{i,j}\in C\) in the train set, where \(C_{i,j}\) indicates that the \(i\)th test case covers the \(j\)th functional unit. The value of \(C_{i,j}\) is 1 if a test case \(T_{i}\) has covered a functional unit \(M_{j}\), and 0 otherwise. Table 1 is an example of a test coverage matrix.  
**Vectors with labels**. In our work, each vector of a functional unit and each vector of a test case are connected into a vector. This vector is a pair of the functional unit and the test case, called a _test pair_ in this paper. The vector contains 206 dimensions and indicates the qualification of the coverage \(C_{i,j}\in C\), where \(C_{i,j}\) indicates that the \(i\)th test case covers the \(j\)th functional unit. To train a model that ranks test cases, we use a classifier to assign scores to the test cases. In our work, we label a vector with 206 dimension as 1 if \(C_{i,j}=1\) and the functional unit \(M_{j}\) contains a defect; otherwise, we label the vector as 0. Such labeling shows that the value of the label indicates the test coverage of a functional unit with a defect. Base on the labeling, each vector of the test coverage (indicating the coverage of a functional unit by a test case) and its label are conducted. In the learning phase of our approach, the labels are known as 1 or 0; in the ranking phase, the label is unknown, and the ranking model will assign a score to each 206-dimension vector. Then test cases can be ranked according to the assigned scores of test cases.